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
|
||||
|
||||
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"
|
||||
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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue