Skip to content

Commit e50185d

Browse files
authored
fix: healthcheck (#175)
* fix: backend health check * fix: healthcheck in compose Updated healthcheck command to use Node.js for API check. * Update Dockerfile * Update healthcheck command for backend service * Update healthcheck URL for frontend service * Update Dockerfile * Add healthcheck parameters to backend and frontend services * Add curl installation to Dockerfile * Remove continue-on-error from Docker Compose step Removed continue-on-error option from Docker Compose step.
1 parent 6510200 commit e50185d

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

.github/workflows/.e2e.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
FLYWAY_IMAGE: ghcr.io/${{ github.repository }}/migrations:${{ inputs.tag }}
2828
FRONTEND_IMAGE: ghcr.io/${{ github.repository }}/frontend:${{ inputs.tag }}
2929
run: docker compose up -d --wait
30-
continue-on-error: true
30+
3131
- name: Docker Compose Logs
3232
if: ( inputs.frontend_url == 'http://localhost:3000' )
3333
run: docker compose logs
@@ -62,4 +62,4 @@ jobs:
6262
E2E_BASE_URL: ${{ inputs.frontend_url }}
6363
CI: 'true'
6464
run: |
65-
npx playwright test --project="chromium" --reporter=blob
65+
npx playwright test --project="chromium" --reporter=blob

backend/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ COPY --from=build /app/dist ./dist
3030

3131
# Boilerplate, not used in OpenShift/Kubernetes
3232
EXPOSE 3001
33-
HEALTHCHECK --start-period=2s --start-interval=5s --interval=30s --timeout=3s CMD curl -f http://localhost:30001/api
33+
HEALTHCHECK --start-period=2s --start-interval=5s --interval=30s --timeout=3s CMD ["/nodejs/bin/node", "-pe", "require('http').get('http://[::1]:3001/api/health', function(res){console.log('Health check status:', res.statusCode); process.exit(res.statusCode === 200 ? 0 : 1)}).on('error', function(err){console.error('Health check error:', err.message); process.exit(1);});"]
3434

3535

3636
# Nonroot user, limit heap size to 50 MB
3737
USER nonroot
38-
CMD ["--max-old-space-size=50", "/app/dist/main"]
38+
CMD ["--max-old-space-size=150", "/app/dist/main"]

docker-compose.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ services:
6262
context: ./backend
6363
ports: ["3001:3001"]
6464
healthcheck:
65-
test: ["CMD", "curl", "-f", "http://localhost:3001/api"]
65+
start_interval: 5s
66+
start_period: 5s
67+
interval: 10s
68+
timeout: 3s
69+
retries: 6
70+
test: ["CMD","/nodejs/bin/node", "-pe", "require('http').get('http://[::1]:3001/api/health', function(res){console.log('Health check status:', res.statusCode); process.exit(res.statusCode === 200 ? 0 : 1)}).on('error', function(err){console.error('Health check error:', err.message); process.exit(1);});"]
6671
working_dir: "/app"
6772

6873
frontend:
@@ -77,7 +82,12 @@ services:
7782
image: ${FRONTEND_IMAGE:-frontend}
7883
ports: ["3000:3000"]
7984
healthcheck:
80-
test: ["CMD", "curl", "-f", "http://localhost:3000"]
85+
start_interval: 5s
86+
start_period: 5s
87+
interval: 10s
88+
timeout: 3s
89+
retries: 6
90+
test: ["CMD", "curl", "-f", "http://0.0.0.0:3001/health"]
8191
working_dir: "/app"
8292
depends_on:
8393
backend:

frontend/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ COPY . ./
77
RUN npm run deploy
88

99
# Deploy using Caddy to host static files
10-
FROM caddy:2.10.2-alpine
11-
RUN apk add --no-cache ca-certificates
10+
FROM caddy:2.10.0-alpine
11+
RUN apk add --no-cache \
12+
ca-certificates \
13+
curl
14+
1215

1316
# Copy static files, verify Caddyfile formatting
1417
COPY --from=build /app/dist /srv
@@ -17,7 +20,7 @@ RUN caddy fmt /etc/caddy/Caddyfile
1720

1821
# Boilerplate, not used in OpenShift/Kubernetes
1922
EXPOSE 3000 3001
20-
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:3001/health
23+
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://0.0.0.0:3001/health
2124

2225
# Nonroot user
2326
USER 1001

0 commit comments

Comments
 (0)