37 KiB
New Client Installation Playbook
Standing up ERPNext for a new client, start to finish. A client is a Frappe site, not
necessarily a whole new stack — this VPS's bench can hold one client or several, isolated from
each other by site + tenants.json, not by a separate Docker Compose project per client. See
"Architecture" below before Stage 1 if that's new to you. Finish this playbook, then move to the
Field Ops Runbook (with this client's real names) to run the actual demo.
This is the fast path. Every native customization this deployment relies on — Custom Fields,
Client/Server Scripts, the Workflow, both Notifications, the Damage & Cost Report, permissions,
audit hardening — is automated by
provisioning/provision_client.py (Stage 5
below), not typed by hand. If that script ever fails, produces something wrong, or you need to
reproduce one piece of it manually to debug or extend it, DEVELOPER_GUIDE.md
is the detailed reference — the exact Desk UI steps and full content for every single thing the
script creates, plus the general methodology for building more of these yourself.
Architecture: one VPS, one or many clients
One docker compose up (Stage 1) brings up one bench — the shared Frappe/ERPNext containers,
MariaDB, Redis, and the backend-billing service. That's a one-time, per-VPS event, not a
per-client one. Each client is a Frappe site on that bench (bench new-site, Stage 2):
its own database (inside the shared db-data volume) and its own site folder (inside the shared
sites volume), invisible to any other site on the box.
VPS (one docker compose stack = one bench, one Stage 1)
├── backend-billing ← one shared service for every client below
│ └── tenants.json ← one entry per client, keyed by tenant_slug (Stage 9)
├── db (MariaDB) ← one shared container, one database per site
│ ├── acme site's database
│ └── beta site's database
├── sites/ ← one shared volume, one folder per site
│ ├── acme.box.bettersight.io/ (acme.localhost/ for local dev — see Stage 2)
│ └── beta.box.bettersight.io/
└── backup.sh → one nightly archive → R2 (every site above, together — see Stage 10)
Bringing on client #1: Stage 1 (bring up the stack) → Stage 2 (create the site) → ... → Stage 9 (register it as a tenant) → Stage 10 (wire up backups, once).
Bringing on client #2, months later, same VPS: skip Stage 1 — the stack, and Stage 10's
backup cron, are already running. Jump straight to Stage 2 with the new site name, run Stage 5's
provisioning script against that site, and give it its own tenants.json entry in Stage 9.
Stage 10 needs nothing further — its backup already captures every site under $SIGHTBOX_DATA_DIR
indiscriminately, this new one included, from the next nightly run onward.
Want a client fully isolated on their own hardware instead? Nothing above is mandatory — just run this entire playbook, Stage 1 included, against a separate VPS. Both models use the identical set of stages; the only variable is whether Stage 1 has already happened for the VPS you're targeting.
Restoring after a VPS failure or provider migration: restore.sh (see
BACKUP_RESTORE.md) brings every client site on that VPS back at once,
from the one shared nightly archive — there's no per-client restore, because there's no
per-client backup.
Prerequisites
- This repo's structure copied to wherever this VPS's stack will live (skip if it already exists — see "Architecture" above).
- Decided: the site name — in production,
<client-slug>.box.bettersight.io(see Stage 1's wildcard DNS note and Stage 2 below),<client>.localhostfor local testing — a DB password, and an Administrator password.
Stage 1 — Bring up the stack
Adding another client to a VPS that's already running one? Skip this entire stage — one bench serves every client on it (see "Architecture" above) — and go straight to Stage 2 with the new site name.
⚠ Confirmed the hard way, now fixed rather than just worked around: backend-billing's
config (TENANTS_CONFIG_PATH/SENTRY_DSN/ENVIRONMENT/STATE_STORE_PATH) used to live in a
separate backend/.env file, loaded via env_file: — which broke outright under Dokploy's
AutoDeploy, since Dokploy deletes and re-clones the whole git checkout on every deploy, wiping
any file that lived inside it. These four are now plain environment: vars in
docker-compose.yml, same as every other setting — just set them in .env (see .env.example)
like everything else below. No separate file, no separate step, nothing that can go stale between
deploys.
Optional — this product's own branding (recommended for a real client), before the first
docker compose up. Stock ERPNext shows its own name and logo in a few spots Website Settings
can't reach — confirmed by reading Frappe's own source, not guessed (see
DEVELOPER_GUIDE.md's "Patching the image itself" section for exactly
which spots and why). Skip this and stay on stock branding, or build the patched image once per
VPS:
./erpnext-image/build.sh
It prints three variables — CUSTOM_IMAGE, CUSTOM_TAG, PULL_POLICY=never — set them in
.env (see .env.example) before bringing up the stack below. Every Frappe-image service
(backend, frontend, queue-*, scheduler, websocket, configurator) then builds from this
image instead of the stock one, via frappe_docker's own CUSTOM_IMAGE/CUSTOM_TAG mechanism —
no edits to frappe_docker/ or this repo's own docker-compose.yml. Re-run build.sh any time
ERPNEXT_VERSION in .env changes; its own build-time checks fail loudly if a version bump means
the patches no longer apply cleanly, rather than silently shipping unpatched branding.
Required for a real client deployed via Dokploy (not optional like branding above): build and
push backend-billing's image before the first deploy.
./backend/build.sh
docker-compose.yml references ${BACKEND_BILLING_IMAGE}:${BACKEND_BILLING_TAG} with
pull_policy: never by default — correct for local dev (uses whatever was just built locally),
but on a fresh Dokploy VPS there's no image to pull at all until one has actually been pushed
somewhere it can reach. Set BACKEND_BILLING_IMAGE to a real registry path and
BACKEND_BILLING_PULL_POLICY=always in .env first (see .env.example) — build.sh detects
the registry path automatically and pushes; set DOKPLOY_URL/DOKPLOY_API_TOKEN/
DOKPLOY_COMPOSE_ID too if it should also trigger the redeploy itself. The VPS never builds this
image from source — same build-locally-test-locally-ship-the-tested-artifact reasoning as the
branding image above, and the one confirmed way to avoid Dokploy's AutoDeploy rebuilding
something slightly differently than what was actually tested. Must be always, not
missing — confirmed the hard way: missing only pulls when the tag isn't already present
locally, so once the VPS has pulled this image once, every later push under the same
:latest tag is silently never re-pulled and the container keeps running stale code
indefinitely, with no error anywhere.
Real client, on the production Linux VPS: every persistent volume this stack uses (site
data, the database, the billing state) gets bind-mounted to one visible host directory instead of
Docker's own opaque storage — this is what makes Stage 10's backups possible at all, and it has
to be set up before the first docker compose up, not retrofitted onto an already-running
site later (retrofitting means migrating live volume data by hand — safe, but unnecessary
work if this is done up front). Bind mounts don't auto-create their target directories the way a
named volume does, so create them first:
mkdir -p /opt/sightbox/data/{sites,db-data,redis-queue-data,billing-state}
[ -f /opt/sightbox/data/tenants.json ] || echo '{}' > /opt/sightbox/data/tenants.json
echo "SIGHTBOX_DATA_DIR=/opt/sightbox/data" >> .env
echo "TENANTS_JSON_PATH=/opt/sightbox/data/tenants.json" >> .env
docker compose -f docker-compose.yml -f docker-compose.data-dir.yml up -d
⚠ Confirmed the hard way: TENANTS_JSON_PATH isn't optional here the way it might look —
backend-billing's own docker-compose.yml mount defaults to a path inside the repo checkout
(./backend/tenants.json), which is correct for local dev but gets wiped on every Dokploy
AutoDeploy same as backend/.env used to. Worse than a clean failure: Docker silently creates an
empty directory at a bind-mount source that doesn't exist yet, which then crashes
backend-billing with a confusing IsADirectoryError instead of an obvious missing-file error.
The echo '{}' > above seeds a real, empty (zero-tenant) file at the durable path before the
first docker compose up — safe even before Stage 9 adds a real client, since an empty object is
a valid, zero-tenant config. Putting it inside $SIGHTBOX_DATA_DIR specifically (not some other
absolute path) means it also survives a VPS migration and is already covered by Stage 10's nightly
backup, with nothing extra to configure there.
Local dev / testing (<client>.localhost): skip the data-dir file entirely — just
docker compose up -d
⚠ Confirmed the hard way: never layer docker-compose.data-dir.yml on a macOS/Windows dev
machine. 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 — MariaDB
silently sets lower_case_table_names=2 against it, which doesn't match how the data's tables
were actually created, and every query starts failing with doesn't exist in engine. Docker's
own named-volume storage (what a bare docker compose up -d uses) lives inside the Desktop VM's
own Linux filesystem regardless of host OS, so it never hits this. See
BACKUP_RESTORE.md for the full explanation — this was found and fixed by
actually migrating a real running site's data onto this setup and watching it break.
Either way, wait for db to report healthy: docker compose ps.
⚠ This is also what brings the QR code image-generation service (backend-billing) online —
it's defined in the same docker-compose.yml as the Frappe containers, so a bare
docker compose up -d (not naming individual services) starts it automatically, before any site
even exists. It's genuinely tenant-agnostic — no per-client config needed for QR generation
itself — so once it's up here, it's already reachable and ready. Stage 5's provisioning script
only creates the Frappe-side Server/Client Scripts that call out to it; it never touches this
container, the same way it never touches MariaDB or Redis. If QR codes aren't generating on a new
site, confirm this container is actually running (docker compose ps) before suspecting the
provisioning script.
Real client via Dokploy only — one-time per VPS, skip for local dev and skip entirely if
already done for this VPS. Every client site on this box lives under one dedicated subdomain —
box.bettersight.io — as <client-slug>.box.bettersight.io. One wildcard DNS record covers every
client forever; new clients never need a new DNS entry, only Stage 2's per-client Dokploy Domain
below.
In Namecheap: Domain List → Manage next to bettersight.io → Advanced DNS tab → Add New
Record:
| Type | Host | Value | TTL |
|---|---|---|---|
| A Record | *.box |
<this VPS's public IPv4> |
Automatic |
Confirm it resolves before moving on — Namecheap propagation is usually fast but can take up to ~30 min:
dig +short anything-at-all.box.bettersight.io
should return the VPS's IP.
⚠ This wildcard matches exactly one label under box (client1.box.bettersight.io) — it does
not cover box.bettersight.io itself (add a separate, non-wildcard record if that bare
domain should resolve to anything, e.g. a shared landing page) and does not cover a second-level
label (a.b.box.bettersight.io), which this design never needs since every client is exactly one
label deep.
Stage 2 — Route the domain and create the site
Adding another client? Both steps below are per-client — run them even if Stage 1's wildcard DNS is already in place.
2a. Point this client's domain at Dokploy
Dokploy dashboard → this Compose application → Domains tab → Add Domain:
- Host:
<client-slug>.box.bettersight.io - Service Name:
frontend - Container Port:
8080(frontend's internal port — seefrappe_docker/overrides/compose.noproxy.yaml; notHTTP_PUBLISH_PORT, which is only the local-dev host-port mapping) - HTTPS: enabled, Certificate: Let's Encrypt
Save, then redeploy. ⚠ Confirmed the hard way: a Compose app's domain settings are applied as
Traefik labels at deploy time, not the moment you click Save — the new domain won't actually
route anywhere until the next deploy finishes (visible on frontend's own container labels via
docker inspect <frontend-container> --format '{{json .Config.Labels}}' — look for
traefik.enable/traefik.http.routers.* entries; their absence after a deploy means this hasn't
synced yet, not a config mistake). Dokploy generates these labels itself; nothing to hand-edit in
docker-compose.yml/docker-compose.dokploy.yml for this.
⚠ Confirmed the hard way, and genuinely surprising — check this on every new VPS:
dokploy-traefik (Dokploy's own shared reverse-proxy container, auto-provisioned once per server
when it's first registered with Dokploy — not something this playbook or any client project
creates) is not guaranteed to actually be attached to dokploy-network, the overlay network every
deployed app's containers join so Traefik can reach them. On the VPS this was found on,
dokploy-traefik had been sitting stopped for an unknown reason and came back attached only to
the default bridge network — Traefik itself started fine, TLS/Let's Encrypt issuance succeeded,
the domain's Traefik labels were correctly applied to frontend, and curl still got a clean
504 Gateway Timeout the entire time, because Traefik simply had no network path to the
container it was trying to proxy to. Every other symptom looked like a labels or DNS problem; it
wasn't. Confirm before assuming anything else is wrong:
docker inspect dokploy-traefik --format '{{json .NetworkSettings.Networks}}'
If dokploy-network isn't in that output, fix it directly:
docker network connect dokploy-network dokploy-traefik
This fix is not persistent — it's an ad-hoc docker network connect, not something stored in
any compose file or Dokploy setting, so it would need reapplying if Dokploy ever recreates its own
Traefik container (an upgrade, for instance). Worth rechecking this specific thing first if
domain routing that previously worked suddenly stops.
Skip this sub-step entirely for local dev — <client>.localhost needs no DNS or Dokploy domain,
just the site name below.
2b. Create the Frappe site
docker compose exec backend bench new-site <site-name> \
--mariadb-user-host-login-scope=% \
--db-root-username root \
--db-root-password '<DB_PASSWORD>' \
--install-app erpnext \
--admin-password '<ADMIN_PASSWORD>'
⚠ The site name must be exactly the domain the browser will send as its Host header — in
production, <client-slug>.box.bettersight.io from 2a above, verbatim; for local dev,
<client>.localhost. FRAPPE_SITE_NAME_HEADER defaults to $host, so Frappe resolves which
site's folder to serve purely off that header — a mismatch (e.g. creating the site as
client1.localhost in production) means the domain routes through Dokploy fine but Frappe 404s
or serves the wrong site underneath it.
Stage 3 — Complete the real Setup Wizard — do not script around this
Log in as Administrator at <site>/login (https://client1.box.bettersight.io/login in
production, once Stage 2a's domain is live — http://<client>.localhost:8083/login for local
dev) and walk through the actual browser wizard: company name, abbreviation, currency, country,
domain.
Bypassing this causes confirmed bugs, all discovered the hard way:
- No default language set → a Frappe locale crash (
UnboundLocalError). This isn't limited to Stock Entry rate calculations — it fires from any code path that touches date formatting, including Server Script creation, so Stage 5's provisioning script will fail confusingly partway through on an un-wizarded site. - Serial/batch tracking left off → a Stock Entry with a serialized item can end up
docstatus=1("submitted") while posting zero actual stock ledger entries — a silent, not a loud, failure. - No Chart of Accounts → "Please enter Difference Account" blocks every Stock Entry outright.
The wizard sets up all three correctly in one pass. There is no shortcut worth taking here.
Stage 4 — Enable Server Scripts bench-wide
Already done for this VPS if another client's site already went through this stage — the -g
flag below makes it bench-wide, not per-site. Safe to run again regardless; skip if unsure.
bench set-config -g server_script_enabled true
⚠ Confirmed the hard way: this flag lives in common_site_config.json (bench-global) — not
site_config.json (per-site). Running bench --site <site> set-config server_script_enabled true writes it to the wrong file, silently has no effect, and every Server Script the next stage
creates fails with ServerScriptNotEnabled — with no Error Log entry at all, since the check
happens before the script body ever runs. There is no Desk UI setting for this either. Always use
the -g flag, and always run it before Stage 5.
Stage 5 — Run the provisioning script
./provisioning/provision_client.sh <site-name>
This one command replays every site-generic native customization onto the fresh site:
- Stock Settings flags (serial/batch tracking, auto-reorder, barcode field)
- System Settings toggles (scheduler enabled, standard email footer disabled)
- The Tool Kit DocType and its child table
- Customize Form fields on Stock Entry (Signature, Photo, Issue Reason, Tool Kit — Signature and Photo mandatory) and Serial No (maintenance date fields)
- Every Client Script (Tool Kit auto-populate, maintenance-date recalculation, the QR "Regenerate" button, the Item → Serial No dropdown)
- Every Server Script (QR auto-attach on tool receipt, the QR "Regenerate" API)
- The Material Request Approval Workflow, with its states and actions
- Both Notifications (maintenance due, low stock), each with a full professional HTML email template
- The Damage & Cost Report
- The Stock Manager permission elevation on Item/Warehouse (create + write, never delete)
- Audit trail hardening (change tracking on Material Request, Deleted Document lockdown)
- The
Trial Expiredlockout Role (no Desk access, redirects to/billing) - The Custom Field
System Settings.billing_tenant_slug— set once per site in Stage 9, step 6 - The
Daily Trial Expiry CheckScheduled Server Script and theGet Billing StatusAPI Server Script (both call out tobackend-billing, both read the samebilling_tenant_slug) - The public
/billingWeb Page (status, days-to-next-bill, receipts, the reactivation Payment Link — see Stage 9, steps 7-8 for the optional data that populates it) - A "Billing" shortcut on the Stock Workspace, so
/billingis discoverable from Desk by any normal staff member — not just reachable by a locked-out User's automatic redirect
It's idempotent — safe to re-run against a site that already has some or all of this; every step checks before creating. Verified for real against a genuine second site on this bench: exact parity with the original site across every one of the items above.
⚠ This script only ever touches the Frappe site's database — never Docker infrastructure.
The two QR-related Server Scripts it creates call out to backend-billing, but the script has
no awareness of that container's existence, whether it's built, or whether it's running — that's
entirely Stage 1's job. If QR generation doesn't work right after provisioning, the scripts
themselves are almost certainly fine (this is exactly the kind of thing Stage 5's own verification
step should catch) — check that backend-billing is actually up first.
If the script fails, or you need to create/fix one piece of this by hand — a Desk UI walk-
through for every single item above, with full code, is in
DEVELOPER_GUIDE.md's "Manual fallback" section. That's also where the
methodology lives for building new customizations beyond what's listed here.
Stage 6 — Stock module foundation (client-specific — stays manual)
The provisioning script deliberately does not touch this — it's real business data, not a
generic customization. But "manual" doesn't mean clicking through Desk one field at a time:
Frappe's own Data Import tool (Desk → search "Data Import" → New Data Import) bulk-creates
records from a CSV, no code or custom app involved. Three starter templates ship in
provisioning/templates/ — copy each one, fill in this client's
real names, and import in this order (later ones reference earlier ones):
item_groups_template.csv— Consumable Parts, Tools & Equipment (parent: All Item Groups). Import against Item Group.warehouses_template.csv— Main Store, plus one per leased property and one per active construction site, plus a Damaged warehouse — damaged tools get transferred here (not written off outright) so they stay trackable while a repair-or-replace decision gets made. Replace<Your Company Name>with the exact company name from Stage 3's Setup Wizard. Import against Warehouse — leaveWarehouse Nameplain (e.g.Main Store); ERPNext appends the company abbreviation itself (Main Store - JPT) on creation, the template doesn't need to.items_template.csv—has_serial_no+ aserial_no_seriespattern (e.g.TOOL-.#####) on Tools & Equipment only; Reorder Level/Qty (the trailing four columns, via the Item Reorder child table) on Consumable Parts that need auto-reordering — leave those four blank on serialized tool rows, as in the template's own example. Import against Item, after Warehouse above — see the two gotchas below before filling in theRequest forcolumn specifically.
For each: Desk → Data Import → New Data Import → select the Doctype above → Insert New Records → upload the filled-in CSV → Start Import.
⚠ Confirmed the hard way — two values below must match Frappe's stored records exactly, not what you typed somewhere else:
- The
Companycolumn in step 2 must match the Company record's name character-for-character — including punctuation. TypingSample Cowhen the Setup Wizard actually createdSample Co.(trailing period) fails the whole warehouse import with "value missing for Company," even though it reads like a typo in the data, not the company name. Check Desk → Company for the exact stored value before filling this column in, don't rely on memory. - The
Request forcolumn in step 3 needs the warehouse's actual stored name, not the plain name you typed into step 2's CSV. ERPNext appends the company abbreviation on creation (Main StorebecomesMain Store - SC), and the Reorder Level child table references Warehouse by that full, suffixed name — using the plain name fails with "value missing for Warehouse." Check Desk → Warehouse for the exact stored name after step 2's import completes, before filling in step 3's CSV.
⚠ Confirmed against this exact ERPNext version — these are not guessed header names. Every
column header above was generated from Frappe's own Exporter class (the same code
download_template uses), not typed from memory: a mismatched header silently fails to map
during import rather than erroring clearly, so hand-typing these is genuinely risky on a version
bump. If ERPNEXT_VERSION ever changes, regenerate and diff the headers before trusting these
templates again — from bench console:
from frappe.core.doctype.data_import.exporter import Exporter
Exporter("Item", export_fields={"Item": ["item_code", "..."]}, export_data=False, file_type="CSV").get_csv_array_for_export()[0]
Stage 7 — Email delivery & the scheduler
Two of these are the provisioning script's job (system settings toggles); these two are not, since they need real per-client credentials or are host-level CLI-only:
- Email Account (fully UI-configurable): Desk → Settings → Email Account → New.
For Resend specifically: Email Address = your verified sender, check "Use different Email
ID" and set Login ID to the literal string
resend(not the email address), Password = the Resend API key, SMTP Serversmtp.resend.com, Port587, check Use TLS, check Enable Outgoing and Default Outgoing. Any other SMTP provider works the same way with its own host/port/credentials. - CLI-only, no UI equivalent: run
bench --site <site> scheduler resumeonce, from the server. This clears a separatepause_schedulerflag that lives insite_config.jsonon disk — it is host-level configuration, not application data, so nothing in Desk can reach it. A brand-new site has this paused by default.
⚠ Gotcha, confirmed the hard way: a Notification's Channel field locks after the record is first saved — this only matters if you're recreating a Notification by hand (see the Developer's Guide); the provisioning script already sets Channel correctly on creation.
Verify, don't assume: trigger a Notification's condition for real, and confirm the resulting
Email Queue record actually reaches status: Sent (Desk → Email Queue) — not just that it was
created. A queued-but-never-flushed email (step 2 above missed) looks identical to a working one
until you check.
Stage 8 — Roles & staff accounts
Create real staff Users, assign Stock User (dispatchers who raise and fulfill requests) or Stock Manager (whoever runs the store), and set each one's Default Workspace to Stock — except Administrator, which stays on the general home page.
⚠ Confirmed the hard way, changed this session: field technicians do not get a system
account at all, even a read-only one. The original design gave them Stock User for self-service
stock lookups — but Stock User carries full create/submit/cancel rights with no restriction
tying a transaction to who it's "for," so nothing actually stopped a technician from issuing
stock to themselves. Since the only real need was checking what's on hand at their site, dropping
the account entirely (they call the Dispatcher instead) closes that risk outright rather than
trying to carve out a narrower role for a need phone-based reporting already covers.
Worth knowing: ERPNext's native Stock Entry permissions give Stock User full create/write/submit/cancel rights, identical to Stock Manager — this is left as the default for the roles that actually need it (Dispatcher, Store Manager). Stock Manager's elevated rights (Item/Warehouse create+write, never delete) are already handled by Stage 5's provisioning script.
Optional — a read-only account for a stakeholder (a board member, an investor) who needs visibility but should never alter anything: assign the Stock Viewer role instead, also created by Stage 5's provisioning script. Read/report/export/print only — cost and value figures included — on Stock Entry, Material Request, Serial No, Item, Warehouse, and Stock Ledger Entry, plus both the Damage & Cost Report and Serial No Ledger; no create/write/submit/cancel/delete anywhere. Not part of daily operations — skip this for a client who doesn't need it.
Stage 9 — Wire up billing
backend-billing is multi-tenant — one running service serves every client site on this
bench, isolated by its own entry in backend/tenants.json. QR generation needs no per-client
setup at all; it's already tenant-agnostic.
(backend-billing's own SENTRY_DSN/ENVIRONMENT/path vars and its image/registry setup are
both one-time-per-bench, from Stage 1 — not something this or any later client needs to redo. If
backend-billing never came up at all back in Stage 1, its image is the first thing to check —
docker compose ps should show it running before anything below will work.)
-
Create one dedicated System Manager User for this client (e.g.
billing-service@<client>.local), no welcome email.⚠ Confirmed the hard way: on
invoice.payment_failed(or the trial-expiry check below),backend-billinglocks out every currently-unlocked User — and this account authenticates every one of those API calls. Early testing had it lock itself out along with everyone else, which invalidated its own API token mid-sweep and cascaded into 401s (and a tripped circuit breaker) for the rest of the list, meaning no one actually got locked out. Fixed infrappe_client.py: the client resolves its own username once (GET /api/method/frappe.auth.get_logged_user) and excludes it from every lock/restore sweep, the same way it excludes Administrator. Nothing to configure — this is automatic for whatever email you use in this step — but worth knowing why this account stays untouched even during a real payment failure.How "locked out" actually works, worth knowing before you see it happen: a locked-out User is never disabled (
enabledstays1) — they can still log in. What changes is their Role, swapped to a singleTrial ExpiredRole with no Desk access, which redirects them straight to the/billingpage instead. ⚠ Confirmed the hard way: a User's owndefault_workspacefield (set in Stage 8 below) silently overrides that redirect if left in place — Frappe checks it after resolving the Role's redirect and blindly sends the User to their old workspace anyway, which then 403s since Desk access is gone.frappe_client.py's lock/restore always moves Roles anddefault_workspacetogether in one call for exactly this reason; nothing to configure here either. -
Generate its API key/secret: Settings → My Settings → API Access, or
bench --site <site> execute frappe.core.doctype.user.user.generate_keys --args "['<email>']". -
Add one entry to
tenants.json(copy the shape frombackend/tenants.example.json), keyed by a slug for this client — for a real Dokploy deployment this file now lives at$SIGHTBOX_DATA_DIR/tenants.json(/opt/sightbox/data/tenants.json, seeded empty back in Stage 1), notbackend/tenants.jsoninside the repo checkout; edit it directly at that path on the VPS. Local dev still usesbackend/tenants.jsonnext to the repo, unchanged:{ "acme": { "frappe_api_url": "http://frontend:8080", "frappe_api_key": "<from step 2>", "frappe_api_secret": "<from step 2>", "stripe_webhook_secret": "<from this client's own Stripe Dashboard>" } }tenants.jsonis gitignored and mounted read-only into the container — never baked into the image.frappe_api_urlmust resolve to this client's own site: once more than one site shares thefrontendcontainer, that means this client's actual domain, not the generic service name. -
In this client's own Stripe Dashboard, register the webhook endpoint as
https://<your-domain>/webhook/stripe/<slug>. -
docker compose up -d backend-billing, then confirmGET /healthreturns{"status": "ok", "checks": {"frappe_api": {"<slug>": true, ...}}}. -
Desk → Settings → System Settings → set Billing Tenant Slug to the same slug used in step 3 (e.g.
acme). This is how the two Server Scripts Stage 5 already created — the daily trial-expiry check and the billing page's status lookup — know whichtenants.jsonentry is theirs. ⚠ Confirmed the hard way: this can't live insite_config.jsoninstead —frappe.confis not reachable at all from inside a Server Script's sandbox (neither the render nor exec safe-globals expose it), unlikefrappe.db.get_single_value, which is. Every client uses the exact same script text; only this one Desk field differs per site. -
Optional — the independent trial timer. Add
trial_start_date(ISO 8601, e.g."2026-01-01T00:00:00+00:00") andtrial_days(integer) to this tenant'stenants.jsonentry. Once that window elapses, the daily Scheduled Server Script locks the client out the same way a realinvoice.payment_failedwould — independently of whether a Stripe subscription exists yet. Leave both unset for a client who shouldn't be trial-gated at all. -
Optional — the billing status page's live Stripe data. The
/billingpage (Stage 5, redirected to automatically once a client is locked out, or visited anytime by any logged-in staff — seeCLIENT_DEMO_GUIDE.md's positioning notes) shows subscription status, days until next bill, and downloadable receipts if these three fields are also set on the tenant:stripe_restricted_key— a Stripe Restricted key, Read-only on Invoices and Subscriptions, nothing else. Never the full secret key: this code only ever looks, never charges, refunds, or modifies anything. Dashboard → Developers → API keys → Create restricted key.stripe_customer_id— this client's Stripe Customer id.stripe_payment_link_url— a Stripe Payment Link (Dashboard → Payment Links) the page shows as a "Manage Billing" button. Leave its own trial-period option off iftrial_daysabove is already handling the trial independently — that keeps the two mechanisms from double-trialing a client who resubscribes.
Leave all three unset for a client who doesn't need this yet — the page shows an "unconfigured" state rather than erroring.
Stage 10 — Wire up backups
Real client only — skip entirely for local dev/testing. Nightly snapshot of this whole
deployment to Cloudflare R2, restorable onto any brand-new Linux VPS with one script. Full design
and every gotcha found building it: BACKUP_RESTORE.md.
-
cp backup/.env.example backup/.env, fill in:SIGHTBOX_APP_DIR— for a real Dokploy deployment, this is the Dokploy-managed checkout (e.g./etc/dokploy/compose/<project-id>/code), not a traditional/opt/sightbox/appclone — confirm the real path via this Compose app's own container labels (com.docker.compose.project.working_dir) if unsure.SIGHTBOX_DATA_DIR— same path as Stage 1 either way (e.g./opt/sightbox/data).R2_ACCOUNT_ID,R2_ACCESS_KEY_ID,R2_SECRET_ACCESS_KEY,R2_BUCKET— from Cloudflare's R2 dashboard. ⚠ The headlinecfat_-prefixed value R2 shows first is a general Cloudflare API Token, not S3-compatible — rclone rejects it outright. The real Access Key ID (32 characters) and Secret Access Key (64 characters) are separate fields on the same screen; seeBACKUP_RESTORE.mdfor exactly where to look.- Retention days, if you want something other than 14 daily / 8 weekly (56 days).
⚠ Confirmed the hard way — under Dokploy,
backup/.envitself must NOT live next tobackup.shinside the checkout. That whole directory gets wiped and re-cloned on every AutoDeploy, so a file placed there (the same waybackend/.envandtenants.jsononce broke) is gone by the next deploy, or even the next cron tick after one. Instead, create it at$SIGHTBOX_DATA_DIR/backup.env(e.g./opt/sightbox/data/backup.env) and pointbackup.shat it viaBACKUP_ENV_FILE— see step 3's cron entry. Skip this relocation entirely for local dev or a traditional, non-Dokploy VPS where the checkout is stable;backup/.envnext to the script is correct there. -
Test one backup by hand and confirm it completes and the archive shows up in the R2 bucket's
daily/prefix before trusting it to cron:BACKUP_ENV_FILE=/opt/sightbox/data/backup.env ./backup/backup.sh(omit the
BACKUP_ENV_FILE=prefix for local dev / a traditional VPS, where the default next-to-the-script location is correct.) ⚠ Confirmed the hard way: on a brand-new VPS this first run installsrcloneitself (same self-installrestore.shalready did) — nothing to do manually, but the very first run takes a few seconds longer and prints an install log before the actual backup starts. -
Add the cron job — for a real Dokploy deployment, point it at the actual checkout path from step 1 and set
BACKUP_ENV_FILE:crontab -e # nightly at 3am server time 0 3 * * * BACKUP_ENV_FILE=/opt/sightbox/data/backup.env /etc/dokploy/compose/<project-id>/code/backup/backup.sh >> /var/log/sightbox-backup.log 2>&1For local dev / a traditional, non-Dokploy VPS:
0 3 * * * /opt/sightbox/app/backup/backup.sh >> /var/log/sightbox-backup.log 2>&1
Stage 11 — Done — hand off
Installation is complete. Move to the Field Ops Runbook artifact (rebuilt with this client's real property/site/item names) to actually demo the system.