add restart tolerance

This commit is contained in:
Aaron Po
2026-10-04 20:29:37 -04:00
parent 0d74c5f47d
commit 1cda5779a4
3 changed files with 84 additions and 4 deletions

View File

@@ -20,6 +20,8 @@ services:
timeout: 5s
retries: 12
start_period: 30s
restart: unless-stopped
stop_grace_period: 60s
networks:
- prodnet
@@ -54,7 +56,7 @@ services:
database.migrations:
condition: service_completed_successfully
seaweedfs:
condition: service_started
condition: service_healthy
build:
context: ./backend
dockerfile: API/API.Core/Dockerfile
@@ -79,6 +81,20 @@ services:
SEAWEEDFS_ACCESS_KEY_ID: "${SEAWEEDFS_ACCESS_KEY_ID}"
SEAWEEDFS_SECRET_ACCESS_KEY: "${SEAWEEDFS_SECRET_ACCESS_KEY}"
SEAWEEDFS_BUCKET: "${SEAWEEDFS_BUCKET}"
healthcheck:
# The .NET runtime image carries bash but no HTTP client, so the probe speaks
# HTTP to /health over bash's /dev/tcp rather than adding curl to the image.
test:
[
"CMD",
"bash",
"-c",
'exec 3<>/dev/tcp/127.0.0.1/8080; printf "GET /health HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n" >&3; head -1 <&3 | grep -q " 200 "',
]
interval: 15s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped
networks:
- prodnet
@@ -97,6 +113,14 @@ services:
S3_BUCKET: "${SEAWEEDFS_BUCKET}"
volumes:
- seaweedfsdata-prod:/data
healthcheck:
# Probes the S3 gateway, the one component api.core talks to; it comes up
# last, after the master, volume and filer servers are serving.
test: ["CMD", "curl", "-fsS", "-o", "/dev/null", "http://localhost:8333/status"]
interval: 15s
timeout: 5s
retries: 5
start_period: 20s
restart: unless-stopped
networks:
- prodnet
@@ -107,7 +131,7 @@ services:
container_name: prod-env-frontend
depends_on:
api.core:
condition: service_started
condition: service_healthy
build:
context: ./frontend
dockerfile: Dockerfile
@@ -118,6 +142,14 @@ services:
PORT: "5656"
API_BASE_URL: "http://api.core:8080"
SESSION_SECRET: "${SESSION_SECRET}"
healthcheck:
# /healthz answers from the Express server alone, so the frontend stays
# healthy while api.core is still starting and serves its own error states.
test: ["CMD", "wget", "--quiet", "--spider", "--tries=1", "http://127.0.0.1:5656/healthz"]
interval: 15s
timeout: 5s
retries: 5
start_period: 15s
restart: unless-stopped
networks:
- prodnet

View File

@@ -6,6 +6,12 @@ const app = express();
app.use('/assets', express.static('build/client/assets', { immutable: true, maxAge: '1y' }));
app.use(express.static('build/client', { maxAge: '1h' }));
// Answers from Express alone so the container health check reports on this
// process only, independent of whether the API is reachable yet.
app.get('/healthz', (_req, res) => {
res.status(200).type('text/plain').send('ok');
});
const requestHandler = createRequestHandler({
build: () => import('./build/server/index.js'),
});