From 416b0f81095d54cdbdee9604fa856f0ba0e0e785 Mon Sep 17 00:00:00 2001 From: epistemophiliac Date: Tue, 16 Jun 2026 22:10:38 -0400 Subject: [PATCH] Fix backend healthcheck for multi-site Frappe routing Frappe returns 404 on /api/method/ping without a Host header matching the site name. Pass SERVICE_FQDN_FRONTEND in healthchecks and drop SITE_NAME env indirection that Coolify was caching as a literal. --- docker-compose.yml | 19 ++++++++++--------- docs/COOLIFY_DEPLOY.md | 3 ++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 318daa4..785577a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -104,14 +104,14 @@ services: - > export CI=1; B=/usr/local/bin/bench; - SITE=$$SITE_NAME; - if [ -z "$$SITE" ]; then echo "[create-site] ERROR: SITE_NAME empty — assign domain to frontend:8080 in Coolify (SERVICE_FQDN_FRONTEND)"; exit 1; fi; + SITE=$$SERVICE_FQDN_FRONTEND; + if [ -z "$$SITE" ]; then echo "[create-site] ERROR: SERVICE_FQDN_FRONTEND empty — assign domain to frontend:8080 in Coolify"; exit 1; fi; wait-for-it -t 120 db:3306; wait-for-it -t 120 redis-cache:6379; wait-for-it -t 120 redis-queue:6379; if [ -d "sites/$$SITE" ]; then echo "[create-site] exists"; $$B use "$$SITE"; else echo "[create-site] creating (10-20 min first time — verbose progress suppressed)"; INSTALL_ARGS=""; IFS=',' read -r -a apps <<< "$$INSTALL_APPS"; for app in "$${apps[@]}"; do INSTALL_ARGS="$$INSTALL_ARGS --install-app $$app"; done; set -o pipefail; $$B new-site "$$SITE" --mariadb-user-host-login-scope='%' --admin-password "$$ADMIN_PASSWORD" --db-root-password "$$DB_PASSWORD" $$INSTALL_ARGS --set-default 2>&1 | grep -vE '^Updating DocTypes for |^Creating Workspace|^Creating Desktop Icons|^Updating Dashboard for |^\* Installing |^Patching Existing|^rename_field:|^Thank you for installing|^Setting up Frappe HR'; fi environment: - - 'SITE_NAME=${SITE_NAME:-${SERVICE_FQDN_FRONTEND}}' + - SERVICE_FQDN_FRONTEND - 'ADMIN_PASSWORD=${ADMIN_PASSWORD:-changeme}' - 'DB_PASSWORD=${DB_PASSWORD:-changeme}' - 'INSTALL_APPS=${INSTALL_APPS:-erpnext,payments,hrms,lending,lms}' @@ -144,6 +144,7 @@ services: backend: <<: *backend_defaults environment: + - SERVICE_FQDN_FRONTEND - 'GUNICORN_THREADS=${GUNICORN_THREADS:-4}' - 'GUNICORN_WORKERS=${GUNICORN_WORKERS:-2}' - 'GUNICORN_TIMEOUT=${GUNICORN_TIMEOUT:-120}' @@ -155,11 +156,11 @@ services: migrator: condition: service_completed_successfully healthcheck: - test: ['CMD-SHELL', 'curl -sf http://localhost:8000/api/method/ping || exit 1'] + test: ['CMD-SHELL', 'curl -sf -H "Host: $$SERVICE_FQDN_FRONTEND" http://127.0.0.1:8000/api/method/ping || exit 1'] interval: 15s timeout: 10s - retries: 10 - start_period: 120s + retries: 15 + start_period: 180s websocket: <<: [*depends_on_configurator, *customizable_image, *frappe_platform, *sites_volume] @@ -180,7 +181,7 @@ services: - SERVICE_FQDN_FRONTEND - 'BACKEND=backend:8000' - 'SOCKETIO=websocket:9000' - - 'FRAPPE_SITE_NAME_HEADER=${FRAPPE_SITE_NAME_HEADER:-${SERVICE_FQDN_FRONTEND}}' + - 'FRAPPE_SITE_NAME_HEADER=${SERVICE_FQDN_FRONTEND}' - 'UPSTREAM_REAL_IP_ADDRESS=${UPSTREAM_REAL_IP_ADDRESS:-127.0.0.1}' - 'UPSTREAM_REAL_IP_HEADER=${UPSTREAM_REAL_IP_HEADER:-X-Forwarded-For}' - 'UPSTREAM_REAL_IP_RECURSIVE=${UPSTREAM_REAL_IP_RECURSIVE:-off}' @@ -194,11 +195,11 @@ services: websocket: condition: service_started healthcheck: - test: ['CMD-SHELL', 'curl -sf http://localhost:8080/ || exit 1'] + test: ['CMD-SHELL', 'curl -sf -H "Host: $$SERVICE_FQDN_FRONTEND" http://127.0.0.1:8080/api/method/ping || exit 1'] interval: 15s timeout: 10s retries: 15 - start_period: 90s + start_period: 120s queue-short: <<: *backend_defaults diff --git a/docs/COOLIFY_DEPLOY.md b/docs/COOLIFY_DEPLOY.md index c267a98..b33307b 100644 --- a/docs/COOLIFY_DEPLOY.md +++ b/docs/COOLIFY_DEPLOY.md @@ -80,7 +80,8 @@ Login: `https://your-domain` — user `Administrator`, password = `ADMIN_PASSWOR | Symptom | Fix | |---------|-----| -| `SITE_NAME empty` on create-site | Assign domain on `frontend:8080` before deploy | +| Backend unhealthy / deploy fails after migrator | Healthcheck must send `Host: ` — fixed in compose; redeploy | +| `SITE_NAME empty` on create-site | Assign domain on `frontend:8080` before deploy (`SERVICE_FQDN_FRONTEND`) | | Wrong site / 404 nginx | Delete old `SITE_NAME` in Coolify UI; ensure header matches domain | | Site created with wrong name | Wipe `sites` volume or rename site manually — env change alone won't rename | | Deploy log page crashes / blank | First `create-site` is huge — fixed by filtering DocType spam; redeploy after site exists |