Files
photoreport/docs/DEPLOY.md
T
sparkandClaude Opus 5.5 8947a51d83
ci / typescript (push) Successful in 15m12s
ci / rust (push) Successful in 22m16s
feat(shop): galleries on the public sites, Stripe checkout and rendered downloads
Sites per domain with two skins (PhotoReport, ShootYourMove) in apps/site (Next.js); public, unlisted and private galleries with watermarked photos; products, cart, orders with VIES reverse charge; the organization's own Stripe Checkout and signed webhooks; bought files rendered from the original with edits and IPTC, emailed; Vendas module in the app.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
2026-10-11 22:36:16 +01:00

5.2 KiB

Deploy

Same model as the other BitReport projects (see app.photoreport.pt/DEPLOY.md, BIT-23722): push to main on Gitea -> webhook -> the container pulls and redeploys itself. No manual scp/rsync of code.

Flow per container

  1. Gitea sends a push webhook to https://<container-domain>/_deploy/gitea (one webhook per container).
  2. The receiver (small Node service, infra/deploy-receiver) verifies X-Gitea-Signature (HMAC-SHA256 with the webhook secret from .env), checks ref == refs/heads/main, and that the push touched a path this container owns (table below). Otherwise it answers 202 and does nothing.
  3. It runs infra/deploy/<service>.sh <sha> under a lock (one deploy at a time per container):
    • git fetch + git reset --hard <sha> in /srv/photoreport
    • pnpm install --frozen-lockfile / cargo build --release -p <crate> as needed
    • build only the affected package (pnpm --filter <pkg> build)
    • API only: prisma migrate deploy
    • reload the process (PM2 for Node, systemd for Rust/Python workers)
    • health check (/health must report the new version); on failure, reset to the previous sha and reload
  4. Result (sha, duration, status) is posted to the deploy log and, on failure, to the notifications channel.

What a deploy never touches (norm BIT-25005)

  • .env is never created from .env.example over an existing file and never overwritten; a backup .env.bak.deploy is written before each deploy. New variables are appended, never replaced.
  • Data directories, Garage buckets, database contents (only versioned migrations run).

Path ownership

Container Redeploys when these paths change
pr-api apps/api/**, packages/contracts/**, packages/metadata/**, prisma/**
pr-app apps/app/**, packages/ui/**, packages/sdk/**, engine/** (WASM build)
pr-site apps/site/**, packages/ui/**
pr-workers workers/media/**, workers/render/**, engine/**, packages/metadata/**
pr-ml workers/ml/**

Files

File Purpose
infra/deploy-receiver/ Webhook receiver (Node, no dependencies). Tests cover signature, path rules and the queue.
infra/deploy/deploy.sh Per-service deploy with rollback. Tested end to end (success, failed build -> rollback, .env kept).
infra/systemd/photoreport-deploy-receiver.service Runs the receiver on each container.
infra/nginx/deploy-receiver.conf Exposes /_deploy/gitea to Gitea; /_deploy/status only locally.
infra/pm2/api.config.cjs API processes (2 instances, cluster mode) and photoreport-worker (one, fork mode).

First-time setup of a container

  1. Clone the repo to /srv/photoreport (read-only deploy key from Gitea).

  2. Install Node 22, pnpm, PM2 (and Rust for workers); create the service .env from its .env.example.

  3. /etc/photoreport/deploy-receiver.env from infra/deploy-receiver/.env.example (0600), with a new secret.

  4. pnpm install && pnpm --filter @photoreport/deploy-receiver build, then enable photoreport-deploy-receiver.service and include infra/nginx/deploy-receiver.conf in the site.

  5. In Gitea: Settings -> Webhooks -> add https://<container-domain>/_deploy/gitea, content type JSON, the same secret, push events only, branch filter main.

  6. API container only, once: create-owner (see README) for the first organization.

  7. API and ingest containers: mount the shared data folder at /srv/photoreport-data (Proxmox bind mount), set STORAGE_ROOT, INGEST_ROOT and DELIVERY_SECRET_KEY (openssl rand -base64 32, the same value wherever the worker or API runs). The worker needs perl (ExifTool). On the ingest container, SFTPGo users get <INGEST_ROOT>/<login> as home folder; register each login under the member it belongs to (POST /v1/orgs/:orgId/ftp-accounts).

  8. Faces (worker host): install Rust, infra/faces/download-models.sh /srv/photoreport-data/models, and set the FACES_* variables in apps/api/.env. Deploys build photoreport-faces whenever cargo is present.

  9. Develop (Revelar): on the worker host set RENDER_BIN=/srv/photoreport/target/release/photoreport-render (built by the API deploy when Rust is installed). On the app host install the browser engine toolchain once: rustup target add wasm32-unknown-unknown and cargo install wasm-bindgen-cli --version 0.2.129 --locked; every app deploy then rebuilds apps/app/public/engine/ (infra/engine/build-wasm.sh). Serve .wasm as application/wasm.

  10. Sites (pr-site): API_URL for infra/pm2/site.config.cjs (default http://127.0.0.1:3000), reverse proxy every brand domain to port 3100. In the app (Vendas -> Sites e pagamentos) add each domain, then the Stripe secret key and webhook secret; in Stripe add the shown endpoint for checkout.session.completed, checkout.session.async_payment_succeeded, checkout.session.async_payment_failed and checkout.session.expired. Set SMTP_URL on the worker for order emails.

Desktop and print agent

Not deployed by webhook. A tag desktop-v* / agent-v* triggers Gitea Actions to build installers per OS and publish a Gitea release; the Tauri updater and the agent's updater read from it.