Skip to content

Commit

Permalink
Merge pull request #1 from Netcracker/dockerbuild
Browse files Browse the repository at this point in the history
Switch to golang compilation in docker build phase, polish local development guides
  • Loading branch information
alagishev authored Jan 13, 2025
2 parents 7fe5189 + 62f53e5 commit 1593b30
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 96 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
TAG_NAME: ${{ github.event.release.tag_name || github.ref }}

jobs:
multiplatform_build:
build_and_push_image:
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
no-cache: true
context: ${{ matrix.component.context }}
file: ${{ matrix.component.file }}
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
push: true
tags: ghcr.io/netcracker/${{ matrix.component.name }}:${{ env.TAG_NAME }}
provenance: false
Expand All @@ -57,4 +57,4 @@ jobs:
package-name: ${{ matrix.component.name }}
package-type: 'container'
package-version-ids: ${{ steps.get-ids-for-delete.outputs.ids-for-delete }}
if: ${{ steps.get-ids-for-delete.outputs.ids-for-delete != '' }}
if: ${{ steps.get-ids-for-delete.outputs.ids-for-delete != '' }}
21 changes: 10 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
apihub-service/.idea
apihub-service/go.sum
qubership-apihub-service/.idea
qubership-apihub-service/go.sum
.idea
.vscode
.history
apihub-service/data/**
apihub-service/static/**
apihub-service/logs/**
apihub-service/apihub-service.exe
apihub-service/__debug_bin.exe
apihub-service/apihub-service
qubership-apihub-service/data/**
qubership-apihub-service/logs/**
qubership-apihub-service/qubership-apihub-service.exe
qubership-apihub-service/__debug_bin.exe
qubership-apihub-service/qubership-apihub-service
logs
apihub-service/logs
apihub-service/tmp/**
apihub-service/bin/**
qubership-apihub-service/logs
qubership-apihub-service/tmp/**
qubership-apihub-service/bin/**

docs/local_development/jwt_private_key
*.patch
Expand Down
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
FROM docker.io/golang:1.23.4-alpine3.21 as builder

WORKDIR /workspace

COPY qubership-apihub-service qubership-apihub-service

WORKDIR /workspace/qubership-apihub-service

RUN set GOSUMDB=off && set CGO_ENABLED=0 && set GOOS=linux && go mod tidy && go mod download && go build .

FROM docker.io/golang:1.23.4-alpine3.21

MAINTAINER qubership.org
Expand All @@ -8,7 +18,7 @@ USER root

RUN apk --no-cache add curl

ADD qubership-apihub-service/qubership-apihub-service ./qubership-apihub-service
COPY --from=builder /workspace/qubership-apihub-service/qubership-apihub-service ./qubership-apihub-service
ADD qubership-apihub-service/static ./static
ADD qubership-apihub-service/resources ./resources
ADD docs/api ./api
Expand Down
1 change: 1 addition & 0 deletions build_docker_image.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
podman build ./ -t netcracker/qubership-apihub-backend
3 changes: 1 addition & 2 deletions build.cmd → build_golang_binary.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ cd ./qubership-apihub-service
go mod tidy
go mod download
go build .
cd ..
podman build ./ -t netcracker/qubership-apihub-backend
cd ..
105 changes: 53 additions & 52 deletions docs/local_development/docker-compose/DB/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
version: "3.9"
services:
postgres:
image: postgres:13.3
command:
- "postgres"
- "-c"
- "max_connections=50"
- "-c"
- "shared_buffers=1GB"
- "-c"
- "effective_cache_size=4GB"
- "-c"
- "work_mem=16MB"
- "-c"
- "maintenance_work_mem=512MB"
- "-c"
- "random_page_cost=1.1"
- "-c"
- "temp_file_limit=10GB"
- "-c"
- "log_min_duration_statement=200ms"
- "-c"
- "idle_in_transaction_session_timeout=10s"
- "-c"
- "lock_timeout=1s"
- "-c"
- "shared_preload_libraries=pg_stat_statements"
- "-c"
- "pg_stat_statements.max=10000"
- "-c"
- "pg_stat_statements.track=all"
environment:
POSTGRES_DB: "apihub"
POSTGRES_USER: "apihub"
POSTGRES_PASSWORD: "APIhub1234"
PGDATA: "/C/pg-docker/data"
volumes:
- ../2. Init Database:/docker-entrypoint-initdb.d
- .:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U apihub -d apihub"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '1'
memory: 4G
postgres:
image: docker.io/postgres
container_name: postgres
command:
- "postgres"
- "-c"
- "max_connections=50"
- "-c"
- "shared_buffers=1GB"
- "-c"
- "effective_cache_size=1GB"
- "-c"
- "work_mem=16MB"
- "-c"
- "maintenance_work_mem=512MB"
- "-c"
- "random_page_cost=1.1"
- "-c"
- "temp_file_limit=10GB"
- "-c"
- "log_min_duration_statement=200ms"
- "-c"
- "idle_in_transaction_session_timeout=10s"
- "-c"
- "lock_timeout=1s"
- "-c"
- "shared_preload_libraries=pg_stat_statements"
- "-c"
- "pg_stat_statements.max=10000"
- "-c"
- "pg_stat_statements.track=all"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
- PGDATA=/C/pg-docker/data
ports:
- 5432:5432
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 10s
timeout: 15s
retries: 15
start_period: 5s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '1'
memory: 3G
volumes:
- '.:/var/lib/postgresql/data:Z'
- './scripts/init-db:/docker-entrypoint-initdb.d'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE USER apihub WITH PASSWORD 'apihub' CREATEDB INHERIT;
CREATE DATABASE apihub OWNER apihub;
GRANT ALL PRIVILEGES ON DATABASE apihub TO apihub;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: "3.9"
services:
apihub-ui:
image: ghcr.io/qubersip/apihub-ui-assembly-release-2.2.18:build8
qubership-apihub-ui:
image: ghcr.io/netcracker/qubership-apihub-ui:main
environment:
APIHUB_BACKEND_ADDRESS: "host.docker.internal:8090"
APIHUB_NC_SERVICE_ADDRESS: "host.docker.internal:8091"
ports:
- "8080:8080"
- "8081:8080"
restart: unless-stopped
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: "3.9"
services:
apihub-node-service:
image: ghcr.io/qubership/apihub-node-service-assembly-develop:build861
qubership-apihub-build-task-consumer:
image: ghcr.io/netcracker/qubership-apihub-build-task-consumer:main
environment:
APIHUB_BACKEND_ADDRESS: "host.docker.internal:8090"
APIHUB_API_KEY: "123123"
ports:
- "8092:8080"
- "3000:3000"
restart: unless-stopped
53 changes: 32 additions & 21 deletions docs/local_development/local_development.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This instruction tells how to set up local development.

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

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

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

Run corresponding docker-compose file from /docker-compose/DB folder.
It will start Postgres DB in docker container with predefined credentials and database. So it's ready to connect from Apihub BE.

At this moment there's no procedure to create NC service DB in one command, so you have to create DB `apihub_nc` manually.
It will start Postgres DB in docker container with predefined credentials and database. So it's ready to connect from APIHUB BE.
User `apihub` with password `apihub` and database `apihub` will be created automatically.
If you use DBeaver you need to connect to PostgreSQL DB first using parameters:
```
Host=localhost
Username=apihub
Password=APIhub1234
Username=postgres
Password=postgres
Port=5432
```
Don't forget to check 'Show all databases' to see all DBs.
Then open postgres->Databases and create `apihub_nc` DB with owner 'apihub' (all other params leave as default).

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

```bash
docker-compose -f docs/local_development/docker-compose/DB/docker-compose.yml up
```

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**.
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**.

* To run the image please issue a command below:

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

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.

#### API hub BE environment
#### APIHUB BE environment

The following environment variables are required to start Apihub application:

ENV format
```INI
LISTEN_ADDRESS=127.0.0.1:8090;
APIHUB_POSTGRESQL_DB_NAME=apihub;
APIHUB_POSTGRESQL_USERNAME=apihub;
APIHUB_POSTGRESQL_PASSWORD=APIhub1234;
APIHUB_POSTGRESQL_PASSWORD=apihub;
APIHUB_POSTGRESQL_PORT=5432;
PRODUCTION_MODE=false;
JWT_PRIVATE_KEY={use generated key here}
```

JSON format
```JSON
"LISTEN_ADDRESS": "127.0.0.1:8090",
"APIHUB_POSTGRESQL_DB_NAME": "apihub",
"APIHUB_POSTGRESQL_USERNAME": "apihub",
"APIHUB_POSTGRESQL_PASSWORD": "apihub",
"APIHUB_POSTGRESQL_PORT": "5432",
"PRODUCTION_MODE": "false",
"JWT_PRIVATE_KEY": "USE GENERATED KEY HERE"
```


Set these variables to build configuration.

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

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.

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

### Custom service

Expand All @@ -107,33 +118,33 @@ LISTEN_ADDRESS=127.0.0.1:8091;
DB_TYPE=postgres;
APIHUB_POSTGRESQL_HOST=localhost;
APIHUB_POSTGRESQL_PORT=5432;
NC_APIHUB_POSTGRESQL_DB_NAME=apihub_nc;
NC_APIHUB_POSTGRESQL_DB_NAME=apihub_custom_service;
NC_APIHUB_POSTGRESQL_USERNAME=apihub;
NC_APIHUB_POSTGRESQL_PASSWORD=APIhub1234;
NC_APIHUB_POSTGRESQL_PASSWORD=apihub;
APIHUB_URL=http://127.0.0.1:8090;
APIHUB_ACCESS_TOKEN={use generated token value here};
```

## FE
## UI


### Run frontend
### Run UI service

Run corresponding docker-compose file from `/docker-compose/FE` folder.
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.
Run corresponding docker-compose file from `/docker-compose/UI` folder.
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.

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

```bash
docker compose -f docs/local_development/docker-compose/FE/docker-compose.yml up
docker compose -f docs/local_development/docker-compose/UI/docker-compose.yml up
```

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)

To run the image please issue a command below:

```bash
docker compose -f docs/local_development/docker-compose/FE/docker-compose.yml run apihub-ui
docker compose -f docs/local_development/docker-compose/UI/docker-compose.yml run qubership-apihub-ui
```

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

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

#### Fill DB with data if needed
You can fill DB with data:
Expand Down

0 comments on commit 1593b30

Please sign in to comment.