SPB Git

Repository Public

DEPLOYMENT.md 9.0 KB

# Deployment

Status. The lead deployed commit c457cff (Phases 0–3, plus src/components/data/DataPanel.tsx) on 2026-11-22 with the cluster's mld tool: node m4mm, PM2 process atlas-web, port 8840, application directory ~/apps/atlas-platform, state directory ~/apps-data/atlas-platform, environment file .env (ATLAS_PUBLIC_URL, ATLAS_DATA_DIR, PORT), build on the node (pnpm install --frozen-lockfile, next build), rsync excludes anchored /data/ and /backups/. ffmpeg is not installed on that node. That information was given to this work by the lead; nothing here was verified against the node.

The upgrade to this version (studio, worker) has not been deployed. It is to be performed by the lead. No server, DNS record, cluster node, remote PM2 or git remote was touched by this work.

# What changes for the existing deployment

Before (c457cff) This version
Processes atlas-web atlas-web + atlas-worker (media encodes)
State none (ATLAS_DATA_DIR empty) atlas.db (+ -wal, -shm), slides/, media/, masters/, resources/, uploads/, work/, backups/ under ATLAS_DATA_DIR
Rendering static pages built once public pages rendered on demand from the database (no rebuild to publish)
Build needs — nothing more: SQLite is Node's built-in node:sqlite (Node ≥ 24), no native module to compile
Public site right after upgrade 24 sessions « À venir » identical — until the database exists the committed snapshot is served; the first enrolment creates the database from that same snapshot and publishes the same plan (tested: tests/studio-publication.test.ts, first test)
ffmpeg not needed needed by the worker only; absent = reported, not fatal

# Environment (.env in the application directory, mode 600)

Template with comments: .env.production.example. Next.js, pnpm studio, pnpm worker and ecosystem.config.cjs all read .env.

Variable Meaning Value on the node
ATLAS_PUBLIC_URL public origin (canonical URLs, sitemap) https://atlas.spboucher.ai (already set)
ATLAS_DATA_DIR all mutable state, outside the app directory ~/apps-data/atlas-platform as an absolute path (already set)
PORT / HOST listening address 8840 (already set)
ATLAS_STUDIO_ORIGIN origin the browser shows for /admin: WebAuthn expected origin and CSRF reference add: https://atlas.spboucher.ai (defaults to ATLAS_PUBLIC_URL)
ATLAS_RP_ID WebAuthn relying-party id; passkeys are bound to it add: atlas.spboucher.ai (defaults to the host of the origin)
ATLAS_HEALTH_TOKEN bearer token of /api/health/details; unset = endpoint answers 404 add: openssl rand -hex 32
ATLAS_FFMPEG, ATLAS_FFPROBE absolute paths (PM2's PATH often lacks /opt/homebrew/bin) add once installed: /opt/homebrew/bin/ffmpeg, /opt/homebrew/bin/ffprobe
ATLAS_COURSE_REPO optional checkout of the course repository on the node leave unset: upload snapshots as archives
ATLAS_QUOTA_GB, ATLAS_MIN_FREE_GB storage budget (0 = none), free-space alert threshold (20) to choose
ATLAS_MAX_MASTER_GB / _RESOURCE_MB / _ARCHIVE_MB upload limits (40 / 500 / 300) defaults
ATLAS_X264_PRESET, ATLAS_LADDER, ATLAS_WORKER_CONCURRENCY, ATLAS_JOB_TIMEOUT_MIN, ATLAS_MAX_VIDEO_MIN encoding (see VIDEO_PIPELINE.md) defaults
ATLAS_LOG_LEVEL info (default), debug, silent default

Never on the public deployment: ATLAS_PREVIEW (development preview; it also closes the studio), ATLAS_CONTENT_SOURCE=seed (tests).

# Upgrade runbook (for the lead)

bash
# 0. on the node, before anything: nothing to back up the first time (no database yet). From the second upgrade on:
cd ~/apps/atlas-platform && pnpm studio backup --out ~/apps-data/atlas-backups/avant-$(date +%Y%m%d-%H%M)

# 1. ship the code as before (mld stage/deploy or rsync with the anchored excludes), then on the node:
pnpm install --frozen-lockfile
pnpm build                                   # no database access at build time
# 2. add the new variables to .env (table above), chmod 600 .env
# 3. restart the web process and add the worker (or: pm2 start ecosystem.config.cjs && pm2 save)
pm2 restart atlas-web --update-env
pm2 start node_modules/tsx/dist/cli.mjs --name atlas-worker --cwd ~/apps/atlas-platform --interpreter node --kill-timeout 20000 -- scripts/worker.ts
pm2 save
# 4. checks
curl -s http://127.0.0.1:8840/api/health            # {"status":"ok","mode":"production","sessions":24,"published":0}
pnpm studio health                                   # JSON; "degraded" while ffmpeg is missing — expected on m4mm today
curl -s -o /dev/null -w '%{http_code}\n' https://atlas.spboucher.ai/admin   # 307 → /admin/connexion
# 5. first enrolment (creates and seeds the database), on the node:
pnpm studio enrol --name "Simon-Pierre Boucher"     # prints a one-time link; open it on the device that will hold the passkey

In an mld manifest the second process is: command node node_modules/tsx/dist/cli.mjs scripts/worker.ts, same directory and environment as atlas-web, no port, no health URL (its liveness is the heartbeat shown by pnpm studio health and the dashboard). mld move to another node must move ATLAS_DATA_DIR with the application: the database and the media live there.

# Slides of S01–S10 (owner's request of 2026-11-22) — to be run by the lead at deployment

poppler is needed only where the packs are built (this laptop has it; the node need not).

bash
# on the laptop, in this repository
pnpm slides:build --from ~/Desktop/UQO/Enseignement/atlas-ai-mooc --out /tmp/atlas-packs      # ≈ 50 s, 10 packs, ≈ 28 MB in all
rsync -a /tmp/atlas-packs/*-slides.tar.gz m4mm:/tmp/atlas-packs/
# on the node, in ~/apps/atlas-platform, after the upgrade above and the first enrolment (or before it: the commands seed the database too)
pnpm studio slides-import /tmp/atlas-packs/S*-slides.tar.gz          # private; ≈ 105 MB under $ATLAS_DATA_DIR/slides
pnpm studio slides-publish S01 S02 S03 S04 S05 S06 S07 S08 S09 S10   # slides only; refuses a session where anything else is marked public
curl -s http://127.0.0.1:8840/api/health                             # still "published":0 — slides-only sessions are not counted as published
# to undo:  pnpm studio slides-unpublish S01 S02 …    (or, per session, the publication history in the studio)

Rehearsed locally on 2026-11-22 with the real S01–S10 exports on a scratch data directory (import, publication, pages, search, WebKit rendering). To check on the node: that the gateway compresses image/svg+xml (each slide is ≈ 125 kB raw, ≈ 20 kB gzipped; next.config.ts leaves compression to the gateway), and one session page on a real iPhone.

ffmpeg — brew install ffmpeg on the node (the build must include libx264 and an AAC encoder; Homebrew's does), set the two paths in .env, pm2 restart atlas-worker --update-env. Until then: uploads are accepted and stored, encode jobs fail at once with « ffmpeg est introuvable… », the dashboard shows it in red; after installing, Traitements → Relancer.

Gateway (Caddy) — nothing new is required: uploads are 4 MiB requests. To verify at deployment (not verifiable from here): that X-Forwarded-For is set (rate limits and the audit log use it), that /admin responses are not cached, that a request body of 4 MiB passes, and that HLS segments under /media/ stream with ranges. The application sends Cache-Control: private, no-store and X-Robots-Tag: noindex on everything under /admin.

Rollback of this upgrade — redeploy the previous commit and stop atlas-worker. The old code ignores the database; once sessions are published through the studio, going back to c457cff would show the plan only.

# Local run (verified)

bash
pnpm install --frozen-lockfile && pnpm build
ATLAS_PUBLIC_URL=http://localhost:8840 ATLAS_DATA_DIR=./data pnpm start     # web
ATLAS_PUBLIC_URL=http://localhost:8840 ATLAS_DATA_DIR=./data pnpm worker    # worker, second terminal
ATLAS_PUBLIC_URL=http://localhost:8840 ATLAS_DATA_DIR=./data pnpm studio enrol --name "Moi"

Use localhost, not 127.0.0.1: a WebAuthn relying-party id cannot be an IP address.

# Launch checklist (Phase 6 — nothing ticked by this work)

  • Upgrade deployed; pnpm studio health is ok (ffmpeg installed, worker alive)
  • Owner passkey enrolled on a real device, and a second one on another device; recovery link procedure tried once
  • A real multi-GB master uploaded through the gateway, encoded, played on iPhone and iPad Safari
  • Licence decided; legal pages reviewed; contact addresses added
  • One session reviewed, recorded, captioned and published through the studio
  • Backup scheduled with an off-node copy of masters/; a restore rehearsed
  • Uptime check on /api/health; alert on /api/health/details ≠ 200
  • pnpm test:all green on the deployed commit; pnpm audit reviewed
Files main
Menu

Theme