From e9d8fabae918c90a293dfb6cdb9ca1adf96ea87c Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Fri, 2 Jan 2026 10:52:07 +0800 Subject: [PATCH 1/2] build --- infra/makefile/build.mk | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/infra/makefile/build.mk b/infra/makefile/build.mk index 9e1a24a1..d5d75ed4 100644 --- a/infra/makefile/build.mk +++ b/infra/makefile/build.mk @@ -42,8 +42,14 @@ build-deploy: DB_SECRET_PASSWORD="$(DB_SECRET_PASSWORD)" \ DB_SECRET_DBNAME="$(DB_SECRET_DBNAME)" chmod +x "$(DB_INFRA_SCRIPTS_PATH)/postgres-entrypoint.sh" && \ - chmod +x "$(DB_INFRA_SCRIPTS_PATH)/run-migration.sh" && \ - make db:migrate && \ + chmod +x "$(DB_INFRA_SCRIPTS_PATH)/run-migration.sh" + @echo "Starting database service..." + docker compose --env-file ./.env up api-db -d + @echo "Waiting for database to be healthy..." + @timeout 60 sh -c 'until docker inspect --format="{{.State.Health.Status}}" oullin_db 2>/dev/null | grep -q "healthy"; do sleep 2; done' || (echo "Database failed to become healthy" && exit 1) + @echo "Running migrations..." + make db:migrate + @echo "Starting remaining services..." docker compose --env-file ./.env --profile prod up -d build-release: From bb8ab70f2c26a0165e0b5f7b7abdb28e3b83cef6 Mon Sep 17 00:00:00 2001 From: Gustavo Ocanto Date: Fri, 2 Jan 2026 10:59:54 +0800 Subject: [PATCH 2/2] abstraction --- Makefile | 1 - infra/makefile/build.mk | 16 ++++++++++++++-- infra/makefile/db.mk | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 349e9ea7..a102a29c 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,6 @@ YELLOW := \033[1;33m # -------------------------------------------------------------------------------------------------------------------- # ROOT_NETWORK := oullin_net -DATABASE := "api-db" SOURCE := go_bindata ROOT_PATH := $(shell pwd) APP_PATH := $(ROOT_PATH)/ diff --git a/infra/makefile/build.mk b/infra/makefile/build.mk index d5d75ed4..a3a3f8e1 100644 --- a/infra/makefile/build.mk +++ b/infra/makefile/build.mk @@ -44,9 +44,21 @@ build-deploy: chmod +x "$(DB_INFRA_SCRIPTS_PATH)/postgres-entrypoint.sh" && \ chmod +x "$(DB_INFRA_SCRIPTS_PATH)/run-migration.sh" @echo "Starting database service..." - docker compose --env-file ./.env up api-db -d + docker compose --env-file ./.env up $(DB_DOCKER_SERVICE_NAME) -d @echo "Waiting for database to be healthy..." - @timeout 60 sh -c 'until docker inspect --format="{{.State.Health.Status}}" oullin_db 2>/dev/null | grep -q "healthy"; do sleep 2; done' || (echo "Database failed to become healthy" && exit 1) + @attempt=0; max_attempts=30; \ + while [ $$attempt -lt $$max_attempts ]; do \ + if docker inspect --format="{{.State.Health.Status}}" $(DB_DOCKER_CONTAINER_NAME) 2>/dev/null | grep -q "healthy"; then \ + echo "Database is healthy"; \ + break; \ + fi; \ + attempt=$$((attempt + 1)); \ + if [ $$attempt -eq $$max_attempts ]; then \ + echo "Database failed to become healthy after 60 seconds" >&2; \ + exit 1; \ + fi; \ + sleep 2; \ + done @echo "Running migrations..." make db:migrate @echo "Starting remaining services..." diff --git a/infra/makefile/db.mk b/infra/makefile/db.mk index 4515d903..cc50ffbf 100644 --- a/infra/makefile/db.mk +++ b/infra/makefile/db.mk @@ -5,7 +5,7 @@ DB_API_RUNNER_SERVICE := api-runner DB_DOCKER_SERVICE_NAME := api-db DB_DOCKER_CONTAINER_NAME := oullin_db -DB_MIGRATE_SERVICE_NAME := api-db-migrate +DB_MIGRATE_SERVICE_NAME := $(DB_DOCKER_SERVICE_NAME)-migrate # --- Paths # Define root paths for clarity. Assumes ROOT_PATH is exported or defined.