diff --git a/.env.example b/.env.example index eb1f30f53..a3230e4a4 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,7 @@ OAUTH_REDIRECT_BASE=http://localhost:3000 JWT_SECRET=secret_jwt ENCRYPT_CRYPTO_SECRET_KEY="0123456789abcdef0123456789abcdef" BACKEND_PORT=3000 - +BACKEND_HOSTNAME="0.0.0.0" #Managed only SENTRY_DSN= diff --git a/.github/workflows/docker-compose.healthcheck.yml b/.github/workflows/docker-compose.healthcheck.yml index 589241ab6..1e0c699bc 100644 --- a/.github/workflows/docker-compose.healthcheck.yml +++ b/.github/workflows/docker-compose.healthcheck.yml @@ -13,6 +13,7 @@ jobs: environment: SELF_HOSTED env: POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + BACKEND_PORT: ${{ secrets.BACKEND_PORT }} POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} POSTGRES_DB: ${{ secrets.POSTGRES_DB }} DISTRIBUTION: ${{ secrets.DISTRIBUTION }} diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 795d528e8..974f73032 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -36,6 +36,8 @@ services: REDIS_HOST: ${REDIS_HOST} REDIS_PASS: ${REDIS_PASS} REDIS_PORT: ${REDIS_PORT} + BACKEND_HOSTNAME: ${BACKEND_HOSTNAME} + BACKEND_PORT: ${BACKEND_PORT} ENCRYPT_CRYPTO_SECRET_KEY: ${ENCRYPT_CRYPTO_SECRET_KEY} HUBSPOT_CRM_CLOUD_CLIENT_ID: ${HUBSPOT_CRM_CLOUD_CLIENT_ID} HUBSPOT_CRM_CLOUD_CLIENT_SECRET: ${HUBSPOT_CRM_CLOUD_CLIENT_SECRET} diff --git a/docker-compose.source.yml b/docker-compose.source.yml index 86147cca3..517a4af94 100644 --- a/docker-compose.source.yml +++ b/docker-compose.source.yml @@ -37,6 +37,8 @@ services: REDIS_HOST: ${REDIS_HOST} REDIS_PASS: ${REDIS_PASS} REDIS_PORT: ${REDIS_PORT} + BACKEND_HOSTNAME: ${BACKEND_HOSTNAME} + BACKEND_PORT: ${BACKEND_PORT} ENCRYPT_CRYPTO_SECRET_KEY: ${ENCRYPT_CRYPTO_SECRET_KEY} HUBSPOT_CRM_CLOUD_CLIENT_ID: ${HUBSPOT_CRM_CLOUD_CLIENT_ID} HUBSPOT_CRM_CLOUD_CLIENT_SECRET: ${HUBSPOT_CRM_CLOUD_CLIENT_SECRET} @@ -119,6 +121,12 @@ services: condition: service_healthy networks: - backend + healthcheck: + test: ["CMD-SHELL", "curl", "-f", "http://localhost:3000/health"] + start_period: 60s + interval: 10s + timeout: 1s + retries: 50 redis: image: valkey/valkey:7.2-alpine @@ -144,7 +152,8 @@ services: ports: - 80:8090 depends_on: - - api + api: + condition: service_healthy networks: - backend - frontend @@ -159,7 +168,8 @@ services: ports: - 81:80 depends_on: - - api + api: + condition: service_healthy networks: - backend - frontend diff --git a/docker-compose.yml b/docker-compose.yml index 155555183..0912af5b1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,12 +26,13 @@ services: image: panoradotdev/backend-api:selfhosted environment: DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}?ssl=false - PORT: ${BACKEND_PORT} DISTRIBUTION: ${DISTRIBUTION} JWT_SECRET: ${JWT_SECRET} REDIS_HOST: ${REDIS_HOST} REDIS_PASS: ${REDIS_PASS} REDIS_PORT: ${REDIS_PORT} + BACKEND_HOSTNAME: ${BACKEND_HOSTNAME} + BACKEND_PORT: ${BACKEND_PORT} ENCRYPT_CRYPTO_SECRET_KEY: ${ENCRYPT_CRYPTO_SECRET_KEY} HUBSPOT_CRM_CLOUD_CLIENT_ID: ${HUBSPOT_CRM_CLOUD_CLIENT_ID} HUBSPOT_CRM_CLOUD_CLIENT_SECRET: ${HUBSPOT_CRM_CLOUD_CLIENT_SECRET} @@ -106,7 +107,6 @@ services: MAILCHIMP_MARKETINGAUTOMATION_CLOUD_CLIENT_SECRET: ${MAILCHIMP_MARKETINGAUTOMATION_CLOUD_CLIENT_SECRET} PODIUM_MARKETINGAUTOMATION_CLOUD_CLIENT_ID: ${PODIUM_MARKETINGAUTOMATION_CLOUD_CLIENT_ID} PODIUM_MARKETINGAUTOMATION_CLOUD_CLIENT_SECRET: ${PODIUM_MARKETINGAUTOMATION_CLOUD_CLIENT_SECRET} - restart: unless-stopped ports: - 3000:3000 @@ -116,11 +116,11 @@ services: networks: - backend healthcheck: - #test: ["CMD", "nc", "-z", "localhost", "${BACKEND_PORT}"] - test: ["CMD", "curl", "-f", "http://api:3000/health"] # Alternative healthcheck method + test: ["CMD-SHELL", "curl", "-f", "https://google.com"] + start_period: 60s interval: 10s timeout: 1s - retries: 5 + retries: 50 redis: image: valkey/valkey:7.2-alpine diff --git a/packages/api/src/main.ts b/packages/api/src/main.ts index 61b1ccaf2..8d60cc284 100644 --- a/packages/api/src/main.ts +++ b/packages/api/src/main.ts @@ -29,6 +29,10 @@ async function bootstrap() { app.useGlobalInterceptors(new LoggerErrorInterceptor()); app.use(cookieParser()); - await app.listen(3000); + + // Passing a host is required by some PaaS providers such as flightcontrol + const port = process.env.BACKEND_PORT || 3000; + const host = process.env.BACKEND_HOSTNAME || '0.0.0.0'; + await app.listen(port, host); } bootstrap();