From 554c873f5dba69a6d58bfa5aea11982f329806bd Mon Sep 17 00:00:00 2001 From: NishantRajputRN Date: Tue, 19 May 2026 18:12:24 +0530 Subject: [PATCH] deploy code 2 --- backend/Dockerfile | 2 ++ backend/src/index.js | 4 ++-- deploy/README.md | 9 +++++++++ deploy/docker-compose.yml | 16 +++++++--------- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index e56a371..8bf8133 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,5 +1,7 @@ FROM node:22-alpine +RUN apk add --no-cache curl + WORKDIR /app COPY package.json package-lock.json ./ diff --git a/backend/src/index.js b/backend/src/index.js index eeee422..7ab3750 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -53,7 +53,7 @@ app.get('/api/me', requireAccessToken, (req, res) => { }); }); -app.listen(port, () => { - console.log(`API listening on http://localhost:${port}`); +app.listen(port, '0.0.0.0', () => { + console.log(`API listening on http://0.0.0.0:${port}`); console.log(`OIDC issuer: ${oidcIssuer}`); }); diff --git a/deploy/README.md b/deploy/README.md index 77940c1..5845633 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -86,6 +86,15 @@ sudo ufw allow 3001/tcp docker compose --env-file .env up -d --build ``` +If the API container is unhealthy, check logs: + +```bash +docker compose --env-file .env logs api +docker compose --env-file .env ps +``` + +Rebuild after changes: `docker compose --env-file .env up -d --build api` + Verify: ```bash diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 4168169..46a2895 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -7,6 +7,8 @@ services: context: ../backend dockerfile: Dockerfile restart: unless-stopped + env_file: + - .env environment: PORT: 3001 CORS_ORIGIN: ${CORS_ORIGIN:-http://localhost} @@ -17,15 +19,11 @@ services: ports: - "${API_PORT:-3001}:3001" healthcheck: - test: - [ - "CMD-SHELL", - "node -e \"fetch('http://127.0.0.1:3001/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))\"", - ] - interval: 30s + test: ["CMD", "curl", "-fsS", "http://127.0.0.1:3001/health"] + interval: 10s timeout: 5s - retries: 3 - start_period: 10s + retries: 5 + start_period: 40s web: build: @@ -41,4 +39,4 @@ services: - "${WEB_PORT:-80}:80" depends_on: api: - condition: service_healthy + condition: service_started