Skip to content

Commit 1593b30

Browse files
authored
Merge pull request #1 from Netcracker/dockerbuild
Switch to golang compilation in docker build phase, polish local development guides
2 parents 7fe5189 + 62f53e5 commit 1593b30

File tree

10 files changed

+120
-96
lines changed

10 files changed

+120
-96
lines changed

.github/workflows/push.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
TAG_NAME: ${{ github.event.release.tag_name || github.ref }}
1010

1111
jobs:
12-
multiplatform_build:
12+
build_and_push_image:
1313
strategy:
1414
fail-fast: false
1515
matrix:
@@ -46,7 +46,7 @@ jobs:
4646
no-cache: true
4747
context: ${{ matrix.component.context }}
4848
file: ${{ matrix.component.file }}
49-
platforms: linux/amd64,linux/arm64
49+
platforms: linux/amd64
5050
push: true
5151
tags: ghcr.io/netcracker/${{ matrix.component.name }}:${{ env.TAG_NAME }}
5252
provenance: false
@@ -57,4 +57,4 @@ jobs:
5757
package-name: ${{ matrix.component.name }}
5858
package-type: 'container'
5959
package-version-ids: ${{ steps.get-ids-for-delete.outputs.ids-for-delete }}
60-
if: ${{ steps.get-ids-for-delete.outputs.ids-for-delete != '' }}
60+
if: ${{ steps.get-ids-for-delete.outputs.ids-for-delete != '' }}

.gitignore

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
apihub-service/.idea
2-
apihub-service/go.sum
1+
qubership-apihub-service/.idea
2+
qubership-apihub-service/go.sum
33
.idea
44
.vscode
55
.history
6-
apihub-service/data/**
7-
apihub-service/static/**
8-
apihub-service/logs/**
9-
apihub-service/apihub-service.exe
10-
apihub-service/__debug_bin.exe
11-
apihub-service/apihub-service
6+
qubership-apihub-service/data/**
7+
qubership-apihub-service/logs/**
8+
qubership-apihub-service/qubership-apihub-service.exe
9+
qubership-apihub-service/__debug_bin.exe
10+
qubership-apihub-service/qubership-apihub-service
1211
logs
13-
apihub-service/logs
14-
apihub-service/tmp/**
15-
apihub-service/bin/**
12+
qubership-apihub-service/logs
13+
qubership-apihub-service/tmp/**
14+
qubership-apihub-service/bin/**
1615

1716
docs/local_development/jwt_private_key
1817
*.patch

Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
FROM docker.io/golang:1.23.4-alpine3.21 as builder
2+
3+
WORKDIR /workspace
4+
5+
COPY qubership-apihub-service qubership-apihub-service
6+
7+
WORKDIR /workspace/qubership-apihub-service
8+
9+
RUN set GOSUMDB=off && set CGO_ENABLED=0 && set GOOS=linux && go mod tidy && go mod download && go build .
10+
111
FROM docker.io/golang:1.23.4-alpine3.21
212

313
MAINTAINER qubership.org
@@ -8,7 +18,7 @@ USER root
818

919
RUN apk --no-cache add curl
1020

11-
ADD qubership-apihub-service/qubership-apihub-service ./qubership-apihub-service
21+
COPY --from=builder /workspace/qubership-apihub-service/qubership-apihub-service ./qubership-apihub-service
1222
ADD qubership-apihub-service/static ./static
1323
ADD qubership-apihub-service/resources ./resources
1424
ADD docs/api ./api

build_docker_image.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
podman build ./ -t netcracker/qubership-apihub-backend

build.cmd renamed to build_golang_binary.cmd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ cd ./qubership-apihub-service
55
go mod tidy
66
go mod download
77
go build .
8-
cd ..
9-
podman build ./ -t netcracker/qubership-apihub-backend
8+
cd ..
Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
11
version: "3.9"
22
services:
3-
postgres:
4-
image: postgres:13.3
5-
command:
6-
- "postgres"
7-
- "-c"
8-
- "max_connections=50"
9-
- "-c"
10-
- "shared_buffers=1GB"
11-
- "-c"
12-
- "effective_cache_size=4GB"
13-
- "-c"
14-
- "work_mem=16MB"
15-
- "-c"
16-
- "maintenance_work_mem=512MB"
17-
- "-c"
18-
- "random_page_cost=1.1"
19-
- "-c"
20-
- "temp_file_limit=10GB"
21-
- "-c"
22-
- "log_min_duration_statement=200ms"
23-
- "-c"
24-
- "idle_in_transaction_session_timeout=10s"
25-
- "-c"
26-
- "lock_timeout=1s"
27-
- "-c"
28-
- "shared_preload_libraries=pg_stat_statements"
29-
- "-c"
30-
- "pg_stat_statements.max=10000"
31-
- "-c"
32-
- "pg_stat_statements.track=all"
33-
environment:
34-
POSTGRES_DB: "apihub"
35-
POSTGRES_USER: "apihub"
36-
POSTGRES_PASSWORD: "APIhub1234"
37-
PGDATA: "/C/pg-docker/data"
38-
volumes:
39-
- ../2. Init Database:/docker-entrypoint-initdb.d
40-
- .:/var/lib/postgresql/data
41-
ports:
42-
- "5432:5432"
43-
healthcheck:
44-
test: ["CMD-SHELL", "pg_isready -U apihub -d apihub"]
45-
interval: 10s
46-
timeout: 5s
47-
retries: 5
48-
start_period: 10s
49-
restart: unless-stopped
50-
deploy:
51-
resources:
52-
limits:
53-
cpus: '1'
54-
memory: 4G
3+
postgres:
4+
image: docker.io/postgres
5+
container_name: postgres
6+
command:
7+
- "postgres"
8+
- "-c"
9+
- "max_connections=50"
10+
- "-c"
11+
- "shared_buffers=1GB"
12+
- "-c"
13+
- "effective_cache_size=1GB"
14+
- "-c"
15+
- "work_mem=16MB"
16+
- "-c"
17+
- "maintenance_work_mem=512MB"
18+
- "-c"
19+
- "random_page_cost=1.1"
20+
- "-c"
21+
- "temp_file_limit=10GB"
22+
- "-c"
23+
- "log_min_duration_statement=200ms"
24+
- "-c"
25+
- "idle_in_transaction_session_timeout=10s"
26+
- "-c"
27+
- "lock_timeout=1s"
28+
- "-c"
29+
- "shared_preload_libraries=pg_stat_statements"
30+
- "-c"
31+
- "pg_stat_statements.max=10000"
32+
- "-c"
33+
- "pg_stat_statements.track=all"
34+
environment:
35+
- POSTGRES_USER=postgres
36+
- POSTGRES_PASSWORD=postgres
37+
- POSTGRES_DB=postgres
38+
- PGDATA=/C/pg-docker/data
39+
ports:
40+
- 5432:5432
41+
healthcheck:
42+
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
43+
interval: 10s
44+
timeout: 15s
45+
retries: 15
46+
start_period: 5s
47+
restart: unless-stopped
48+
deploy:
49+
resources:
50+
limits:
51+
cpus: '1'
52+
memory: 3G
53+
volumes:
54+
- '.:/var/lib/postgresql/data:Z'
55+
- './scripts/init-db:/docker-entrypoint-initdb.d'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE USER apihub WITH PASSWORD 'apihub' CREATEDB INHERIT;
2+
CREATE DATABASE apihub OWNER apihub;
3+
GRANT ALL PRIVILEGES ON DATABASE apihub TO apihub;
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
version: "3.9"
22
services:
3-
apihub-ui:
4-
image: ghcr.io/qubersip/apihub-ui-assembly-release-2.2.18:build8
3+
qubership-apihub-ui:
4+
image: ghcr.io/netcracker/qubership-apihub-ui:main
55
environment:
66
APIHUB_BACKEND_ADDRESS: "host.docker.internal:8090"
77
APIHUB_NC_SERVICE_ADDRESS: "host.docker.internal:8091"
88
ports:
9-
- "8080:8080"
9+
- "8081:8080"
1010
restart: unless-stopped
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
version: "3.9"
22
services:
3-
apihub-node-service:
4-
image: ghcr.io/qubership/apihub-node-service-assembly-develop:build861
3+
qubership-apihub-build-task-consumer:
4+
image: ghcr.io/netcracker/qubership-apihub-build-task-consumer:main
55
environment:
66
APIHUB_BACKEND_ADDRESS: "host.docker.internal:8090"
77
APIHUB_API_KEY: "123123"
88
ports:
9-
- "8092:8080"
9+
- "3000:3000"
1010
restart: unless-stopped

docs/local_development/local_development.md

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
This instruction tells how to set up local development.
44

5-
Backends (Apihub and Custom service) could be started from IDE/cmd.
5+
Backend could be started from IDE/cmd.
66

7-
DB and frontend components in docker are required to run full Apihub application except the agent functionality.
7+
DB and UI components in docker are required to run full APIHUB application (except the agent functionality).
88
There's no way for start agent in docker since k8s API is required.
99

1010
## Prerequisites
@@ -16,26 +16,24 @@ Install necessary software if it was not installed earlie. For more info please
1616
### DB
1717

1818
Run corresponding docker-compose file from /docker-compose/DB folder.
19-
It will start Postgres DB in docker container with predefined credentials and database. So it's ready to connect from Apihub BE.
20-
21-
At this moment there's no procedure to create NC service DB in one command, so you have to create DB `apihub_nc` manually.
19+
It will start Postgres DB in docker container with predefined credentials and database. So it's ready to connect from APIHUB BE.
20+
User `apihub` with password `apihub` and database `apihub` will be created automatically.
2221
If you use DBeaver you need to connect to PostgreSQL DB first using parameters:
2322
```
2423
Host=localhost
25-
Username=apihub
26-
Password=APIhub1234
24+
Username=postgres
25+
Password=postgres
2726
Port=5432
2827
```
2928
Don't forget to check 'Show all databases' to see all DBs.
30-
Then open postgres->Databases and create `apihub_nc` DB with owner 'apihub' (all other params leave as default).
3129

3230
* To create a corresponding docker image you need to issue a command:
3331

3432
```bash
3533
docker-compose -f docs/local_development/docker-compose/DB/docker-compose.yml up
3634
```
3735

38-
If you have another docker image (usually another DB container from another project) which could intersect with this one then you need to change PostgreSQL port settings and image port mapping in [`DB/docker-compose.yml`](/docs/local_development/docker-compose/DB/docker-compose.yml). Please add two arguments into **command** section ("\-p" and "\<new port number\>") and update port mapping in the **ports** section. Default port number for PostgreSQL is **5433**.
36+
If you have another docker image (usually another DB container from another project) which could intersect with this one then you need to change PostgreSQL port settings and image port mapping in [`DB/docker-compose.yml`](/docs/local_development/docker-compose/DB/docker-compose.yml). Please add two arguments into **command** section ("\-p" and "\<new port number\>") and update port mapping in the **ports** section. Default port number for PostgreSQL is **5432**.
3937

4038
* To run the image please issue a command below:
4139

@@ -59,20 +57,33 @@ Apihub contains built-in identity provider and it requires RSA private key as a
5957

6058
Run [`generate_jwt_pkey.sh`](generate_jwt_pkey.sh), it will generate file jwt_private_key in the current directory. Paste the value to Apihub BE environment. Please mind that the key must be non-empty.
6159

62-
#### API hub BE environment
60+
#### APIHUB BE environment
6361

6462
The following environment variables are required to start Apihub application:
6563

64+
ENV format
6665
```INI
6766
LISTEN_ADDRESS=127.0.0.1:8090;
6867
APIHUB_POSTGRESQL_DB_NAME=apihub;
6968
APIHUB_POSTGRESQL_USERNAME=apihub;
70-
APIHUB_POSTGRESQL_PASSWORD=APIhub1234;
69+
APIHUB_POSTGRESQL_PASSWORD=apihub;
7170
APIHUB_POSTGRESQL_PORT=5432;
7271
PRODUCTION_MODE=false;
7372
JWT_PRIVATE_KEY={use generated key here}
7473
```
7574

75+
JSON format
76+
```JSON
77+
"LISTEN_ADDRESS": "127.0.0.1:8090",
78+
"APIHUB_POSTGRESQL_DB_NAME": "apihub",
79+
"APIHUB_POSTGRESQL_USERNAME": "apihub",
80+
"APIHUB_POSTGRESQL_PASSWORD": "apihub",
81+
"APIHUB_POSTGRESQL_PORT": "5432",
82+
"PRODUCTION_MODE": "false",
83+
"JWT_PRIVATE_KEY": "USE GENERATED KEY HERE"
84+
```
85+
86+
7687
Set these variables to build configuration.
7788

7889
#### Run API hub
@@ -89,7 +100,7 @@ Since you will run non-production environment you do not have any valid identity
89100

90101
You can use any of test tools approved by company to send REST API requests. The best request collection can be found in the [`apihub-postman-collections repository`](https://<git_group_link>/apihub-postman-collections). And the command above, collection and environment for local development are also included.
91102

92-
You can use NC-newman-desktop or Bruno app to run REST API requests.
103+
You can use Postman or Bruno app to run REST API requests.
93104

94105
### Custom service
95106

@@ -107,33 +118,33 @@ LISTEN_ADDRESS=127.0.0.1:8091;
107118
DB_TYPE=postgres;
108119
APIHUB_POSTGRESQL_HOST=localhost;
109120
APIHUB_POSTGRESQL_PORT=5432;
110-
NC_APIHUB_POSTGRESQL_DB_NAME=apihub_nc;
121+
NC_APIHUB_POSTGRESQL_DB_NAME=apihub_custom_service;
111122
NC_APIHUB_POSTGRESQL_USERNAME=apihub;
112-
NC_APIHUB_POSTGRESQL_PASSWORD=APIhub1234;
123+
NC_APIHUB_POSTGRESQL_PASSWORD=apihub;
113124
APIHUB_URL=http://127.0.0.1:8090;
114125
APIHUB_ACCESS_TOKEN={use generated token value here};
115126
```
116127

117-
## FE
128+
## UI
118129

119130

120-
### Run frontend
131+
### Run UI service
121132

122-
Run corresponding docker-compose file from `/docker-compose/FE` folder.
123-
It will start FE container providing you a kind of GUI on localhost:8080 that will connect to Apihub BE on :8090 and NC service on :8091.
133+
Run corresponding docker-compose file from `/docker-compose/UI` folder.
134+
It will start FE container providing you a kind of GUI on localhost:8081 that will connect to Apihub BE on :8090 and Custom service on :8091.
124135

125136
To create a corresponding Docker image you need to issue a command:
126137

127138
```bash
128-
docker compose -f docs/local_development/docker-compose/FE/docker-compose.yml up
139+
docker compose -f docs/local_development/docker-compose/UI/docker-compose.yml up
129140
```
130141

131142
If default port (8080) was already taken by another application or Docker image you have configure another one in the **ports** section an re-create image with the command above. See [`FE/docker-compose.yml`](/docs/local_development/docker-compose/FE/docker-compose.yml)
132143

133144
To run the image please issue a command below:
134145

135146
```bash
136-
docker compose -f docs/local_development/docker-compose/FE/docker-compose.yml run apihub-ui
147+
docker compose -f docs/local_development/docker-compose/UI/docker-compose.yml run qubership-apihub-ui
137148
```
138149

139150
Of course, you can perform the actions above with your favorite IDE.
@@ -150,7 +161,7 @@ Open NC-newman-desktop or Bruno app and run `POST /api/internal/users` at APIHUB
150161
}`
151162

152163
#### Open web view
153-
Go to http://localhost:8080 (use other port if you change it) and enter created above credentials.
164+
Go to http://localhost:8081 (use other port if you change it) and enter created above credentials.
154165

155166
#### Fill DB with data if needed
156167
You can fill DB with data:

0 commit comments

Comments
 (0)