diff --git a/.env.example b/.env.example index 43385a6d..c976cca9 100644 --- a/.env.example +++ b/.env.example @@ -14,6 +14,9 @@ DATABASE_URL=postgresql://postgres:your_postgres_password@host.docker.internal:5 # DATABASE_URL=postgresql://postgres:your_postgres_password@localhost:5432/games_platform_db DATABASE_PASSWORD=your_postgres_password +# 1 = run schema.sql on every backend start (slow). 0 = run npm run db:migrate on deploy only (recommended). +RUN_MIGRATE_ON_START=0 + # Phase B ports BACKEND_PORT=4000 WS_PORT=4001 diff --git a/docker-compose.yml b/docker-compose.yml index 7e4b9173..7e637fde 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -127,9 +127,21 @@ services: API_PREFIX: /api/v1 ENGINE_ENABLED: "false" WS_ENABLED: "false" - command: ["sh", "-c", "node dist/db/migrate.js && node dist/apps/api.js"] + command: ["sh", "-c", "if [ \"${RUN_MIGRATE_ON_START:-0}\" = \"1\" ]; then node dist/db/migrate.js || exit 1; fi; exec node dist/apps/api.js"] expose: - "4000" + healthcheck: + test: + [ + "CMD", + "node", + "-e", + "require('http').get('http://127.0.0.1:4000/health',(r)=>{r.resume();process.exit(r.statusCode===200?0:1)}).on('error',()=>process.exit(1))", + ] + interval: 5s + timeout: 5s + retries: 12 + start_period: 30s backend-engine: <<: *backend-common @@ -193,9 +205,12 @@ services: container_name: prediqo_nginx restart: unless-stopped depends_on: - - prediqo_web - - backend - - backend-ws + prediqo_web: + condition: service_started + backend: + condition: service_healthy + backend-ws: + condition: service_started ports: - "${PREDIQO_HTTP_PORT:-9080}:80" environment: @@ -213,9 +228,12 @@ services: container_name: prediqo_nginx_https restart: unless-stopped depends_on: - - prediqo_web - - backend - - backend-ws + prediqo_web: + condition: service_started + backend: + condition: service_healthy + backend-ws: + condition: service_started ports: - "${PREDIQO_HTTP_PORT:-9080}:80" - "${PREDIQO_HTTPS_PORT:-9443}:443" @@ -279,9 +297,12 @@ services: container_name: prediqo_nginx_ssl restart: unless-stopped depends_on: - - prediqo_web - - backend - - backend-ws + prediqo_web: + condition: service_started + backend: + condition: service_healthy + backend-ws: + condition: service_started ports: - "${PREDIQO_HTTP_PORT:-80}:80" - "${PREDIQO_HTTPS_PORT:-443}:443"