Files
immich-redaktions-plugin/docs/operations.md
T
Leon TonhäuserandClaude Opus 5.5 9e938e4d07 feat: redesign portal UI with Sakani UI and add release notes
Replace the hand-rolled Tailwind/shadcn look with Sakani UI across the
editorial area, the admin area and all signed-out pages.

- AppShell (Sakani Sidebar + TopBar) for /redaktion and /admin, with a
  mobile drawer, theme toggle, sign-out, legal links and a "Was ist neu"
  button; PublicShell for login, registration, password, 2FA and errors.
- Shared primitives (Button, Card, Input, PageHeader) now render Sakani;
  components/ui/sakani.tsx is the client boundary for Server Components
  (Sakani ships no "use client") and adds FormSelect (native form value)
  and DataTable (element cells from the server).
- Legacy CSS variables map onto Sakani tokens; globals.css shrinks from
  ~2200 to ~700 lines. Geist replaces Inter. recharts/lucide-react dropped
  (charts via Sakani BarChart).
- Release notes popup per area, shown once per version (localStorage) and
  reopenable from the sidebar; native <dialog> for focus trapping.
- Fixes found while testing: TOTP field reused the typed password in
  clear text, modal dialogs sat top-left, invisible unchecked checkboxes
  in dark mode.
- Parallel run: compose.parallel.yaml, AUTO_RULE_SYNC_DISABLED switch and
  docs/operations.md §8 (start, rollback, cutover).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:24:05 +01:00

9.0 KiB

Operations Runbook: Immich Redaktionsportal

This guide documents production deployment, operations, security practices, backup/restore procedures, and maintenance for the Immich Redaktionsportal.


1. Production Architecture Overview

The portal runs as a self-hosted Next.js standalone container alongside a dedicated PostgreSQL 17 database.

  • App Server: Next.js 16 (Node.js 24 LTS, standalone output).
  • Database: PostgreSQL 17 (isolated database, separate from Immich).
  • Immich Integration: Isolated via server-only Immich API adapter using an administrator API key.
  • Mail: Nodemailer via SMTP (TLS / STARTTLS).

2. Environment Configuration

All production configuration is provided via environment variables (e.g. .env or Docker secrets).

Variable Description Example / Notes
DATABASE_URL PostgreSQL connection string postgres://portal:pass@portal-db:5432/portal
BETTER_AUTH_SECRET 32+ character random secret openssl rand -hex 32
BETTER_AUTH_URL Public base URL of the portal https://presse.example.de
IMMICH_BASE_URL Internal URL to Immich server http://immich-server:2283
IMMICH_API_KEY Restricted Immich API key API key of dedicated Immich service user
SMTP_HOST Outbound mail server hostname smtp.infomaniak.com
SMTP_PORT Outbound mail server port 587 (STARTTLS) or 465 (SSL)
SMTP_USER SMTP username portal@example.de
SMTP_PASSWORD SMTP password Confidential
SMTP_FROM Default From email address Leon Tonhäuser Presse <portal@example.de>
LEGAL_IMPRINT_URL Public Impressum link https://leon-tonhaeuser.de/impressum
LEGAL_PRIVACY_URL Public Datenschutz link https://leon-tonhaeuser.de/datenschutz
LEGAL_TERMS_URL Public Nutzungsbedingungen link https://leon-tonhaeuser.de/agb
AUTO_RULE_SYNC_INTERVAL_SECONDS Interval of the album auto-rule sync in seconds (min 30) 120 (default)
CRON_SECRET Optional bearer token for POST /api/cron/album-sync; unset disables the endpoint openssl rand -hex 32
AUTO_RULE_SYNC_DISABLED true skips the in-process album auto-rule sync (for a second instance on the same DB, see §8) unset (sync runs)

3. Reverse Proxy & Streaming Configuration

When placing Nginx or Traefik in front of the portal:

  1. Proxy Buffering: Disable response buffering for the download stream endpoint (/api/downloads/[downloadId]/file) to support direct streaming of original high-resolution photo files:
    location /api/downloads/ {
        proxy_pass http://localhost:3000;
        proxy_buffering off;
        proxy_read_timeout 600s;
        proxy_send_timeout 600s;
    }
    
  2. Body Size Limits: Unused (portal handles photo downloads only, not uploads).
  3. Security Headers: Managed by Next.js (next.config.ts), including restrictive CSP, frame denial (DENY), and strict Referrer-Policy.
  4. Client-IP headers: The portal accepts the proxy-appended final hop of X-Forwarded-For (the normal Zoraxy/Go reverse-proxy path) and alternatively X-Real-IP for abuse protection. Keep the application port unreachable from the public network so clients cannot bypass the trusted proxy. If a proxy sets X-Real-IP, it must overwrite rather than pass through a public client value.

4. Immich Service-User Permissions & API Key Setup

  1. Create a dedicated service user in Immich (e.g. redaktion-service@example.de).
  2. Share only administrator-approved editorial albums read-only with this user.
  3. Generate an API Key for the user with only the following scopes:
    • album.read
    • asset.read
    • asset.view
    • asset.download
  4. Test API access against Immich endpoints before deploying.

5. Database Migrations, Admin Seed, Preflight

These one-shot tasks run in the builder stage on the internal network so they can reach portal-db (which is not exposed to the host). They are grouped under the ops compose profile and do not start with docker compose up.

  • Apply migrations (run before starting a new app version):

    docker compose --profile ops run --rm migrate
    

    Migrations are safe to run on every environment, including production. The history was squashed into a single baseline (drizzle/0000_baseline.sql) in August 2026: the baseline carries the timestamp of the original first migration, so drizzle-kit migrate skips it on any database that already has tables (its recorded journal entry is newer) and applies it only on fresh databases. New migrations generated with pnpm exec drizzle-kit generate are picked up automatically on all environments — no manual psql steps required anymore. Historical (pre-squash) migration files live in drizzle-history/pre-squash-2026-08/ and are referenced by integration tests only; do not point drizzle.config.ts at that folder.

  • Seed the first admin (override the command to pass credentials):

    docker compose --profile ops run --rm seed \
      pnpm tsx scripts/create-admin.ts admin@example.de "AdminPassword!" "Name"
    
  • Smoke-test env + connectivity (DB, Better Auth, SMTP, Immich):

    docker compose --profile ops run --rm preflight
    

Migrations and the admin seed must be executed after the database is healthy and before the app is started for the first time.


6. Backup & Restore Procedures

Nightly Backup Drill

Use scripts/backup-db.sh in a daily cron job:

0 2 * * * /path/to/portal/scripts/backup-db.sh /var/backups/immich-portal >> /var/log/portal-backup.log 2>&1

Restore Procedure

To restore from a .dump file created by backup-db.sh:

# 1. Stop the application container to prevent writes
docker compose stop portal-app

# 2. Restore database from dump file
docker exec -i portal-db pg_restore -U portal -d portal --clean --if-exists < /path/to/backup.dump

# 3. Restart application container
docker compose start portal-app

7. Operational Maintenance Tasks

  • API Key Rotation: Generate a new key in Immich, update IMMICH_API_KEY in environment/secrets, and restart portal-app.
  • Health Verification:
    • GET /api/health/live -> 200 OK (Process liveness).
    • GET /api/health/ready -> 200 OK (Database & Immich connectivity).
  • Audit Log Inspection: Accessible in portal UI under /admin/audit (Admin role required).

8. Parallel Run of the New UI (Sakani) and Cutover

The Sakani redesign can run next to the live portal on its own subdomain, against the same database and Immich, until it is accepted. The branch contains no database migrations, so both versions work on the same schema.

What "parallel" means in practice

  • Every action in the new UI is real: approvals, album grants, downloads, usages, billing reports and announcements land in the production database.
  • Sessions are per domain: users log in separately on the new subdomain.
  • E-mails sent by the parallel instance (verification, password reset, album notifications) link to the new subdomain (PARALLEL_BASE_URL).
  • Only the live instance runs the album auto-rule sync and the cron endpoint; the parallel one has AUTO_RULE_SYNC_DISABLED=true and no CRON_SECRET.

Start the parallel instance (on the server, next to the live checkout):

  1. Push the branch, then check it out beside the live checkout:
    git fetch origin && git worktree add ../portal-sakani origin/<sakani-branch>
    
  2. Build its image:
    docker build -t portal-app:sakani ../portal-sakani
    
  3. In the live .env, add the public URL of the new subdomain:
    PARALLEL_BASE_URL=https://neu.redaktionen.leon-tonhaeuser.de
    
  4. Start it from the live checkout (so it joins the live networks and DB):
    docker compose -f compose.yaml -f ../portal-sakani/compose.parallel.yaml up -d portal-app-next
    
  5. DNS: point the subdomain at the server. Reverse proxy (Zoraxy): add a rule neu.redaktionen… → localhost:3001 with the same settings as the live rule (no buffering for /api/downloads/, X-Forwarded-For as described in §3).
  6. Smoke test: GET https://<subdomain>/api/health/ready → 200, then log in as admin and as an editorial account.

Update the parallel instance after new commits on the branch: git -C ../portal-sakani pull, rebuild the image (step 2), re-run step 4.

Roll back at any time: stop only the parallel container — the live portal is untouched.

docker compose -f compose.yaml -f ../portal-sakani/compose.parallel.yaml rm -sf portal-app-next

Cutover (the new UI replaces the old one on the main domain):

  1. Merge the Sakani branch into main.
  2. In the live checkout: git pull, then docker compose build portal-app && docker compose up -d portal-app. (BETTER_AUTH_URL stays the main domain; no other env changes are needed.)
  3. Stop the parallel container (rollback command above), remove the Zoraxy rule or turn it into a redirect to the main domain, delete PARALLEL_BASE_URL from .env, and git worktree remove ../portal-sakani.