WSU-Software-Development-Club / WSU-Software-Development-Club/self-hosting

Add Docker healthchecks so the API waits for Postgres

Open Beginner friendly
#4 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

intermediate
Dominant language
JavaScript
Stars
2
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Why

Once migrations run on startup (see the SQLAlchemy/Alembic issue), the api container will crash-loop if Postgres isn't accepting connections yet. A healthcheck on db plus depends_on with condition: service_healthy makes the api wait.

Files to touch

  • docker-compose.yml

Definition of done

  • db service has a healthcheck using pg_isready
  • api has depends_on: db: condition: service_healthy
  • docker compose down -v && docker compose up from a cold start shows no DB connection errors in the api logs
  • docker compose ps shows db as healthy

Hints

The postgres image ships with pg_isready. Set a short interval and a few retries. Docs: https://docs.docker.com/reference/compose-file/services/#healthcheck

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in docker-compose.yml and read the db and api service definitions, then check the Compose healthcheck and depends_on documentation. Run docker compose down -v && docker compose up from a cold start, confirm the api logs show no DB connection errors, and verify with docker compose ps that db is healthy.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose, postgresql
Domain
databases, devops, infrastructure
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
90/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.