Persist Frappe site across domain changes and redeploys
Use stable SITE_NAME instead of SERVICE_FQDN_FRONTEND for site identity. On redeploy: reuse existing site volume, recover from duplicate empty site after domain change, and bench rename-site when folder name differs.
This commit is contained in:
parent
7d893d68b4
commit
20d1a46711
3 changed files with 23 additions and 14 deletions
|
|
@ -9,13 +9,14 @@ PULL_POLICY=if_not_present
|
||||||
DB_PASSWORD=replace-with-strong-secret
|
DB_PASSWORD=replace-with-strong-secret
|
||||||
ADMIN_PASSWORD=replace-with-strong-secret
|
ADMIN_PASSWORD=replace-with-strong-secret
|
||||||
|
|
||||||
# --- Domain (automatic — do NOT set unless overriding) ---
|
# --- Site identity (CRITICAL for production) ---
|
||||||
# 1. In Coolify UI: add domain on service "frontend", port 8080
|
# Set SITE_NAME once to your canonical Frappe site name (usually your public domain).
|
||||||
# 2. Coolify sets SERVICE_FQDN_FRONTEND → compose uses it for SITE_NAME + nginx header
|
# Do NOT rely on SERVICE_FQDN_FRONTEND alone — changing Coolify domain without SITE_NAME
|
||||||
# 3. Deploy AFTER domain is assigned (first deploy creates the Frappe site)
|
# used to create a second empty site. SITE_NAME stays fixed; change Coolify domain freely.
|
||||||
#
|
SITE_NAME=erp.aexoradao.com
|
||||||
# SITE_NAME=
|
|
||||||
# FRAPPE_SITE_NAME_HEADER=
|
# --- Domain (automatic from Coolify UI) ---
|
||||||
|
# Assign domain on service "frontend", port 8080 → SERVICE_FQDN_FRONTEND / SERVICE_URL_FRONTEND_8080
|
||||||
|
|
||||||
# --- Apps installed on first site creation only (order matters) ---
|
# --- Apps installed on first site creation only (order matters) ---
|
||||||
INSTALL_APPS=erpnext,payments,hrms,lending,lms
|
INSTALL_APPS=erpnext,payments,hrms,lending,lms
|
||||||
|
|
|
||||||
|
|
@ -104,13 +104,19 @@ services:
|
||||||
- >
|
- >
|
||||||
export CI=1;
|
export CI=1;
|
||||||
B=/usr/local/bin/bench;
|
B=/usr/local/bin/bench;
|
||||||
SITE=$$SERVICE_FQDN_FRONTEND;
|
TARGET=$${SITE_NAME:-$$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;
|
if [ -z "$$TARGET" ]; then echo "[create-site] ERROR: set SITE_NAME or assign domain to frontend:8080 in Coolify"; exit 1; fi;
|
||||||
wait-for-it -t 120 db:3306;
|
wait-for-it -t 120 db:3306;
|
||||||
wait-for-it -t 120 redis-cache:6379;
|
wait-for-it -t 120 redis-cache:6379;
|
||||||
wait-for-it -t 120 redis-queue: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
|
SITE_DIRS=$$(find sites -mindepth 1 -maxdepth 1 -type d ! -name assets 2>/dev/null | sort);
|
||||||
|
SITE_COUNT=$$(echo "$$SITE_DIRS" | grep -c . 2>/dev/null || echo 0);
|
||||||
|
if [ "$$SITE_COUNT" -gt 1 ]; then OTHER=""; for d in $$SITE_DIRS; do s=$$(basename "$$d"); if [ "$$s" != "$$TARGET" ]; then OTHER="$$s"; break; fi; done; if [ -n "$$OTHER" ] && [ -d "sites/$$TARGET" ] && [ -f "sites/$$OTHER/site_config.json" ]; then echo "[create-site] recover $$OTHER (drop empty $$TARGET)"; $$B drop-site "$$TARGET" --force --no-backup; $$B --site "$$OTHER" rename-site "$$TARGET" --force; $$B use "$$TARGET"; elif [ -n "$$OTHER" ]; then echo "[create-site] using $$OTHER"; $$B use "$$OTHER"; else echo "[create-site] ERROR: multiple sites — set SITE_NAME in Coolify"; exit 1; fi;
|
||||||
|
elif [ "$$SITE_COUNT" -eq 1 ]; then CUR=$$(basename "$$(echo "$$SITE_DIRS" | head -1)"); echo "[create-site] existing $$CUR"; $$B use "$$CUR"; if [ "$$CUR" != "$$TARGET" ]; then echo "[create-site] rename $$CUR -> $$TARGET"; $$B --site "$$CUR" rename-site "$$TARGET" --force; $$B use "$$TARGET"; fi;
|
||||||
|
elif [ -d "sites/$$TARGET" ]; then echo "[create-site] exists"; $$B use "$$TARGET";
|
||||||
|
else echo "[create-site] creating $$TARGET (first deploy)"; 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 "$$TARGET" --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:
|
environment:
|
||||||
|
- SITE_NAME
|
||||||
- SERVICE_FQDN_FRONTEND
|
- SERVICE_FQDN_FRONTEND
|
||||||
- 'ADMIN_PASSWORD=${ADMIN_PASSWORD:-changeme}'
|
- 'ADMIN_PASSWORD=${ADMIN_PASSWORD:-changeme}'
|
||||||
- 'DB_PASSWORD=${DB_PASSWORD:-changeme}'
|
- 'DB_PASSWORD=${DB_PASSWORD:-changeme}'
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,12 @@ Copy from [`coolify.env.example`](../coolify.env.example). **Required before fir
|
||||||
| `DB_PASSWORD` | yes | strong secret |
|
| `DB_PASSWORD` | yes | strong secret |
|
||||||
| `ADMIN_PASSWORD` | yes | Frappe `Administrator` password |
|
| `ADMIN_PASSWORD` | yes | Frappe `Administrator` password |
|
||||||
| `INSTALL_APPS` | yes | `erpnext,payments,hrms,lending,lms` |
|
| `INSTALL_APPS` | yes | `erpnext,payments,hrms,lending,lms` |
|
||||||
| `SITE_NAME` | **no** (auto) | From Coolify domain via `SERVICE_FQDN_FRONTEND` |
|
| `SITE_NAME` | **yes** | Canonical Frappe site name — set once (e.g. `erp.aexoradao.com`). **Do not omit** — changing Coolify domain without this created a second empty site. |
|
||||||
| `FRAPPE_SITE_NAME_HEADER` | **no** (auto) | Set at frontend start from `sites/currentsite.txt` |
|
| `FRAPPE_SITE_NAME_HEADER` | **no** (auto) | Set at frontend start from `sites/currentsite.txt` |
|
||||||
|
|
||||||
> **Coolify env cache:** If you previously set `SITE_NAME=erp.example.com` in Coolify, **delete it** so compose defaults use your real domain. Changing `docker-compose.yml` defaults alone does not update stored values.
|
> **Data persistence:** MariaDB (`db-data`), Frappe files (`sites`), and Redis queue data use **named Docker volumes** — they survive restarts and redeploys. The site **name** is stored in the `sites` volume; it must stay consistent via `SITE_NAME`.
|
||||||
|
|
||||||
|
> **Changing domain:** Set `SITE_NAME` to your target domain **before** the first deploy, or leave it set when you change Coolify's domain. On redeploy, `create-site` reuses the existing site and runs `bench rename-site` if the folder name differs from `SITE_NAME`.
|
||||||
|
|
||||||
## 3. Domain (before first deploy)
|
## 3. Domain (before first deploy)
|
||||||
|
|
||||||
|
|
@ -83,8 +85,8 @@ Login: `https://your-domain` — user `Administrator`, password = `ADMIN_PASSWOR
|
||||||
| Traefik `404 page not found` / URL unreachable | Domain on service `frontend` port **8080**; compose must declare `SERVICE_URL_FRONTEND_8080`; add `traefik.http.services.frontend.loadbalancer.server.port=8080` (Coolify 4.1.x omits port if domain has no `:8080` suffix) |
|
| Traefik `404 page not found` / URL unreachable | Domain on service `frontend` port **8080**; compose must declare `SERVICE_URL_FRONTEND_8080`; add `traefik.http.services.frontend.loadbalancer.server.port=8080` (Coolify 4.1.x omits port if domain has no `:8080` suffix) |
|
||||||
| Backend unhealthy / deploy fails after migrator | Gunicorn can take 6+ min on redeploy — backend `start_period` is 360s; healthcheck uses `Host` from `currentsite.txt` or `SERVICE_FQDN_FRONTEND` |
|
| Backend unhealthy / deploy fails after migrator | Gunicorn can take 6+ min on redeploy — backend `start_period` is 360s; healthcheck uses `Host` from `currentsite.txt` or `SERVICE_FQDN_FRONTEND` |
|
||||||
| `SITE_NAME empty` on create-site | Assign domain on `frontend:8080` before deploy (`SERVICE_FQDN_FRONTEND`) |
|
| `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 |
|
| Wrong site / setup wizard again after domain change | Set **`SITE_NAME`** in Coolify (e.g. `erp.aexoradao.com`) and redeploy — compose reuses existing site volume and renames if needed. Do not wipe volumes. |
|
||||||
| Site created with wrong name | Wipe `sites` volume or rename site manually — env change alone won't rename |
|
| Site created with wrong name | Set `SITE_NAME` and redeploy (auto rename), or `bench rename-site` manually — **never** wipe `sites` / `db-data` unless intentional |
|
||||||
| Deploy log page crashes / blank | First `create-site` is huge — fixed by filtering DocType spam; redeploy after site exists |
|
| Deploy log page crashes / blank | First `create-site` is huge — fixed by filtering DocType spam; redeploy after site exists |
|
||||||
| create-site finished but backend/scheduler not running | Deploy timed out during first site install — **redeploy** (site exists, starts in seconds) |
|
| create-site finished but backend/scheduler not running | Deploy timed out during first site install — **redeploy** (site exists, starts in seconds) |
|
||||||
| Image pull failed | Ensure `:main` on host via Jenkins or sync script — do not pull large image through Cloudflare |
|
| Image pull failed | Ensure `:main` on host via Jenkins or sync script — do not pull large image through Cloudflare |
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue