sightbox/docker-compose.yml

204 lines
11 KiB
YAML

# Root launch path for the sightbox deployment (Dokploy points here).
# Brings up frappe_docker's unmodified stack via `include:` (base compose.yaml
# + the mariadb/redis/noproxy overrides, merged exactly as multiple -f flags
# would merge them) and adds this client's one custom service, backend-billing,
# on the same default project network. frappe_docker/ itself is never edited
# or duplicated here — see frappe_docker/docs/02-setup/05-overrides.md for
# what each included override file does.
#
# noproxy is used (not compose.https.yaml/compose.traefik.yaml) because
# Dokploy provides its own reverse proxy/TLS layer in front of whatever port
# a compose service exposes; running frappe_docker's own Traefik here would
# double up proxies. Reassess if the deployment target changes.
include:
- path:
- frappe_docker/compose.yaml
- frappe_docker/overrides/compose.mariadb.yaml
- frappe_docker/overrides/compose.redis.yaml
- frappe_docker/overrides/compose.noproxy.yaml
services:
# frappe_docker/compose.yaml hardcodes platform: linux/amd64 on every
# Frappe-image service. That's correct for the real deployment target
# (an x86_64 Dokploy VPS) but forces QEMU emulation on an Apple Silicon
# dev machine, where pyarrow's native code segfaults under emulation.
# FRAPPE_IMAGE_PLATFORM lets a local arm64 dev machine override this to
# linux/arm64 (frappe/erpnext ships a native arm64 image) via its own
# .env, without changing the default for production.
configurator:
platform: ${FRAPPE_IMAGE_PLATFORM:-linux/amd64}
backend:
platform: ${FRAPPE_IMAGE_PLATFORM:-linux/amd64}
frontend:
platform: ${FRAPPE_IMAGE_PLATFORM:-linux/amd64}
websocket:
platform: ${FRAPPE_IMAGE_PLATFORM:-linux/amd64}
queue-short:
platform: ${FRAPPE_IMAGE_PLATFORM:-linux/amd64}
queue-long:
platform: ${FRAPPE_IMAGE_PLATFORM:-linux/amd64}
scheduler:
platform: ${FRAPPE_IMAGE_PLATFORM:-linux/amd64}
marketing:
# The public BettersightBox marketing/sales page — deliberately NOT a
# Frappe Web Page. Confirmed the hard way: stock Frappe/ERPNext has no
# mechanism to serve a fully custom, unwrapped HTML document at a route
# without a custom app — every Web Page unconditionally extends
# templates/web.html, so Frappe's own topbar/footer would wrap around
# this page's own from-scratch nav/hero and double up. A plain nginx
# service serving the file directly keeps it fully decoupled from
# Frappe's templating and safe across Frappe/ERPNext upgrades.
#
# This container fronts the product's own marketing domain, separate
# from any client's ERPNext site (which lives on its own domain/
# subdomain via the `frontend` service, e.g. <client>.yourdomain.com).
# The page's own "Sign in" link is a hardcoded absolute URL to this
# bench's login page for local dev — repoint it at each real client's
# actual domain before that client's launch, same spirit as rebuilding
# the demo guides with a real client's names (see CLAUDE.md).
image: nginx:alpine
restart: unless-stopped
# content-hash label — confirmed the hard way, in production, TWICE:
# Docker Compose only recreates a container when its own service
# DEFINITION changes (image, env, labels, ...), never from a
# bind-mounted file's content changing on disk by itself. Since this
# service's definition is otherwise 100% static, Dokploy's
# AutoDeploy — which wipes and re-clones the WHOLE git checkout on
# EVERY deploy, not just ones that touch this HTML file — never had a
# reason to recreate this one container on its own.
#
# First confirmed failure mode: the container kept serving the OLD
# index.html indefinitely. Fixed by hashing bettersightbox-index.html
# and baking the hash in as this label's literal value — but that
# only forces a recreate on deploys that change THAT one file.
#
# Second, separate failure mode, confirmed later: a deploy that
# changed unrelated files (no content-hash change at all) still
# re-cloned the checkout, which orphans the assets/ directory bind
# mount below — the running container's mount still points at the
# OLD, now-deleted directory inode, so /assets/building.jpg starts
# 404ing even though index.html itself keeps serving fine (a single
# FILE bind mount doesn't have this problem; a DIRECTORY one does).
# generate-dokploy-compose.sh now bakes in the current git commit SHA
# instead of a content hash — see that script's own comment — so this
# container gets recreated on every deploy, full stop, not just ones
# that happen to touch index.html.
#
# The default below (${MARKETING_DEPLOY_TOKEN:-dev}) only applies to
# local dev, where scripts/dev.sh force-recreates this service
# unconditionally anyway (see its own comment) rather than relying on
# this label changing at all.
#
# Everything box.bettersight.io-specific lives under
# website/website-bettersightbox/ now — colocated with its sibling
# marketing sites (bi.bettersight.io, bettersight.io) under website/,
# rather than loose at the repo root.
labels:
- "content-hash=${MARKETING_DEPLOY_TOKEN:-dev}"
volumes:
- ./website/website-bettersightbox/bettersightbox-index.html:/usr/share/nginx/html/index.html:ro
# ./assets/ holds images the page references directly (e.g. the hero
# background) — served as plain static files, same as the HTML itself.
- ./website/website-bettersightbox/assets:/usr/share/nginx/html/assets:ro
# Replaces nginx:alpine's own default.conf — adds the same-origin
# /contact-lead proxy to backend-billing. See marketing-nginx.conf's
# own header comment for why it's a custom config rather than a
# second public domain/CORS setup.
- ./website/website-bettersightbox/marketing-nginx.conf:/etc/nginx/conf.d/default.conf:ro
ports:
- ${MARKETING_PUBLISH_PORT:-8091}:80
depends_on:
- backend-billing
backend-billing:
# Pre-built and pushed via backend/build.sh — the VPS only ever pulls,
# never builds, same build-locally-test-locally-ship-the-tested-artifact
# pattern as CUSTOM_IMAGE/erpnext-image/ below. BACKEND_BILLING_IMAGE
# defaults to a bare local tag (no registry path) for local dev; set it
# to a real registry path (see .env.example) once deploying for real.
image: ${BACKEND_BILLING_IMAGE:-sightbox-backend-billing}:${BACKEND_BILLING_TAG:-latest}
pull_policy: ${BACKEND_BILLING_PULL_POLICY:-never}
restart: unless-stopped
# Plain environment: vars, not env_file: ./backend/.env — confirmed the
# hard way against a real Dokploy AutoDeploy: Dokploy deletes and
# re-clones the whole git checkout on every deploy, so a file living
# inside it (as env_file: pointed at) never survives to the next
# deploy. Dokploy's own Environment tab variables, by contrast, are
# stored in Dokploy's own database and rewritten fresh into a .env next
# to this compose file on every deploy, independent of the git clone —
# the one mechanism here that's actually designed to persist. These
# four values are simple enough (no multi-line content, nothing
# structured) to move there outright; see .env.example.
environment:
TENANTS_CONFIG_PATH: ${TENANTS_CONFIG_PATH:-tenants.json}
SENTRY_DSN: ${SENTRY_DSN:-}
ENVIRONMENT: ${ENVIRONMENT:-production}
STATE_STORE_PATH: ${STATE_STORE_PATH:-/data/state.db}
# Used only by billing/contact_lead.py — the marketing page's contact
# form notification, unrelated to any tenant's own billing. See that
# module's own docstring and .env.example for where these come from.
RESEND_API_KEY: ${RESEND_API_KEY:-}
CONTACT_LEAD_NOTIFY_EMAIL: ${CONTACT_LEAD_NOTIFY_EMAIL:-}
CONTACT_LEAD_FROM_EMAIL: ${CONTACT_LEAD_FROM_EMAIL:-onboarding@resend.dev}
volumes:
- billing-state:/data
# Per-tenant credentials, mounted read-only at runtime — never baked
# into the image (see backend/.dockerignore). Multi-tenant billing:
# every client's Frappe API key/secret and Stripe webhook secret live
# here, one JSON object per tenant slug (see backend/tenants.example.json).
#
# TENANTS_JSON_PATH, not a hardcoded ./backend/tenants.json — confirmed
# the hard way: Dokploy deletes and re-clones the whole git checkout
# (including backend/) on every AutoDeploy, so a file living inside it
# never survives to the next deploy. Worse, Docker silently creates an
# empty DIRECTORY at a bind-mount source that doesn't exist yet rather
# than failing, which then crashes the app with a confusing
# IsADirectoryError instead of a clear missing-file error. The default
# below (./backend/tenants.json) is correct for local dev, where the
# checkout is stable; production must override this in .env to an
# absolute path inside $SIGHTBOX_DATA_DIR (e.g.
# /opt/sightbox/data/tenants.json) — outside the wiped checkout, and
# already covered by the nightly backup since it's already inside the
# directory backup.sh tars. See .env.example and
# INSTALLATION_PLAYBOOK.md Stage 1.
#
# Explicit long-form (type: bind), not the short-form
# "source:target:ro" string — confirmed the hard way:
# generate-dokploy-compose.sh's --no-interpolate flag (needed so
# Dokploy's own Environment tab keeps control of these values, see
# that script's header) leaves this source as a literal, unresolved
# "${TENANTS_JSON_PATH:-...}" string. `docker compose config` can't
# tell that's a path when it can't interpolate it, and silently
# normalizes the short form to type: volume instead of type: bind —
# Dokploy then rejects it as "refers to undefined volume". Declaring
# type: bind explicitly here removes the guesswork entirely.
- type: bind
source: ${TENANTS_JSON_PATH:-./backend/tenants.json}
target: /app/tenants.json
read_only: true
depends_on:
- backend
ports:
- ${BILLING_PUBLISH_PORT:-8001}:8000
volumes:
# Plain Docker-managed volumes by default — safe on any host OS. For the
# real Linux deployment target, layer docker-compose.data-dir.yml on top
# (-f docker-compose.yml -f docker-compose.data-dir.yml) to redirect these
# to one visible, backup-able host directory instead. Never do that layering
# for local dev on macOS/Windows: Docker Desktop's bind mount runs the
# container's view of that directory through the *host's* filesystem
# semantics, and macOS's default filesystem is case-insensitive — confirmed
# the hard way: MariaDB silently sets lower_case_table_names=2 against a
# case-insensitive filesystem, which does not match how this data's tables
# were actually created, and every query starts failing with "doesn't exist
# in engine". Docker's own named-volume storage (used here) lives inside
# the Desktop VM's Linux filesystem regardless of host OS, so it never hits
# this — only a host bind mount can. See playbook/BACKUP_RESTORE.md.
billing-state:
sites:
db-data:
redis-queue-data: