Replace postgres wait loop with Docker healthcheck#12339
Conversation
There was a problem hiding this comment.
Pull request overview
This PR simplifies local dev startup by replacing the ol-home-start.sh Postgres polling loop with Docker Compose-native gating: a db healthcheck plus home.depends_on conditioned on service_healthy.
Changes:
- Add a Postgres
healthchecktodbincompose.override.yamlusingpg_isready. - Update
hometo wait fordbto be healthy viadepends_on: condition: service_healthy. - Remove the manual Postgres wait loop from
docker/ol-home-start.sh.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| docker/ol-home-start.sh | Removes the manual Postgres readiness polling loop from the home startup script. |
| compose.override.yaml | Adds a db healthcheck and makes home depend on db health (similar to existing solr gating). |
| - ol-postgres:/var/lib/postgresql | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
| interval: 5s |
There was a problem hiding this comment.
The db healthcheck has no start_period (or similar startup grace period). With interval: 5s and retries: 5, a first-run init (or slow disk) can mark the container unhealthy very quickly, which can be confusing and can delay depends_on: condition: service_healthy until the health status recovers. Consider adding a start_period (and/or increasing retries) to better match Postgres startup times during initialization.
| interval: 5s | |
| interval: 5s | |
| start_period: 30s |
| - ./docker/ol-db-init.sh:/docker-entrypoint-initdb.d/ol-db-init.sh | ||
| - ol-postgres:/var/lib/postgresql | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U postgres"] |
There was a problem hiding this comment.
The healthcheck uses pg_isready -U postgres without -h. That checks the local Unix socket inside the db container, but other services connect over TCP via the db hostname. To make the healthcheck reflect the actual connection path, consider specifying -h localhost (and optionally -p 5432) and using the configured $${POSTGRES_USER} / $${POSTGRES_DB} rather than hardcoding postgres.
| test: ["CMD-SHELL", "pg_isready -U postgres"] | |
| test: ["CMD-SHELL", "pg_isready -h localhost -p 5432 -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] |
|
Thanks for the PR! 🤖 Copilot has been assigned for an initial review. The linked issue (#12322) hasn't been triaged yet — priority assignment typically happens on Mondays and Fridays. The PR is currently assigned to @RayBB who has 12 PRs ahead of this one. Possible improvements for this PR
PR triage checklist (maintainers / Pam)
Note This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting. |
RayBB
left a comment
There was a problem hiding this comment.
Excellent work here. This is doing just what we expected.
I think we're gonna have a much more resilient dev environment thanks to this!
I did push up a few changes to the timing so that we check quicker. I encourage you to look into the commit if you'd like to learn more.
Cheers!
…2339) Co-authored-by: RayBB <RayBB@users.noreply.github.com>
…2339) Co-authored-by: RayBB <RayBB@users.noreply.github.com>
Closes #12322
Summary
Replaces the manual Postgres polling loop in
docker/ol-home-start.shwith Docker's nativehealthcheckanddepends_onmechanism.Changes
healthcheckto thedbservice incompose.override.yamlusing thepg_isreadypatterndepends_onin thehomeservice incompose.override.yamlto usecondition: service_healthyfor thedbserviceuntil pg_isready --host db; do sleep 5; donepolling loop fromdocker/ol-home-start.sh(lines 8–9)homewait forsolrincompose.override.yaml#12321Testing
Run
docker compose upand verify thehomeservice starts only after Postgres is healthy, without the manual polling loop.Screenshots
Checklist
healthcheckadded todbservice usingpg_isreadyincompose.override.yamlhomeservicedepends_onupdated withcondition: service_healthyfordbdocker/ol-home-start.sh