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 9e1a24a1..a3a3f8e1 100644 --- a/infra/makefile/build.mk +++ b/infra/makefile/build.mk @@ -42,8 +42,26 @@ 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 $(DB_DOCKER_SERVICE_NAME) -d + @echo "Waiting for database to be healthy..." + @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..." docker compose --env-file ./.env --profile prod up -d build-release: 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.