Skip to content

Commit

Permalink
Merge pull request #51 from co-cddo/fix-compose-init-error
Browse files Browse the repository at this point in the history
Prevent init container failing when DB is empty
  • Loading branch information
jimnarey authored Mar 11, 2024
2 parents ce4de06 + 67c32f8 commit 26b86cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ Alternatively, you can use `make up-devserver` to use the Django development ser

When the application is run, any migrations are applied to the database. Seed data for the `reviewer` user group (see below) is also applied.

When running the application for the first time, or after deleting the docker volume containing the database, it's typical for docker to throw the following error:

```
service "init" didn't completed successfully: exit 1
make: *** [Makefile:5: up-devserver] Error 1
```

Just run either `make up` or `make up-devserver` again.

## Usage instructions
Expand Down
10 changes: 8 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
<<: *common-application-variables
depends_on:
postgres:
condition: service_started
condition: service_healthy

postgres:
platform: linux/amd64
Expand All @@ -46,6 +46,11 @@ services:
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256 --auth-local=scram-sha-256"
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5

init:
<<: *api-base
Expand All @@ -54,7 +59,8 @@ services:
<<: *common-application-variables
command: [ "sh", "-c", "python manage.py migrate --noinput && python manage.py loaddata ./seed/reviewer_group.json ./seed/users.json ./seed/request.json" ]
depends_on:
- postgres
postgres:
condition: service_healthy


volumes:
Expand Down

0 comments on commit 26b86cc

Please sign in to comment.