From eddbf5470eae78c61caf2a225f4902199cd4f5dd Mon Sep 17 00:00:00 2001 From: venus Date: Sun, 13 Sep 2026 14:38:49 -0500 Subject: [PATCH] updated healthcheck with a dedicated function --- .gitignore | 1 - sample-docker-compose.yml | 23 +++++++++++++++++++++++ test/healthcheck.js | 5 +++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 sample-docker-compose.yml create mode 100644 test/healthcheck.js diff --git a/.gitignore b/.gitignore index 92ea288..8d8e73d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ _site/ *.log .env docker-compose.yml -sample-docker-compose.yml diff --git a/sample-docker-compose.yml b/sample-docker-compose.yml new file mode 100644 index 0000000..3b459c2 --- /dev/null +++ b/sample-docker-compose.yml @@ -0,0 +1,23 @@ +services: + web: + build: + context: . + dockerfile: Dockerfile + args: + SITE_DOMAIN: "${SITE_DOMAIN:?Error: SITE_DOMAIN is not set. Please define SITE_DOMAIN in .env}" + SITE_URL: "${SITE_URL:-https://${SITE_DOMAIN}}" + PORT: "${PORT:-8080}" + image: river-rooks-blog:latest + container_name: river_rooks_web + restart: unless-stopped + healthcheck: + test: ["CMD", "node", "healthcheck.js"] + interval: 30s + timeout: 3s + environment: + - "SITE_DOMAIN=${SITE_DOMAIN:?Error: SITE_DOMAIN is not set. Please define SITE_DOMAIN in .env}" + - "SITE_URL=${SITE_URL:-https://${SITE_DOMAIN}}" + - "PORT=${PORT:-8080}" + ports: + - "${HOST_PORT:-${PORT:-8080}}:${PORT:-8080}" + diff --git a/test/healthcheck.js b/test/healthcheck.js new file mode 100644 index 0000000..95455e6 --- /dev/null +++ b/test/healthcheck.js @@ -0,0 +1,5 @@ +const port = process.env.PORT || 8080; + +fetch(`http://127.0.0.1:${port}/healthz`) + .then((res)) => process.exit(res.ok ? 0:1)) + .catch(() process.exit(1));