Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add docker-compose healthcheck for postgres #437

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ jobs:

- name: Start DB
run: |-
docker-compose -f docker/docker-compose-postgres.yml up -d
# TODO: could we poll the port instead of sleep?
sleep 10
docker exec -i docker_postgres-db_1 psql -U postgres -t < ddl-scripts/create_tables_postgres.sql
docker compose -f docker/docker-compose-postgres.yml up --wait
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and just to repeat, the fix is:

Looks like there are two versions of docker-compose in the image, both v1 and v2. Where docker-compose is v1, while using docker compose will use the v2 plugin.

docker exec -i postgres-db psql -U postgres -t < ddl-scripts/create_tables_postgres.sql

- name: sbt test
run: |-
Expand Down Expand Up @@ -103,10 +101,8 @@ jobs:

- name: Start DB
run: |-
docker-compose -f docker/docker-compose-postgres.yml up -d
# TODO: could we poll the port instead of sleep?
sleep 10
docker exec -i docker_postgres-db_1 psql -U postgres -t < ddl-scripts/create_tables_postgres_jsonb.sql
docker compose -f docker/docker-compose-postgres.yml up --wait
docker exec -i postgres-db psql -U postgres -t < ddl-scripts/create_tables_postgres_jsonb.sql

- name: sbt test
run: |-
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ jobs:

- name: Start DB
run: |-
docker-compose -f docker/docker-compose-postgres.yml up -d
# TODO: could we poll the port instead of sleep?
sleep 10
docker exec -i docker_postgres-db_1 psql -U postgres -t < ddl-scripts/create_tables_postgres.sql
docker compose -f docker/docker-compose-postgres.yml up --wait
docker exec -i postgres-db psql -U postgres -t < ddl-scripts/create_tables_postgres.sql

- name: sbt ${{ matrix.testCmd }}
run: |-
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ The tests expect a locally running database.
It can be started with the docker-compose file in the docker folder:

```
docker-compose -f docker/docker-compose-postgres.yml up
docker-compose -f docker/docker-compose-postgres.yml up --wait
```

```
docker exec -i docker_postgres-db_1 psql -U postgres -t < ddl-scripts/create_tables_postgres.sql
docker exec -i postgres-db psql -U postgres -t < ddl-scripts/create_tables_postgres.sql
```

## Some useful debug queries for Postgres

```
docker exec -it docker_postgres-db_1 psql -U postgres
docker exec -it postgres-db psql -U postgres
```

```
Expand Down
7 changes: 7 additions & 0 deletions docker/docker-compose-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ version: '2.2'
services:
postgres-db:
image: postgres:latest
container_name: postgres-db
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
healthcheck:
test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"]
interval: 5s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't matter much but maybe this should be shorter, like 2s (and more retries)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, could be shorter. Just left it the same as earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this more closely, the healthcheck will keep being tested at this interval while the container is running. So when originally setting this up (for Kalix) the 5s interval was a balance, for getting to healthy but also not checking too frequently during running. Shorter is probably fine though.

There's a new start-interval setting coming, so that the regular healthcheck interval can be longer, and the interval during startup can be much shorter. Maybe we use that, once it's released and available. Scheduled for docker engine version 25.0.

retries: 5
start_period: 5s
timeout: 5s
4 changes: 2 additions & 2 deletions docs/src/main/paradox/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Start with:

Postgres:
: ```
docker-compose -f docker/docker-compose-postgres.yml up
docker-compose -f docker/docker-compose-postgres.yml up --wait
```

Yugabyte:
Expand All @@ -139,7 +139,7 @@ The ddl script can be run in Docker with:

Postgres:
: ```
docker exec -i docker_postgres-db_1 psql -U postgres -t < ddl-scripts/create_tables_postgres.sql
docker exec -i postgres-db psql -U postgres -t < ddl-scripts/create_tables_postgres.sql
```

Yugabyte:
Expand Down