From 8e124336094c4081460179c318c9856a7e5676d0 Mon Sep 17 00:00:00 2001 From: Kaan Yagci Date: Mon, 25 Aug 2025 21:35:19 +0200 Subject: [PATCH 1/4] chore: update docker compose definition and readme Signed-off-by: Kaan Yagci --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++-- docker-compose.yml | 46 +++++++++++++++++++++++++++++----------- 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3b2be1b..687fdff 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,50 @@ -docker-compose build -docker-compose up +## alerteconso.com + +### Environment variables + +Those environment variables should be used when [building](#building) and [publishing](#publishing) the project + +|  Variable name  |  Description | +| ----------------- | ------------------------------------------------------------------------------------ | +| POSTGRES_USER |  The PostgreSQL username | +| POSTGRES_PASSWORD | The PostgreSQL password  | +| POSTGRES_HOST | The PostgresSQL hostname  | +| POSTGRES_DB | The PostgreSQL database name  | +| TAG | The tag of the api image (default to `latest`)  | +| SSL_MODE | The sslmode parameter used when connecting to database (only requird in production)  | + +### Building + +To build the image on your local environment please use following command to run the application in watch mode. + +```bash +POSTGRES_USER= POSTGRES_PASSWORD= POSTGRES_HOST= docker compose --profile dev watch +``` + +Keep your terminal open, the watch mode will follow the changes in the build context and update your application accordingly. + +> [!NOTE] +> To clean up the image and shared volume properly use `docker compose down --volume` + +### Publishing + +Once you have finished the development publish your compose application by following the following steps: + +1. Build the images in production profile + ```bash + TAG= POSTGRES_USER= POSTGRES_PASSWORD= POSTGRES_HOST= docker compose --profile prod build --platform linux/amd64,linux/arm64 + ``` +2. Push the images to the local registry + ```bash + TAG= POSTGRES_USER= POSTGRES_PASSWORD= POSTGRES_HOST= docker compose --profile prod push + ``` +3. Publish the Docker stack + ```bash + TAG= POSTGRES_USER= POSTGRES_PASSWORD= POSTGRES_HOST= docker compose --profile prod --resolve-image-digests publish /: + ``` + +### Deployment + +First create an `.env` file for the production environment, that defines values for [environment variables](#environment-variables) if you did not already. + +Once you have published the docker compose bundle and you have created the `.env` file, you can know deploy the application with `docker compose -f oci:///: --env-file up -d` diff --git a/docker-compose.yml b/docker-compose.yml index 68d21c2..179453c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,36 +1,58 @@ services: - rappel-api: + alerteconso-api-dev: + hostname: alerteconso-app build: . + image: yagcikaan/alerteconso:${TAG:-latest} + container_name: alerteconso-api + restart: unless-stopped + profiles: ["dev"] ports: - "9092:8080" depends_on: - - db + db: + condition: service_healthy + environment: + - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}?sslmode=disable + networks: + - alerteconso-network + + alerteconso-api-prod: + hostname: alerteconso-app + build: . + image: yagcikaan/alerteconso:${TAG:-latest} + container_name: alerteconso-api + restart: unless-stopped + profiles: ["prod"] + ports: + - "9092:8080" environment: - - DATABASE_URL=postgres://rappeluser:rappelpass@db:5432/rappeldb?sslmode=disable + # TODO: Enable ssl mode in production + - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}?sslmode=${SSL_MODE:-enable} networks: - - rappelconso-network - - caddy-network-rappelconso + - caddy-network-alerteconso db: + hostname: ${POSTGRES_HOST} image: postgres:17 - container_name: rappelconso-db + container_name: alerteconso-db restart: unless-stopped + profiles: ["dev"] environment: - POSTGRES_USER: rappeluser - POSTGRES_PASSWORD: rappelpass - POSTGRES_DB: rappeldb + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} ports: - "5433:5432" volumes: - pgdata:/var/lib/postgresql/data - ./schema.sql:/docker-entrypoint-initdb.d/init.sql:ro networks: - - rappelconso-network + - alerteconso-network networks: - rappelconso-network: + alerteconso-network: driver: bridge - caddy-network-rappelconso: + caddy-network-alerteconso: driver: bridge volumes: From 64f76addc2cf213034aff37bb708767d9bcfed5c Mon Sep 17 00:00:00 2001 From: Kaan Yagci Date: Mon, 25 Aug 2025 21:35:46 +0200 Subject: [PATCH 2/4] refactor: rename docker-compose to compose as the naming is changed recently Signed-off-by: Kaan Yagci --- docker-compose.yml => compose.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docker-compose.yml => compose.yml (100%) diff --git a/docker-compose.yml b/compose.yml similarity index 100% rename from docker-compose.yml rename to compose.yml From 3fb2b68f1c9aea159ed21c6fb127617a3e4d8ed0 Mon Sep 17 00:00:00 2001 From: Kaan Yagci Date: Mon, 25 Aug 2025 21:43:51 +0200 Subject: [PATCH 3/4] chore: add .gitignore file Signed-off-by: Kaan Yagci --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b5a137 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.env +.env.prod +.env.dev +.DS_Store +.vscode/ \ No newline at end of file From aa68bd38456561ece59c81932c5e93ee03c60e9e Mon Sep 17 00:00:00 2001 From: Kaan Yagci Date: Mon, 25 Aug 2025 21:44:14 +0200 Subject: [PATCH 4/4] docs: update README file for loading environment variables from .env file Signed-off-by: Kaan Yagci --- README.md | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 687fdff..01157c5 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,32 @@ Those environment variables should be used when [building](#building) and [publishing](#publishing) the project -|  Variable name  |  Description | -| ----------------- | ------------------------------------------------------------------------------------ | -| POSTGRES_USER |  The PostgreSQL username | -| POSTGRES_PASSWORD | The PostgreSQL password  | -| POSTGRES_HOST | The PostgresSQL hostname  | -| POSTGRES_DB | The PostgreSQL database name  | -| TAG | The tag of the api image (default to `latest`)  | -| SSL_MODE | The sslmode parameter used when connecting to database (only requird in production)  | +|  Variable name  |  Description | Environment | +| ----------------- | ------------------------------------------------------------------------------------ | ------------ | +| POSTGRES_USER |  The PostgreSQL username | dev and prod | +| POSTGRES_PASSWORD | The PostgreSQL password  | dev and prod | +| POSTGRES_HOST | The PostgresSQL hostname  | dev and prod | +| POSTGRES_DB | The PostgreSQL database name  | dev and prod | +| TAG | The tag of the api image (default to `latest`)  | dev | +| SSL_MODE | The sslmode parameter used when connecting to database (only requird in production)  | prod | -### Building +> [!TIP] +> You can create youself and `.env` file that defines values for those environment variables for `dev` and use `--env-file` option in the `docker compose` command instead of redfining each environment variable -To build the image on your local environment please use following command to run the application in watch mode. +### Local development + +To run the application on your local machine (dev environment) please use following command to run the application in watch mode. ```bash POSTGRES_USER= POSTGRES_PASSWORD= POSTGRES_HOST= docker compose --profile dev watch ``` +or if you have defined an `.env` file + +```bash +docker compose --env-file --profile dev watch +``` + Keep your terminal open, the watch mode will follow the changes in the build context and update your application accordingly. > [!NOTE] @@ -30,21 +39,39 @@ Keep your terminal open, the watch mode will follow the changes in the build con Once you have finished the development publish your compose application by following the following steps: +> [!TIP] +> You can create youself and `.env` file that defines values for those environment variables for `prod` and use `--env-file` option in the `docker compose` command instead of redfining each environment variable + 1. Build the images in production profile ```bash TAG= POSTGRES_USER= POSTGRES_PASSWORD= POSTGRES_HOST= docker compose --profile prod build --platform linux/amd64,linux/arm64 ``` + or if you have created an `.env` file + ```bash + docker compose --from-env --profile prod build --platform linux/amd64,linux/arm64 + ``` 2. Push the images to the local registry ```bash TAG= POSTGRES_USER= POSTGRES_PASSWORD= POSTGRES_HOST= docker compose --profile prod push ``` + or if you have created an `.env` file + ```bash + docker compose --from-env --profile prod push + ``` 3. Publish the Docker stack ```bash TAG= POSTGRES_USER= POSTGRES_PASSWORD= POSTGRES_HOST= docker compose --profile prod --resolve-image-digests publish /: ``` + or if you have created an `.env` file + ```bash + docker compose --from-env --profile prod publish + ``` ### Deployment First create an `.env` file for the production environment, that defines values for [environment variables](#environment-variables) if you did not already. -Once you have published the docker compose bundle and you have created the `.env` file, you can know deploy the application with `docker compose -f oci:///: --env-file up -d` +Once you have published the docker compose bundle and you have created the `.env` file, you can know deploy the application with: +```bash +docker compose -f oci:///: --env-file up -d +```