Skip to content

Commit

Permalink
fix CKAN container healthcheck in prod/staging (#96)
Browse files Browse the repository at this point in the history
use locally running server for healthcheck test instead of the domain
add missing env var and use CKAN_PORT variable instead of hardcoded port in healthchecks

The previous healthchecks were made against the domain, this is not desirable for two reasons:
- Performed in this way the healthcheck will always succeed given that the domain is configured correctly and at least one target is healthy which should almost always be the case. Thus, it does not actually healthcheck the container itself.
- This can result in an inconsistent state if the new deployment has an issue. The healthcheck could initially succeed resulting in ECS deployment controller replacing the old deployment completely (completing the rolling update), then it would fail once the whole deployment is complete because there would no longer be any actually healthy containers.
  • Loading branch information
aymanizz authored Nov 29, 2024
1 parent aa34b22 commit 98780a3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions contrib/docker-ckan/dev.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ CKAN_SMDH__AWS_ACCOUNT_ID=
CKAN_SMDH__AWS_ACCESS_KEY_ID=
CKAN_SMDH__AWS_SECRET_ACCESS_KEY=
CKAN_SMDH__AWS_STORAGE_BUCKET_NAME=
CKAN_SMDH__AWS_STORAGE_BUCKET_REGION=

# Solr
SOLR_IMAGE_VERSION=2.9-solr8
Expand Down
9 changes: 8 additions & 1 deletion contrib/docker-ckan/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ services:
- ./src:/srv/app/src_extensions
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5000"]
test:
[
"CMD",
"wget",
"-qO",
"/dev/null",
"http://localhost:${CKAN_PORT}/api/3/action/status_show",
]

ckan-dev-worker:
<<: *ckan
Expand Down
6 changes: 6 additions & 0 deletions contrib/docker-ckan/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ x-aws-cloudformation:

services:
ckan:
ports:
# use NGINX port mapping here so that the target group CkanTCP80TargetGroup
# is correctly configured to point to the right ports. We later inject the
# NGINX sidecar and replace this port to point to CKAN's port, and also point
# the target group to the injected NGINX container instead.
- "${NGINX_PORT_HOST}:${NGINX_PORT}"
x-aws-role: &ckan-role
Version: "2012-10-17"
Statement:
Expand Down
11 changes: 8 additions & 3 deletions contrib/docker-ckan/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ services:
condition: service_healthy
volumes:
- ckan_storage:/var/lib/ckan
ports:
- "${NGINX_PORT_HOST}:${NGINX_PORT}"
healthcheck:
test: ["CMD", "wget", "-qO", "/dev/null", "${CKAN_SITE_URL}/api/3/action/status_show"]
test:
[
"CMD",
"wget",
"-qO",
"/dev/null",
"http://localhost:${CKAN_PORT}/api/3/action/status_show",
]

ckan-worker:
<<: *ckan
Expand Down

0 comments on commit 98780a3

Please sign in to comment.