From 966bf698e7bfccb85c06cc8032fb89da5fd702b3 Mon Sep 17 00:00:00 2001 From: ghzhost Date: Thu, 3 Sep 2026 03:35:01 +0000 Subject: [PATCH] devops(docker): add healthchecks for db and api services (#10) - Add pg_isready-based healthcheck for the db (postgres:16-alpine) service so depends_on waits until Postgres is ready to accept connections, not just until the container has started. - Add curl /health-based healthcheck for the api service using the existing GET /health liveness probe. - Upgrade depends_on: [db] to depends_on: db: condition: service_healthy so the API container only starts after the DB is proven healthy. - Add curl to the Dockerfile runtime stage so the healthcheck command is available in the final image. Fixes #10 --- Dockerfile | 2 +- docker-compose.yml | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c9c0dbf..d885d5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/li RUN cargo build --release FROM debian:bookworm-slim -RUN apt-get update && apt-get install -y ca-certificates libssl3 && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y ca-certificates libssl3 curl && rm -rf /var/lib/apt/lists/* COPY --from=builder /app/target/release/stellarsend /usr/local/bin/ EXPOSE 3000 CMD ["stellarsend"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index bcd3ff0..609642c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,15 @@ services: ports: ["3000:3000"] env_file: - .env - depends_on: [db] + depends_on: + db: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000/health"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 30s db: image: postgres:16-alpine environment: @@ -12,5 +20,11 @@ services: POSTGRES_USER: stellarsend POSTGRES_PASSWORD: password volumes: [pgdata:/var/lib/postgresql/data] + healthcheck: + test: ["CMD-SHELL", "pg_isready -U stellarsend -d stellarsend"] + interval: 5s + timeout: 5s + retries: 10 + start_period: 10s volumes: - pgdata: \ No newline at end of file + pgdata: