Repository Public
1# Deployment23**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.45**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.67## What changes for the existing deployment89| | Before (c457cff) | This version |10|---|---|---|11| Processes | `atlas-web` | `atlas-web` **+ `atlas-worker`** (media encodes) |12| State | none (`ATLAS_DATA_DIR` empty) | `atlas.db` (+ `-wal`, `-shm`), `slides/`, `media/`, `masters/`, `resources/`, `uploads/`, `work/`, `backups/` under `ATLAS_DATA_DIR` |13| Rendering | static pages built once | public pages rendered on demand from the database (no rebuild to publish) |14| Build needs | — | nothing more: SQLite is Node's built-in `node:sqlite` (Node ≥ 24), no native module to compile |15| 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) |16| ffmpeg | not needed | needed by the worker only; **absent = reported, not fatal** |1718## Environment (`.env` in the application directory, mode 600)1920Template with comments: `.env.production.example`. Next.js, `pnpm studio`, `pnpm worker` and `ecosystem.config.cjs` all read `.env`.2122| Variable | Meaning | Value on the node |23|---|---|---|24| `ATLAS_PUBLIC_URL` | public origin (canonical URLs, sitemap) | `https://atlas.spboucher.ai` (already set) |25| `ATLAS_DATA_DIR` | all mutable state, outside the app directory | `~/apps-data/atlas-platform` as an absolute path (already set) |26| `PORT` / `HOST` | listening address | `8840` (already set) |27| `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`) |28| `ATLAS_RP_ID` | WebAuthn relying-party id; passkeys are bound to it | **add**: `atlas.spboucher.ai` (defaults to the host of the origin) |29| `ATLAS_HEALTH_TOKEN` | bearer token of `/api/health/details`; unset = endpoint answers 404 | **add**: `openssl rand -hex 32` |30| `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` |31| `ATLAS_COURSE_REPO` | optional checkout of the course repository on the node | leave unset: upload snapshots as archives |32| `ATLAS_QUOTA_GB`, `ATLAS_MIN_FREE_GB` | storage budget (0 = none), free-space alert threshold (20) | to choose |33| `ATLAS_MAX_MASTER_GB` / `_RESOURCE_MB` / `_ARCHIVE_MB` | upload limits (40 / 500 / 300) | defaults |34| `ATLAS_X264_PRESET`, `ATLAS_LADDER`, `ATLAS_WORKER_CONCURRENCY`, `ATLAS_JOB_TIMEOUT_MIN`, `ATLAS_MAX_VIDEO_MIN` | encoding (see `VIDEO_PIPELINE.md`) | defaults |35| `ATLAS_LOG_LEVEL` | `info` (default), `debug`, `silent` | default |3637Never on the public deployment: `ATLAS_PREVIEW` (development preview; it also closes the studio), `ATLAS_CONTENT_SOURCE=seed` (tests).3839## Upgrade runbook (for the lead)4041```bash42# 0. on the node, before anything: nothing to back up the first time (no database yet). From the second upgrade on:43cd ~/apps/atlas-platform && pnpm studio backup --out ~/apps-data/atlas-backups/avant-$(date +%Y%m%d-%H%M)4445# 1. ship the code as before (mld stage/deploy or rsync with the anchored excludes), then on the node:46pnpm install --frozen-lockfile47pnpm build # no database access at build time48# 2. add the new variables to .env (table above), chmod 600 .env49# 3. restart the web process and add the worker (or: pm2 start ecosystem.config.cjs && pm2 save)50pm2 restart atlas-web --update-env51pm2 start node_modules/tsx/dist/cli.mjs --name atlas-worker --cwd ~/apps/atlas-platform --interpreter node --kill-timeout 20000 -- scripts/worker.ts52pm2 save53# 4. checks54curl -s http://127.0.0.1:8840/api/health # {"status":"ok","mode":"production","sessions":24,"published":0}55pnpm studio health # JSON; "degraded" while ffmpeg is missing — expected on m4mm today56curl -s -o /dev/null -w '%{http_code}\n' https://atlas.spboucher.ai/admin # 307 → /admin/connexion57# 5. first enrolment (creates and seeds the database), on the node:58pnpm studio enrol --name "Simon-Pierre Boucher" # prints a one-time link; open it on the device that will hold the passkey59```6061In 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.6263### Slides of S01–S10 (owner's request of 2026-11-22) — to be run by the lead at deployment6465poppler is needed only where the packs are built (this laptop has it; the node need not).6667```bash68# on the laptop, in this repository69pnpm slides:build --from ~/Desktop/UQO/Enseignement/atlas-ai-mooc --out /tmp/atlas-packs # ≈ 50 s, 10 packs, ≈ 28 MB in all70rsync -a /tmp/atlas-packs/*-slides.tar.gz m4mm:/tmp/atlas-packs/71# on the node, in ~/apps/atlas-platform, after the upgrade above and the first enrolment (or before it: the commands seed the database too)72pnpm studio slides-import /tmp/atlas-packs/S*-slides.tar.gz # private; ≈ 105 MB under $ATLAS_DATA_DIR/slides73pnpm studio slides-publish S01 S02 S03 S04 S05 S06 S07 S08 S09 S10 # slides only; refuses a session where anything else is marked public74curl -s http://127.0.0.1:8840/api/health # still "published":0 — slides-only sessions are not counted as published75# to undo: pnpm studio slides-unpublish S01 S02 … (or, per session, the publication history in the studio)76```7778Rehearsed 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.7980### Interactive lessons (owner's second request of 2026-11-22) — upgrade of the existing deployment, to be run by the lead8182State of the deployment as given by the lead (not verified from here): node **m4mm**, application directory `~/apps/atlas-platform` (a git clone of the forge repository), PM2 `atlas-web` + `atlas-worker`, state in `~/apps-data/atlas-platform` with `atlas.db` seeded and the slides of S01–S13 published, ffmpeg installed.8384**Database: no schema migration in this version.** The lesson is one more section key in the existing `sections` table; publications frozen by the previous version stay valid (tested: `tests/lessons.test.ts`, « upgrade of an existing deployment » — schema, migration list, public manifest and publication history unchanged after reopening, then the lesson layer imported and published on top). **A backup is still the first step**, because the import rewrites the working copy of the quizzes (it adds their slide references) and publication adds history entries.8586```bash87# 0. on the laptop, in this repository: build the packs (Node only, ≈ 1 s)88pnpm lessons:build --from ~/Desktop/UQO/Enseignement/atlas-ai-mooc --out /tmp/atlas-lessons89rsync -a /tmp/atlas-lessons/S*-lesson.json m4mm:/tmp/atlas-lessons/9091# 1. on the node, BEFORE anything else: backup (database snapshot + resources; a few seconds)92cd ~/apps/atlas-platform && pnpm studio backup --out ~/apps-data/atlas-backups/avant-lecons-$(date +%Y%m%d-%H%M)9394# 2. code: bring the clone to the new commit (git pull, or the lead's usual mld path), then95pnpm install --frozen-lockfile && pnpm build96pm2 restart atlas-web atlas-worker --update-env97pnpm studio migrate # prints « schéma 3/3 »: nothing to apply98curl -s http://127.0.0.1:8840/api/health # unchanged: {"status":"ok",…,"published":0}99100# 3. import the lessons — private; changes nothing on the public site101pnpm studio lessons-import /tmp/atlas-lessons/S*-lesson.json102103# 4. publish, session by session (each refuses if the slides of that session are not online)104pnpm studio lessons-publish S01 # then S02, S03, … when the owner has looked at each105curl -s http://127.0.0.1:8840/api/health # still "published":0 — a lesson without video is not a published session106# to undo one: pnpm studio lessons-unpublish S01 (back to slides only; or the publication history in the studio)107# to undo everything: stop the processes, pnpm studio restore <backup dir> --force, restart108```109110After step 2 and before step 4 the public site is exactly what it was (slides of S01–S13). Suggested order of publication: S01, S02, S03 first (they have their own explorables); S05, S06, S07, S09, S11, S12 carry one generic diagram of the site's library; S04, S08, S10, S13 are text, slides and check questions only (see `IMPLEMENTATION_STATUS.md`). A private look before publishing: in the studio set « Leçon interactive » to « Aperçu seulement » and open the session's private preview. To check on the node after the first publication: one lesson page on a real iPhone, and the size of the page through the gateway (a lesson page is ≈ 500 kB of HTML before compression — **not measured through the gateway**).111112**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*.113114**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`.115116**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.117118## Local run (verified)119120```bash121pnpm install --frozen-lockfile && pnpm build122ATLAS_PUBLIC_URL=http://localhost:8840 ATLAS_DATA_DIR=./data pnpm start # web123ATLAS_PUBLIC_URL=http://localhost:8840 ATLAS_DATA_DIR=./data pnpm worker # worker, second terminal124ATLAS_PUBLIC_URL=http://localhost:8840 ATLAS_DATA_DIR=./data pnpm studio enrol --name "Moi"125```126127Use `localhost`, not `127.0.0.1`: a WebAuthn relying-party id cannot be an IP address.128129## Launch checklist (Phase 6 — nothing ticked by this work)130131- [ ] Upgrade deployed; `pnpm studio health` is `ok` (ffmpeg installed, worker alive)132- [ ] Owner passkey enrolled on a real device, and a second one on another device; recovery link procedure tried once133- [ ] A real multi-GB master uploaded through the gateway, encoded, played on iPhone and iPad Safari134- [ ] Licence decided; legal pages reviewed; contact addresses added135- [ ] One session reviewed, recorded, captioned and published through the studio136- [ ] Backup scheduled with an off-node copy of `masters/`; a restore rehearsed137- [ ] Uptime check on `/api/health`; alert on `/api/health/details` ≠ 200138- [ ] `pnpm test:all` green on the deployed commit; `pnpm audit` reviewed139