Skip to content

Commit

Permalink
Use Docker Compose v2, wait for healthchecks to pass
Browse files Browse the repository at this point in the history
Switch to Docker Compose v2 and change `make services` to use the `--wait` flag
to wait for healthchecks to pass before exiting. Also add a healthcheck for
Elasticsearch. The Makefile changes follow the pattern in the lms app.

Together these changes mean that h and its services can be started with `make
services && make dev`, without encountering errors due to Postgres /
Elasticsearch not being ready to connect.

The `start_period` setting is set to a generous value (1 min) as normal startup
times for ES are quite long (15-20s on my 2020 Intel MacBook Pro).

See also hypothesis/lms#5556.
  • Loading branch information
robertknight committed Jul 10, 2023
1 parent e4dddaf commit f5cdd93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ help:
@echo " docker-compose in the 'h_default' network."

.PHONY: services
services: args?=up -d
services: args?=up -d --wait
services: python
@tox -qe dockercompose --run-command 'sh -c "docker network create dbs 2>/dev/null || true"'
@tox -qe dockercompose -- $(args)
@docker compose $(args)

.PHONY: db
db: args?=upgrade head
Expand Down Expand Up @@ -62,7 +61,7 @@ shell: python

.PHONY: sql
sql: python
@tox -qe dockercompose -- exec postgres psql --pset expanded=auto -U postgres
@docker compose exec postgres psql --pset expanded=auto -U postgres

.PHONY: lint
lint: frontend-lint backend-lint
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ services:
image: hypothesis/elasticsearch:latest
ports:
- '127.0.0.1:9200:9200'
healthcheck:
test: curl --fail --silent http://localhost:9200 >/dev/null
interval: 3s
start_period: 1m
environment:
- discovery.type=single-node
rabbit:
Expand Down

0 comments on commit f5cdd93

Please sign in to comment.