From 0505a9e196b9dbc494bdfd159e80e42ad2bddbd2 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 30 Nov 2025 02:02:59 -0500 Subject: [PATCH] Add healthcheck to ensure nginx waits for uvicorn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Web service has healthcheck on /api/health - nginx depends on web being healthy before starting - Added curl to Dockerfile for healthcheck 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- Dockerfile | 3 ++- docker-compose.yml | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b9bdff0..c27c7a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,9 +21,10 @@ FROM python:3.13-slim # Install uv COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv -# Install nginx and WeasyPrint system dependencies +# Install nginx, curl (for healthcheck), and WeasyPrint system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ nginx \ + curl \ libpango-1.0-0 \ libharfbuzz0b \ libpangoft2-1.0-0 \ diff --git a/docker-compose.yml b/docker-compose.yml index 73e77e9..29aa7e2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,8 @@ services: - ./nginx.conf:/etc/nginx/nginx.conf:ro - ./kjvstudy_org/static:/app/kjvstudy_org/static:ro depends_on: - - web + web: + condition: service_healthy restart: unless-stopped web: @@ -23,3 +24,9 @@ services: - DISABLE_ANALYTICS=true restart: unless-stopped command: uv run uvicorn kjvstudy_org.server:app --host 0.0.0.0 --port 8001 --reload --reload-include '*.json' + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8001/api/health"] + interval: 5s + timeout: 5s + retries: 10 + start_period: 10s