Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Docker: check Gunicorn before Nginx in HEALTHCHECK and support DISABLE_NGINX=true

sassanix7d8d1455ef19
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c2075b..cf5caf5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -82,8 +82,8 @@
- _Files: `backend/warranties_routes.py`, `tests/test_frontend_and_locales.py`_
- **Docker image no longer logs a startup permission error:** Gunicorn 26 tried to write to the home directory on startup, but the container process had no home set, so every start logged a Permission denied error for /root/.gunicorn. The app still started and worked, the error was only log noise. The gunicorn process now runs with HOME set to /home/warracker, so the error is gone.
- _Files: `Docker/supervisord.conf`, `tests/docker_smoke_test.sh`_
-- **Cleaner Docker startup logs:** the startup banner check polled Nginx before Gunicorn finished booting, which logged a few transient `connect() failed (111: Connection refused)` Nginx errors on every normal container start, and supervisord logged every lifecycle line twice because `nodaemon=true` and `logfile=/dev/stdout` both wrote to stdout. The banner check now waits for Gunicorn (`127.0.0.1:5000/api/health`) before probing Nginx, and `supervisord.conf` sets `logfile=/dev/null`, keeping startup logs clean and single-printed.
- - _Files: `Docker/entrypoint.sh`, `Docker/supervisord.conf`, `tests/docker_smoke_test.sh`_
+- **Cleaner Docker startup logs:** the startup banner check and Docker `HEALTHCHECK` polled Nginx before Gunicorn finished booting, which logged transient `connect() failed (111: Connection refused)` Nginx errors on every normal container start (and caused `DISABLE_NGINX=true` containers to fail the port-80 healthcheck), and supervisord logged every lifecycle line twice because `nodaemon=true` and `logfile=/dev/stdout` both wrote to stdout. Both checks now verify Gunicorn (`127.0.0.1:5000/api/health`) before probing Nginx (skipping the port-80 probe when `DISABLE_NGINX=true`), and `supervisord.conf` sets `logfile=/dev/null`, keeping startup logs clean and single-printed.
+ - _Files: `Dockerfile`, `Docker/entrypoint.sh`, `Docker/supervisord.conf`, `tests/docker_smoke_test.sh`_
## 1.0.6 - 2026-11-10
diff --git a/Dockerfile b/Dockerfile
index 97e72e9..a5162b8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -113,11 +113,11 @@ ENV PYTHONUNBUFFERED=1 \
# Clean default nginx site
RUN rm -f /etc/nginx/sites-enabled/default
-# Optimized health check - hits the backend's /api/health (which verifies DB
-# connectivity) so a frozen backend is detected instead of the container
-# reporting healthy via nginx alone (see issue #239).
+# Optimized health check - probes gunicorn directly first (avoiding transient
+# nginx "Connection refused" logs during startup and supporting DISABLE_NGINX=true),
+# then verifies nginx proxying when nginx is enabled (see issues #190 and #239).
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
- CMD curl -f http://localhost/api/health || exit 1
+ CMD curl -fs http://127.0.0.1:5000/api/health > /dev/null && ([ "${DISABLE_NGINX:-false}" = "true" ] || curl -fs http://localhost/api/health > /dev/null) || exit 1
# Exposed port
EXPOSE 80
diff --git a/tests/docker_smoke_test.sh b/tests/docker_smoke_test.sh
index d4b66fd..afca026 100755
--- a/tests/docker_smoke_test.sh
+++ b/tests/docker_smoke_test.sh
@@ -259,6 +259,8 @@ docker run -d --name "${APP_CTR}" --network "${NET}" \
"${IMAGE}" >/dev/null
wait_for_health "${APP_CTR}" "http://127.0.0.1:18007/api/health"
+docker exec "${APP_CTR}" sh -c 'curl -fs http://127.0.0.1:5000/api/health > /dev/null && ([ "${DISABLE_NGINX:-false}" = "true" ] || curl -fs http://localhost/api/health > /dev/null)' \
+ || fail "HEALTHCHECK command failed under DISABLE_NGINX=true"
if docker exec "${APP_CTR}" python -c "
import glob, sys
comms = []