Skip to content

Commit

Permalink
Fix docker-compose healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Jun 6, 2023
1 parent 2b20eca commit 2b8dadd
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 65 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/gating.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,5 @@ jobs:
GREENWAVE_LISTENERS: '0'
run: |
podman-compose up -d &&
podman-compose ps &&
podman-compose logs &&
tox -e functional -- --no-cov functional-tests &&
podman-compose down
88 changes: 28 additions & 60 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
version: '3'
services:
dev:
greenwave: &greenwave
build: .
image: greenwave
user: ${DEV_USER_ID:-1000}
Expand All @@ -15,12 +15,14 @@ services:
- ./conf/policies/:/etc/greenwave/policies/:ro,z
- ./conf/subject_types/:/etc/greenwave/subject_types/:ro,z
ports:
- 8080:8080
healthcheck:
test: "curl -f http://localhost:8080/api/v1.0/about || exit 1"
- 127.0.0.1:8080:8080
healthcheck: &greenwave-healthcheck
test: >-
/src/docker/docker-entrypoint.sh python -c 'import requests;
requests.get("http://127.0.0.1:8080/healthcheck").raise_for_status();'
interval: 1s
timeout: 30s
retries: 15
timeout: 5s
retries: 30
depends_on:
- memcached
- resultsdb
Expand All @@ -30,18 +32,16 @@ services:
statsd:
image: quay.io/prometheus/statsd-exporter
ports:
- 9102:9102 # http
- 9125:9125 # statsd
- 127.0.0.1:9102:9102 # http
- 127.0.0.1:9125:9125 # statsd

resultsdb-db:
image: postgres:11.16-alpine
restart: always
env_file: ["docker/resultsdb-db.env"]
healthcheck:
<<: *greenwave-healthcheck
test: "pg_isready -U postgres || exit 1"
interval: 1s
timeout: 30s
retries: 15

resultsdb:
image: quay.io/factory2/resultsdb
Expand All @@ -54,12 +54,12 @@ services:
- ./docker/resultsdb-settings.py:/etc/resultsdb/settings.py:ro,z
- ./docker/resultsdb.conf:/etc/httpd/conf.d/resultsdb.conf:ro,z
ports:
- 5001:5001
- 127.0.0.1:5001:5001
healthcheck:
test: "curl -f http://localhost:5001 || exit 1"
interval: 1s
timeout: 30s
retries: 15
<<: *greenwave-healthcheck
test: >-
/app/entrypoint.sh python -c 'import requests;
requests.get("http://127.0.0.1:5001/api/v2.0/healthcheck").raise_for_status();'
depends_on:
- resultsdb-db

Expand All @@ -80,26 +80,24 @@ services:
- ./docker/waiverdb-settings.py:/etc/waiverdb/settings.py:ro,z
- ./docker/client_secrets.json:/etc/secret/client_secrets.json:ro,z
ports:
- 5004:5004
- 127.0.0.1:5004:5004
user: '0'
healthcheck:
test: "curl -f http://localhost:5004/api/v1.0/about || exit 1"
interval: 1s
timeout: 30s
retries: 15
<<: *greenwave-healthcheck
test: >-
/app/entrypoint.sh python -c 'import requests;
requests.get("http://127.0.0.1:5004/healthcheck").raise_for_status();'
depends_on:
- waiverdb-db

memcached:
image: "quay.io/factory2/memcached"
ports:
- 11211:11211
- 127.0.0.1:11211:11211

resultsdb-listener:
<<: *greenwave
image: greenwave
user: ${DEV_USER_ID:-1000}
working_dir: /
env_file: ["docker/dev.env"]
command:
- "gunicorn"
- "--reload"
Expand All @@ -110,29 +108,13 @@ services:
- "--enable-stdio-inheritance"
- "greenwave.resultsdb_listener:app"
ports:
- 8082:8082
volumes:
- ./:/src:ro,z
- ./docker/home:/home/dev:rw,z
- ./docker/greenwave-settings.py:/etc/greenwave/settings.py:ro,z
- ./conf/policies/:/etc/greenwave/policies/:ro,z
- ./conf/subject_types/:/etc/greenwave/subject_types/:ro,z
healthcheck:
test: "curl -f http://localhost:8082/api/v1.0/about || exit 1"
interval: 1s
timeout: 30s
retries: 15
depends_on:
- memcached
- umb
- 127.0.0.1:8082:8082
deploy:
replicas: ${GREENWAVE_LISTENERS:-1}

waiverdb-listener:
<<: *greenwave
image: greenwave
user: ${DEV_USER_ID:-1000}
working_dir: /
env_file: ["docker/dev.env"]
command:
- "gunicorn"
- "--reload"
Expand All @@ -143,21 +125,7 @@ services:
- "--enable-stdio-inheritance"
- "greenwave.waiverdb_listener:app"
ports:
- 8083:8083
volumes:
- ./:/src:ro,z
- ./docker/home:/home/dev:rw,z
- ./docker/greenwave-settings.py:/etc/greenwave/settings.py:ro,z
- ./conf/policies/:/etc/greenwave/policies/:ro,z
- ./conf/subject_types/:/etc/greenwave/subject_types/:ro,z
healthcheck:
test: "curl -f http://localhost:8083/api/v1.0/about || exit 1"
interval: 1s
timeout: 30s
retries: 15
depends_on:
- memcached
- umb
- 127.0.0.1:8083:8083
deploy:
replicas: ${GREENWAVE_LISTENERS:-1}

Expand All @@ -172,8 +140,8 @@ services:
volumes:
- ./docker/umb.yml:/etc/umb.yml:ro,z
ports:
- 5671:5671 # amqp
- 61612:61612 # stomp
- 127.0.0.1:5671:5671 # amqp
- 127.0.0.1:61612:61612 # stomp
deploy:
replicas: ${GREENWAVE_LISTENERS:-1}

Expand Down
23 changes: 23 additions & 0 deletions docker/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
COMPOSE=${COMPOSE:-podman-compose}

healthcheck() {
name=$1
url=$2
if ! curl --retry-all-errors --retry 5 --silent --fail-with-body "$url"; then
echo "ERROR: Health check for $name FAILED"
echo "--- Logs for $name ---"
"$COMPOSE" logs "$name"
exit 1
fi
echo
}

echo "Health check waiverdb"
healthcheck waiverdb http://localhost:5004/healthcheck

echo "Health check resultsdb"
healthcheck resultsdb http://localhost:5001/api/v2.0/healthcheck

echo "Health check greenwave"
healthcheck greenwave http://localhost:8080/healthcheck
4 changes: 2 additions & 2 deletions docs/docker-compose.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Check logs if needed:

.. code-block:: console
podman logs greenwave_dev_1
podman logs greenwave_greenwave_1
Run unit and functional tests:

Expand All @@ -69,7 +69,7 @@ restart the container with:

.. code-block:: console
podman restart greenwave_dev_1
podman restart greenwave_greenwave_1
You could encounter the following error when executing the application or
tests:
Expand Down
2 changes: 1 addition & 1 deletion functional-tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_cache():
backend='dogpile.cache.pymemcache',
expiration_time=5,
arguments={
'url': 'localhost:11211',
'url': '127.0.0.1:11211',
'distributed_lock': True,
},
)
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ setenv =
GREENWAVE_TEST_URL=http://localhost:8080/
WAIVERDB_TEST_URL=http://localhost:5004/
RESULTSDB_TEST_URL=http://localhost:5001/
allowlist_externals = docker/healthcheck.sh
commands =
docker/healthcheck.sh
pytest \
--cov-reset \
--cov-config=.coveragerc \
Expand Down

0 comments on commit 2b8dadd

Please sign in to comment.