From 1643fcb5917e0e229836f583e3e8d670d6a87b01 Mon Sep 17 00:00:00 2001 From: nocode Date: Thu, 24 Sep 2026 14:08:52 +0200 Subject: [PATCH] docs(ops): document deployment, CI, monitoring and backups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Four independent procedures, each opening with the failure it prevents — most of them ones this project actually hit: a front-end older than its API after a partial upload, a broken card move that no test ran before it shipped, an evening spent asking whether the site was down, and a database that came back empty after a rebuild. The CI workflow ships with them. It leaves out `format:check`, which would fail on CRLF files that predate the Prettier configuration; normalising them deserves a commit of its own. Co-Authored-By: Claude Opus 5 (1M context) --- .gitea/workflows/ci.yml | 35 ++++++ CHANGELOG.md | 46 ++++++++ README.en.md | 1 + README.md | 1 + docs/exploitation.md | 246 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 329 insertions(+) create mode 100644 .gitea/workflows/ci.yml create mode 100644 docs/exploitation.md diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..4e0adb3 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI + +# Lint and tests on every push and every pull request. `format:check` is +# deliberately absent: the repository still holds CRLF files that predate the +# Prettier configuration, so the step would fail on untouched code. Normalise +# the line endings in a commit of their own, then add it here. +on: + push: + branches: [main] + pull_request: + +jobs: + quality: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '22' + cache: npm + + - name: Installer les dépendances + run: npm ci + + - name: Lint + run: npm run lint + + - name: Tests + run: npm test + + # The changelog is generated from the commit history, so a stale one is + # a real defect rather than a formatting detail. + - name: Changelog à jour + run: npm run changelog:check diff --git a/CHANGELOG.md b/CHANGELOG.md index fb83462..d9cbb45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,27 @@ The project follows [Semantic Versioning](https://semver.org/). ## [Unreleased] ### Features +- **projects:** _(feat)_ pull Gitea issues onto any board ([1c21f6f]) +- **wiki:** _(feat)_ serve the legal pages at /terms-of-service and /privacy-policy ([3d0e21d]) +- **projects:** _(feat)_ add the board interface ([e1b9a5c]) +- **projects:** _(feat)_ add a Kanban board per repository and one for the organization ([901ca56]) +- **web:** _(feat)_ open a repository from anywhere on its row ([95b51ab]) +- **wiki:** _(feat)_ add the reading site and its editor ([e5b7303]) +- **wiki:** _(feat)_ serve a public documentation written from the panel ([c76c0b9]) +- **web:** _(feat)_ publish the slash commands from the panel ([2622744]) +- **voice:** _(feat)_ take back the generated channels the database forgot ([b42fb10]) +- **settings:** _(feat)_ make the server settings real, and widen them ([406b5af]) +- **web:** _(feat)_ make deploying reachable from where it is looked for ([d439b1b]) +- **web:** _(feat)_ refresh the pages as the events arrive ([5481e79]) +- **web:** _(feat)_ push live updates to the dashboard ([df89cc5]) +- **web:** _(feat)_ serve the dashboard and its interface ([06a9be0]) +- **web:** _(feat)_ expose the dashboard API ([bf92bad]) +- **web:** _(feat)_ run and record release deployments ([611129b]) +- **web:** _(feat)_ read, validate and write the .env configuration ([efaaca3]) +- **web:** _(feat)_ add the HTTP layer and Discord-backed sessions ([e03b184]) +- **database:** _(feat)_ store dashboard sessions, deploy targets and deployments ([5abe713]) +- **gitea:** _(feat)_ add an organization and repository administration client ([4b0737a]) +- **config:** _(feat)_ declare the web dashboard environment variables ([e4534d4]) - **status:** _(feat)_ rotate an editable list of bot statuses ([c785e9a]) - **voice:** _(feat)_ guarantee an empty generated channel disappears ([76e2269]) - **voice:** _(feat)_ support several trigger channels with their own category ([836abea]) @@ -66,7 +87,32 @@ The project follows [Semantic Versioning](https://semver.org/). - **config:** _(feat)_ add colors, access levels and ticket categories ([eca9bbe]) - **config:** _(feat)_ load and expose environment settings ([d1388b6]) +### Bug Fixes +- **wiki:** _(fix)_ render the public pages on the server ([8869c74]) +- **web:** _(fix)_ stop caching the interface modules ([3f4a570]) +- **web:** _(fix)_ keep the stack when a view fails ([c031b4d]) +- **web:** _(fix)_ read the interface build date instead of freezing it at startup ([92c27ae]) +- **web:** _(fix)_ stop the settings page breaking on an unexpected payload ([75d1e53]) +- **web:** _(fix)_ give static assets a validator caches can check ([539b150]) +- **web:** _(fix)_ say when the dashboard is disabled ([3bd290c]) +- **web:** _(fix)_ say out loud when the dashboard cannot listen ([afcd0e5]) +- **config:** _(fix)_ warn when a public address is announced but only loopback is bound ([40032ec]) +- **web:** _(fix)_ make the whole repository card open the repository ([e397abc]) +- **web:** _(fix)_ pin the sidebar highlight to the route, and name the build ([a44ff0c]) +- **web:** _(fix)_ always offer the bootstrap token on the sign-in page ([9c6297e]) +- **web:** _(fix)_ let a deploy target be created without a reachable Gitea ([ff15dfe]) +- **web:** _(fix)_ keep the sidebar in step with the page being shown ([a0428e0]) +- **web:** _(fix)_ derive the OAuth2 redirect from the address actually used ([20ff701]) +- **notifications:** _(fix)_ apply the channel overrides set from Discord ([92405ac]) + ### Other changes +- **web:** _(test)_ lock the sidebar highlighting behind tests ([b793298]) +- **web:** _(docs)_ document the wiki, the settings and the command publishing ([5660235]) +- **web:** _(style)_ adopt the official FWS mark and its palette ([621f3e4]) +- **web:** _(docs)_ document the live updates ([2083133]) +- **web:** _(docs)_ document the dashboard and the configuration wizard ([e63d6aa]) +- **web:** _(test)_ cover the router, configuration, auth, deployments and server ([bd7fdea]) +- **all:** _(refactor)_ uniformisation ([50665c8]) - **readme:** _(docs)_ translate the documentation and document the contribution workflow ([9bbe9cb]) - **changelog:** _(build)_ generate the changelog from the commit history ([478ae41]) - **gitignore:** _(chore)_ ignore the AI assistant data and the other toolchains ([2df33c2]) diff --git a/README.en.md b/README.en.md index 97c615f..ae2454d 100644 --- a/README.en.md +++ b/README.en.md @@ -533,6 +533,7 @@ The rules shared by every FWS repository live in the [organisation `.profile`](h - FWS documentation: `[link to add]` - Technical documentation: [`docs/architecture.md`](docs/architecture.md) - Web dashboard: [`docs/web-dashboard.md`](docs/web-dashboard.md) +- Operations (deployment, continuous integration, monitoring, backups): [`docs/exploitation.md`](docs/exploitation.md) - Organisation conventions: [`.profile/README.md`](https://gitea.nocode-var.tech/FWS/.profile/src/branch/main/README.en.md) - Changelog: [`CHANGELOG.md`](CHANGELOG.md) _(generated)_ - Instructions for AI agents: [`AGENTS.md`](AGENTS.md) diff --git a/README.md b/README.md index d798f0d..ac18f5b 100644 --- a/README.md +++ b/README.md @@ -538,6 +538,7 @@ Les règles communes à tous les repos FWS sont décrites dans le [`.profile` de - Documentation FWS : `[lien à ajouter]` - Documentation technique : [`docs/architecture.md`](docs/architecture.md) - Tableau de bord web : [`docs/web-dashboard.md`](docs/web-dashboard.md) +- Exploitation (déploiement, intégration continue, surveillance, sauvegardes) : [`docs/exploitation.md`](docs/exploitation.md) - Conventions de l'organisation : [`.profile/README.md`](https://gitea.nocode-var.tech/FWS/.profile/src/branch/main/README.md) - Journal des modifications : [`CHANGELOG.md`](CHANGELOG.md) *(généré)* - Instructions pour les agents IA : [`AGENTS.md`](AGENTS.md) diff --git a/docs/exploitation.md b/docs/exploitation.md new file mode 100644 index 0000000..069a37e --- /dev/null +++ b/docs/exploitation.md @@ -0,0 +1,246 @@ +# Exploitation + +Comment déployer, vérifier, surveiller et sauvegarder FWS-Bot en production. Écrit pour un hébergement de type panel (Pterodactyl), qui est le cas actuel. + +Les quatre chapitres sont indépendants et classés par valeur décroissante. + +--- + +## 1. Déployer sans archive + +**Le problème qu'on résout.** Téléverser un zip laisse régulièrement une copie partielle : le front plus ancien que l'API, un module oublié, une page qui plante sans raison apparente. Trois symptômes pour une seule cause, et aucun moyen simple de savoir laquelle. + +Un déploiement reproductible supprime toute la famille. + +### 1.1 Transformer le dossier du conteneur en clone git + +**Une seule fois.** Dans la console du panel : + +```bash +cd /home/container + +# Filet de sécurité : ces deux-là ne sont pas dans git. +cp .env .env.sauvegarde +tar czf data-sauvegarde.tgz data/ + +git init +git remote add origin https://gitea.nocode-var.tech/FWS/fws-discordbot.git +git fetch origin main +git reset --hard origin/main +``` + +`git reset --hard` écrase les fichiers **suivis**. Ton `.env` et ton dossier `data/` sont ignorés par git, donc intacts — la sauvegarde ci-dessus est là au cas où. + +> ⚠️ Ne lance **jamais** `git clean -fd` dans ce dossier : il effacerait `.env` et la base. + +Vérifie ensuite que `git` et l'accès réseau à Gitea existent bien dans le conteneur : + +```bash +git --version && git ls-remote origin main +``` + +### 1.2 Autoriser le déploiement depuis le panel + +Dans le `.env` : + +```bash +WEB_ALLOW_COMMAND_DEPLOYS=true +WEB_ALLOW_RESTART=true +``` + +Puis redémarre le bot une fois pour que ces valeurs soient lues. + +> Ces deux options permettent d'exécuter une commande sur la machine du bot depuis un navigateur. Elles sont réservées au niveau **Owner** et désactivées par défaut. N'ouvre l'accès Owner qu'à des personnes de confiance. + +### 1.3 Déclarer la cible + +**Tableau de bord → Déploiements → Nouvelle cible** + +| Champ | Valeur | +| ----------------------- | ---------------------------------------------------------------------------- | +| Nom | `production` | +| Dépôt | `FWS/fws-discordbot` | +| Environnement | `production` | +| Type | Commande shell sur l'hôte du bot | +| Commande | `git fetch origin main && git reset --hard origin/main && npm ci --omit=dev` | +| Répertoire de travail | `/home/container` | +| Déploiement automatique | à activer si tu veux qu'une release publiée déploie seule | + +### 1.4 Déployer + +1. **Déploiements → Déployer** sur la cible. Le journal complet s'affiche dans l'historique, réussite comme échec. +2. **Paramètres → Redémarrer le bot** — le code n'est relu qu'au démarrage. + +Contrôle : + +```bash +curl -s http://node01.zi-host.ch:25571/api/health +``` + +`buildAt` doit correspondre à ton dernier commit. + +### Ce qu'il faut savoir + +- `npm ci --omit=dev` n'installe pas ESLint, Prettier ni de quoi lancer les tests. C'est voulu : ils tournent en intégration continue (chapitre 2), pas en production. +- Si ton egg Pterodactyl réinstalle les fichiers au démarrage, il écrasera le clone. Vérifie l'option _Auto-update / Reinstall on boot_ et désactive-la. +- Les migrations de base s'appliquent toutes seules au démarrage : rien à lancer. + +--- + +## 2. Faire tourner les tests avant de déployer + +**Le problème qu'on résout.** 301 tests et un lint existent, et ne tournent jamais avant une mise en production. Un déplacement de cartes cassé est passé inaperçu jusqu'à ce qu'un test l'attrape — après coup. + +Le fichier de workflow est déjà dans le dépôt : [`.gitea/workflows/ci.yml`](../.gitea/workflows/ci.yml). Il reste à donner un exécuteur à Gitea. + +### 2.1 Activer Actions sur l'instance + +Côté administration Gitea, dans `app.ini` : + +```ini +[actions] +ENABLED = true +``` + +Puis redémarrer Gitea. Si l'instance ne t'appartient pas, c'est à demander à son administration. + +### 2.2 Enregistrer un exécuteur + +**Dépôt → Settings → Actions → Runners → Create new runner** te donne un jeton d'enregistrement. + +Sur une machine qui a Docker et qui joint ton Gitea — ton poste, un VPS, ou le nœud lui-même : + +```bash +curl -sL -o act_runner \ + https://gitea.com/gitea/act_runner/releases/download/v0.2.11/act_runner-0.2.11-linux-amd64 +chmod +x act_runner + +./act_runner register --no-interactive \ + --instance https://gitea.nocode-var.tech \ + --token \ + --name fws-runner \ + --labels ubuntu-latest:docker://node:22-bookworm + +./act_runner daemon +``` + +Sans Docker, remplace l'étiquette par `ubuntu-latest:host` — les tâches s'exécutent alors directement sur la machine, qui doit avoir Node 22. + +Pour qu'il survive à un redémarrage, place-le en service systemd ou en conteneur `--restart=always`. + +### 2.3 Vérifier + +Pousse une branche : l'onglet **Actions** du dépôt montre le résultat, et la pull request affiche son état. + +### Pourquoi `format:check` n'est pas dans le workflow + +Le dépôt contient encore des fichiers en CRLF antérieurs à la configuration Prettier. L'étape échouerait sur du code que personne n'a touché. + +Pour l'ajouter : normalise les fins de ligne dans un commit dédié (`refactor(all): normalise les fins de ligne`), puis ajoute l'étape. Tant que ce n'est pas fait, l'absence est volontaire. + +--- + +## 3. Savoir que le bot est tombé + +**Le problème qu'on résout.** Une soirée passée à chercher pourquoi le site ne répondait plus, alors qu'une sonde aurait répondu en trente secondes. + +Le bot expose déjà tout ce qu'il faut : + +```json +GET /api/health +{ "status": "ok", "version": "0.1.0", "buildAt": "…", "uptimeMs": 106470 } +``` + +### 3.1 Surveiller depuis l'extérieur + +Un bot ne peut pas signaler sa propre mort : il faut une sonde **externe**. [Uptime Kuma](https://github.com/louislam/uptime-kuma) est léger et sait écrire sur Discord. + +```bash +docker run -d --restart=always -p 3001:3001 \ + -v uptime-kuma:/app/data --name uptime-kuma louislam/uptime-kuma:1 +``` + +Puis, dans son interface : + +| Réglage | Valeur | +| ------------ | ------------------------------------------- | +| Type | HTTP(s) - Keyword | +| URL | `http://node01.zi-host.ch:25571/api/health` | +| Mot-clé | `"status":"ok"` | +| Intervalle | 60 s | +| Notification | Webhook Discord vers ton salon de logs | + +> **Surveille l'origine, pas le domaine public.** Cloudflare renvoie un challenge à toute requête non-navigateur : une sonde sur `https://fws-bot.laxacube.ch` signalerait une panne permanente qui n'existe pas. + +Le mot-clé compte : une page qui répond `200` mais sans `"status":"ok"` n'est pas un bot en bonne santé. + +### 3.2 Ce que le bot surveille déjà lui-même + +- Chaque déploiement, réussi ou non, est annoncé sur Discord et consigné avec son journal. +- Les erreurs d'appel Gitea partent dans le salon `errors`. +- **Paramètres → Tester la connexion** vérifie Discord et Gitea à la demande. + +Ça couvre les pannes partielles. Ça ne couvre pas un processus mort — d'où le point 3.1. + +--- + +## 4. Sauvegarder hors du conteneur + +**Le problème qu'on résout.** Le bouton _Sauvegarder la base_ écrit dans `data/backups`, **à l'intérieur du conteneur**. Une reconstruction efface les deux. C'est déjà arrivé : les salons vocaux orphelins venaient d'une base repartie de zéro. + +### 4.1 Sauvegardes du panel (le plus simple) + +Pterodactyl sait archiver le serveur entier, hors conteneur. + +**Panel → Schedules → Create schedule** + +| Réglage | Valeur | +| ------- | ----------------------- | +| Nom | Sauvegarde hebdomadaire | +| Cron | `0 4 * * 1` (lundi 4 h) | +| Tâche | _Create backup_ | + +Les archives apparaissent dans l'onglet **Backups**, avec téléchargement. Vérifie la limite d'archives de ton offre. + +### 4.2 Instantané cohérent de la base + +Une archive de fichiers peut attraper la base en cours d'écriture. Le bot, lui, produit une copie cohérente (`VACUUM INTO`), même journal WAL actif. + +Crée un jeton dans **Paramètres → Jetons d'API** (niveau Owner), puis, depuis une machine qui tourne en permanence : + +```bash +# Chaque nuit à 3 h +0 3 * * * curl -sS -X POST -H "Authorization: Bearer fws_…" \ + http://node01.zi-host.ch:25571/api/settings/backup +``` + +Le fichier atterrit dans `BACKUP_DIR`, que la sauvegarde du panel emporte ensuite. + +### 4.3 Vraiment hors site + +Une sauvegarde chez le même hébergeur ne protège pas d'un incident chez lui. Depuis une machine qui a l'accès SFTP du panel : + +```bash +rclone sync sftp-panel:/home/container/data backblaze:fws-bot-backups \ + --backup-dir backblaze:fws-bot-backups/anciens/$(date +%F) +``` + +### 4.4 Tester la restauration + +Une sauvegarde jamais restaurée n'est pas une sauvegarde. Une fois : + +```bash +cp fws-bot-2026-09-24.sqlite /tmp/test.sqlite +DATABASE_PATH=/tmp/test.sqlite npm run db:init +``` + +La commande doit se terminer sans erreur et appliquer les migrations. + +--- + +## Dans quel ordre + +1. **Chapitre 1** — supprime une famille entière de pannes, ne demande que de la configuration. +2. **Chapitre 2** — évite de découvrir un bug en production. +3. **Chapitre 4** — protège ce qui n'est pas remplaçable. +4. **Chapitre 3** — utile, mais vient après ce qui empêche les pannes plutôt que ce qui les signale.