Docs Self-Hosting TrueNAS / Docker

Self-Hosting Guide (TrueNAS / Docker)

Deploy the Camp Store v2.0 4-container stack with PostgreSQL 17 logical replication, PowerSync Open Edition, Better Auth, and Nginx behind Traefik or Cloudflare.

For Self-Hosters & Camp IT Leads. Camp Store v2.0 deploys automatically to TrueNAS SCALE or any Docker Compose host via Gitea Actions — with zero manual .env file setup required.


1. Stack Architecture

Camp Store v2.0 separates authentication/API, logical replication sync, database storage, and static marketing/docs into four lightweight services:

Service Hostname (Example) Port Role
camp-store-postgres Internal (default only) 5432 PostgreSQL 17 with wal_level=logical, separate campstore and powersync_storage databases, powersync publication, and Better Auth tables.
camp-store-powersync sync.campstore.app 8080 PowerSync Service (start -r unified) using Edition 2 bucket_definitions sync rules and JWKS JWT verification.
camp-store-server campstore.app 80 Node 24 + Hono API server, Better Auth (Passkeys + Email/Password + JWKS), PowerSync CRUD upload receiver, and bundled Expo Web POS app.
camp-store-www www.campstore.app 80 Nginx Alpine serving this Astro 5 static landing page and documentation portal with /healthz.

2. Database & PowerSync Isolation Rules

Two architectural guardrails keep replication fast and loop-free:

  1. Separate powersync_storage Database: infra/postgres/init/00-init-dbs.sql creates a dedicated powersync_storage database alongside campstore. Keeping PowerSync’s internal bucket/checkpoint storage in its own logical database prevents sync engine writes from feeding back into campstore’s logical replication WAL stream.
  2. Scoped PUBLICATION powersync: Only domain tables (staff_profiles, camps, camp_members, camp_invites, categories, products, campers, ledger_entries, ledger_items, inventory_movements, sync_rejections) are added to PUBLICATION powersync. Better Auth credential tables ("user", "session", "account", "verification", "jwks", "passkey") stay local to PostgreSQL and are never replicated to client SQLite databases. Instead, an AFTER INSERT OR UPDATE trigger (sync_user_to_staff_profiles) mirrors safe profile fields into staff_profiles and auto-claims matching camp_invites.
  3. Edition 2 Sync Rules (bucket_definitions): PowerSync Open Edition requires compiled or Edition 2 bucket_definitions in infra/powersync/sync_rules.yaml:
    • user_self: syncs staff_profiles and sync_rejections scoped by request.user_id().
    • by_camp: syncs all camp operational tables parameterized by SELECT camp_id FROM camp_members WHERE user_id = request.user_id().

3. Zero-Env Configuration & TrueNAS Automation

Camp Store does not use manually created .env files on TrueNAS or local workstations:

  1. Automated CI/CD Deploy (truenas-deploy@main): Pushing to master runs .gitea/workflows/deploy.yml, builds and pushes linux/amd64 container images with Gitea registry build caching, syncs docker-compose.yml to /mnt/jupiter/apps/rodydavis/camp_store/, and verifies live HTTP 200 health responses after startup.
  2. Optional Gitea Secrets & Vars: If you configure repository secrets.* (POSTGRES_PASSWORD, BETTER_AUTH_SECRET) or vars.* (BETTER_AUTH_URL, POWERSYNC_URL, PS_AUDIENCE, APPLE_TEAM_ID, ANDROID_SHA256_FINGERPRINTS) in Gitea, the workflow passes them automatically. If omitted, safe defaults apply immediately.
  3. Auto-Persisted Auth Signing Key: When BETTER_AUTH_SECRET is not explicitly set, camp-store-server generates a cryptographically strong 256-bit random key on first boot and saves it to /app/data/auth-secret.key (./data/server/auth-secret.key on the TrueNAS ZFS dataset), keeping sessions intact across container upgrades.
  4. Private Database Network: camp-store-postgres binds only to the Compose internal default network (never apps-net), keeping database credentials unreachable from other containers or the public proxy.

Proxy & Cookie Note: When deploying behind Traefik or Cloudflare Tunnel, terminate TLS at the edge proxy and route HTTP traffic into camp-store-server:80, camp-store-powersync:8080, and camp-store-www:80 over the shared external apps-net Docker network. BETTER_AUTH_URL defaults to https://campstore.app so Passkey RP ID (campstore.app) and secure session cookies match the browser origin.


4. Deploying & Local Stack Usage

Make sure the shared Traefik proxy network exists once on the production host:

docker network create apps-net || true

Deploy or update the production stack manually if needed (using ./data/pg_data and ./data/server ZFS bind mounts):

docker compose pull
docker compose up -d --remove-orphans

Verify container health:

docker compose ps
curl -fsS http://localhost/healthz

Running Local PostgreSQL & PowerSync for Development

Start a local database and PowerSync sync node directly with docker-compose.dev.yml:

docker compose -f docker-compose.dev.yml up -d

Every Dockerfile in the monorepo builds from the repository root (context: .), and apps/www/nginx/nginx.conf disables absolute/port redirects (absolute_redirect off; port_in_redirect off;), enables gzip, sets immutable caching on /_astro/* assets, forces no-cache on HTML pages, and exposes GET /healthz.


5. Migrating Data from Camp Store v1.x (Firebase)

Upgrading from a Camp Store v1.x Firebase/Firestore deployment is idempotent via legacy_firestore_id columns on camps, categories, products, campers, and ledger_entries. Pass connection details directly via CLI flags:

pnpm migrate:firebase -- \
  --credentials ./service-account.json \
  --project camp-store-23521 \
  --database-url postgresql://campstore:campstore@localhost:5432/campstore \
  --dry-run

Remove --dry-run when ready to commit. Because every migrated entity carries a UNIQUE(camp_id, legacy_firestore_id) constraint, re-running the importer safely skips previously migrated rows without creating duplicates.


6. Backups & Monitoring

  • ZFS Dataset Snapshots & Backups: All persistent production state lives under /mnt/jupiter/apps/rodydavis/camp_store/data/ (./data/pg_data for PostgreSQL 17 and ./data/server for the auth signing key), making TrueNAS ZFS snapshots automatic alongside periodic pg_dump -Fc -d campstore logical backups. PowerSync’s powersync_storage database rebuilds automatically from campstore if cleared.
  • Sync Rejection Inspection: If an offline client attempts a mutation that fails server validation (for example, a stale reversal or revoked membership), the server logs the diagnostic payload into sync_rejections and alerts the operator without losing transaction history.