Skip to content

Commit

Permalink
Wait for Postgres to start up
Browse files Browse the repository at this point in the history
We've been seeing the commands to create the databases failing on CI
with this error:

    psql: error: connection to server at "localhost" (::1), port 5437 failed: server closed the connection unexpectedly
            This probably means the server terminated abnormally
            before or while processing the request.

The problem looks like a race condition between starting the Postgres
docker container and the command that creates the DB: we're trying to
create the DB before Postgres has finished starting up.

Fix this by setting Postgres docker container options that cause it to
wait for Postgres to be up and running before continuing.

See:

https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers#running-jobs-in-containers
  • Loading branch information
seanh committed Nov 8, 2023
1 parent 53d1704 commit 83166fc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions _shared/project/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ jobs:
- {{ cookiecutter['__postgres_port'] }}:5432
env:
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
{% endif %}
{% if include_exists(".github/workflows/ci/services.yml") %}
{{- include(".github/workflows/ci/services.yml", indent=6) -}}
Expand Down

0 comments on commit 83166fc

Please sign in to comment.