From 65db8477fca6a0686582a8daf1bb418db72010d4 Mon Sep 17 00:00:00 2001 From: Rachid F Date: Fri, 31 May 2024 14:28:00 -0700 Subject: [PATCH 1/8] :stethoscope: Updated docker healthchecks --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 155555183..c899b62ba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -116,8 +116,8 @@ services: networks: - backend healthcheck: - #test: ["CMD", "nc", "-z", "localhost", "${BACKEND_PORT}"] - test: ["CMD", "curl", "-f", "http://api:3000/health"] # Alternative healthcheck method + test: ["CMD", "nc", "-z", "localhost", "${BACKEND_PORT}"] + #test: ["CMD", "curl", "-f", "http://api:3000/health"] # Alternative healthcheck method interval: 10s timeout: 1s retries: 5 From 0bd06edef224b9438aab003a8d81006b3f1fab01 Mon Sep 17 00:00:00 2001 From: Rachid F Date: Fri, 31 May 2024 14:45:20 -0700 Subject: [PATCH 2/8] :stethoscope: Update healthcheck on docker-compose --- .github/workflows/docker-compose.healthcheck.yml | 1 + 1 file changed, 1 insertion(+) 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 }} From a75a1671207e8bf872615140eee42ae9ab7e0e51 Mon Sep 17 00:00:00 2001 From: Rachid F Date: Fri, 31 May 2024 15:09:56 -0700 Subject: [PATCH 3/8] :stethoscope: Update docker healthchecks --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index c899b62ba..a26461ec1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -120,7 +120,7 @@ services: #test: ["CMD", "curl", "-f", "http://api:3000/health"] # Alternative healthcheck method interval: 10s timeout: 1s - retries: 5 + retries: 50 redis: image: valkey/valkey:7.2-alpine From e11ea609d4525fd69587173f7c91f7ea3106f6c1 Mon Sep 17 00:00:00 2001 From: Rachid F Date: Fri, 31 May 2024 15:14:19 -0700 Subject: [PATCH 4/8] :stethoscope: Docker healthcheck --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a26461ec1..2c39567c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -116,7 +116,7 @@ services: networks: - backend healthcheck: - test: ["CMD", "nc", "-z", "localhost", "${BACKEND_PORT}"] + test: ["CMD", "nc", "-z", "0.0.0.0", "${BACKEND_PORT}"] #test: ["CMD", "curl", "-f", "http://api:3000/health"] # Alternative healthcheck method interval: 10s timeout: 1s From 8c00577e5d600da80c2adc07981e97d045bd07ab Mon Sep 17 00:00:00 2001 From: Rachid F Date: Fri, 31 May 2024 15:24:31 -0700 Subject: [PATCH 5/8] :stethoscope: Updated healthcheck --- docker-compose.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2c39567c9..097018f5e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -106,7 +106,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,10 +115,11 @@ services: networks: - backend healthcheck: - test: ["CMD", "nc", "-z", "0.0.0.0", "${BACKEND_PORT}"] - #test: ["CMD", "curl", "-f", "http://api:3000/health"] # Alternative healthcheck method + #test: ["CMD", "nc", "-z", "0.0.0.0", "${BACKEND_PORT}"] + test: curl --fail http://localhost || exit 1 # Alternative healthcheck method + start_period: 60s interval: 10s - timeout: 1s + timeout: 5s retries: 50 redis: From 2b0fd205fc56f8e28cd3c34c657a6b1313d6edd1 Mon Sep 17 00:00:00 2001 From: Rachid F Date: Fri, 31 May 2024 15:31:45 -0700 Subject: [PATCH 6/8] :stethoscope: Update Healthcheck --- docker-compose.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 097018f5e..dcb887b25 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -106,6 +106,7 @@ 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,10 +117,10 @@ services: - backend healthcheck: #test: ["CMD", "nc", "-z", "0.0.0.0", "${BACKEND_PORT}"] - test: curl --fail http://localhost || exit 1 # Alternative healthcheck method + test: ["CMD-SHELL", "curl", "-f", "http://localhost:3000/health"] # Alternative healthcheck method start_period: 60s interval: 10s - timeout: 5s + timeout: 1s retries: 50 redis: From 067f456d8ae52189779461a3193dd0312d618d40 Mon Sep 17 00:00:00 2001 From: Rachid F Date: Fri, 31 May 2024 16:03:50 -0700 Subject: [PATCH 7/8] :stethoscope: Healthchecks --- docker-compose.source.yml | 12 ++++++++++-- docker-compose.yml | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docker-compose.source.yml b/docker-compose.source.yml index 86147cca3..e6276b917 100644 --- a/docker-compose.source.yml +++ b/docker-compose.source.yml @@ -119,6 +119,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 +150,8 @@ services: ports: - 80:8090 depends_on: - - api + api: + condition: service_healthy networks: - backend - frontend @@ -159,7 +166,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 dcb887b25..3127febbe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -116,8 +116,7 @@ services: networks: - backend healthcheck: - #test: ["CMD", "nc", "-z", "0.0.0.0", "${BACKEND_PORT}"] - test: ["CMD-SHELL", "curl", "-f", "http://localhost:3000/health"] # Alternative healthcheck method + test: ["CMD-SHELL", "curl", "-f", "https://google.com"] start_period: 60s interval: 10s timeout: 1s From a657503fd1ac91da54ea8ff63d940aedf8428401 Mon Sep 17 00:00:00 2001 From: Rachid F Date: Fri, 31 May 2024 17:14:44 -0700 Subject: [PATCH 8/8] :stethoscope: Updated Healthchecks --- .env.example | 2 +- docker-compose.dev.yml | 2 ++ docker-compose.source.yml | 2 ++ docker-compose.yml | 4 ++-- packages/api/src/main.ts | 6 +++++- 5 files changed, 12 insertions(+), 4 deletions(-) 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/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 e6276b917..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} diff --git a/docker-compose.yml b/docker-compose.yml index 3127febbe..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 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();