(feature): docker health checks (#12124) (#12749)

* Add Docker container health checks

* Use invoke tasks for Docker container health checks

Updates server and worker healthchecks to use invoke server-health
and invoke worker-health as requested in #12124 review.

Refs #12124

* Added HTTP host check to server health check

* Add health-check endpoint for Caddyfile

* Simplify health check for Caddy

* Remove test file

---------




(cherry picked from commit 773ed4eb3a)

Co-authored-by: getpwnam <cp@evilbit.co.uk>
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
Co-authored-by: DESKTOP-691E36A\Administrator <br198064@gmail.com>
Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
github-actions[bot]
2026-08-31 21:01:18 +10:00
committed by GitHub
co-authored by getpwnam Oliver DESKTOP-691E36A\Administrator Matthias Mair
parent 2fbaa02a07
commit d68411571f
3 changed files with 76 additions and 6 deletions
+20 -2
View File
@@ -1665,15 +1665,33 @@ def server_health(c, address: str = 'http://localhost:8000', timeout: int = 5):
"""Check if the web server is healthy by requesting /api/system/health/.
Exits 0 on HTTP 200, 1 otherwise.
No Django startup required.
Django startup only required when when INVENTREE_SITE_URL is not set
and no docker/devcontainer/pkg-installer env vars are set. Django exceptions
caught and logged as warnings, but do not cause the health check to fail.
"""
import urllib.error
import urllib.parse
import urllib.request
from src.backend.InvenTree.InvenTree.config import ( # type: ignore[import]
get_setting,
)
url = f'{address.rstrip("/")}/api/system/health/'
site_url = None
try:
with urllib.request.urlopen(url, timeout=timeout) as response:
site_url = get_setting('INVENTREE_SITE_URL', 'site_url', None)
except (Exception, SystemExit) as exc:
warning(f'Could not determine configured site URL: {exc}')
request = urllib.request.Request(url)
if site_url and (hostname := urllib.parse.urlparse(site_url).hostname):
request.add_header('Host', hostname)
try:
with urllib.request.urlopen(request, timeout=timeout) as response:
if response.status == 200:
success(f'Server is healthy ({url})')
return