From 95b10a3525d74536719d742307e2df5ab97fb4c2 Mon Sep 17 00:00:00 2001 From: Pau Costa Date: Sat, 28 Mar 2026 18:49:46 +0100 Subject: [PATCH] Add health checks for dependent services and automate DB migrations in API Dockerfile - Configure `healthcheck` for the PostgreSQL service in `docker-compose.yml`. - Update service dependencies to use `condition: service_healthy` for PostgreSQL. - Modify API Dockerfile to run `npx prisma migrate deploy` before starting the application. --- apps/api/Dockerfile | 2 +- docker-compose.yml | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/api/Dockerfile b/apps/api/Dockerfile index bca472a..b3930ff 100644 --- a/apps/api/Dockerfile +++ b/apps/api/Dockerfile @@ -44,4 +44,4 @@ ENV PORT=3000 ENV NODE_ENV=production WORKDIR /app/apps/api -CMD ["node", "dist/main"] +CMD npx prisma migrate deploy && node dist/main diff --git a/docker-compose.yml b/docker-compose.yml index 27bfa2f..ea38aad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,11 @@ services: - "${DB_PORT_EXTERNAL:-5433}:5432" volumes: - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres -d hotdesking"] + interval: 5s + timeout: 5s + retries: 5 api: build: @@ -25,7 +30,8 @@ services: PORT: 3000 JWT_SECRET: ${JWT_SECRET:-super-secret-change-me} depends_on: - - postgres + postgres: + condition: service_healthy web: build: @@ -52,7 +58,8 @@ services: ports: - "5051:80" depends_on: - - postgres + postgres: + condition: service_healthy volumes: postgres_data: