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.main
parent
9315502369
commit
95b10a3525
|
|
@ -44,4 +44,4 @@ ENV PORT=3000
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
WORKDIR /app/apps/api
|
WORKDIR /app/apps/api
|
||||||
CMD ["node", "dist/main"]
|
CMD npx prisma migrate deploy && node dist/main
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ services:
|
||||||
- "${DB_PORT_EXTERNAL:-5433}:5432"
|
- "${DB_PORT_EXTERNAL:-5433}:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U postgres -d hotdesking"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
api:
|
api:
|
||||||
build:
|
build:
|
||||||
|
|
@ -25,7 +30,8 @@ services:
|
||||||
PORT: 3000
|
PORT: 3000
|
||||||
JWT_SECRET: ${JWT_SECRET:-super-secret-change-me}
|
JWT_SECRET: ${JWT_SECRET:-super-secret-change-me}
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
web:
|
web:
|
||||||
build:
|
build:
|
||||||
|
|
@ -52,7 +58,8 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "5051:80"
|
- "5051:80"
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue