Docker Compose for VPS (Let's Encrypt, MariaDB) and intranet (internal CA, SQLite): images, setup script, backups, real-stack test; relative redirects in nginx snippet

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
denis
2026-10-17 16:00:09 +02:00
parent 2ecd4142be
commit f79727f793
25 changed files with 868 additions and 1 deletions
+72
View File
@@ -0,0 +1,72 @@
# Docker Compose: VPS and intranet
An alternative to the [installers](installers.md): the whole stack runs in containers, with nothing installed on the host
except Docker (with the `docker compose` plugin). Two ready-to-use files, one per situation:
| | Public VPS | Intranet (school network) |
|---|---|---|
| File | `docker/compose.vps.yaml` | `docker/compose.intranet.yaml` |
| Command | `./docker/setup.sh vps` | `./docker/setup.sh intranet` |
| HTTPS | **Let's Encrypt** (`certbot` service, automatic renewal) | **internal certificate authority** created on first start |
| Database | **MariaDB** (`db` service) | **SQLite** (`data` volume) |
| Services | `web` (nginx), `backend` (Django), `db`, `certbot`, `backup` | `web`, `backend`, `backup` |
The images contain the site and the Python engine (Pyodide, downloaded and verified at build time): **no `make build`
needed**, and the server needs no Internet access once the images are built.
## VPS
Requirements: Docker, the domain name pointing to the VPS, ports 80 and 443 free.
```bash
git clone git@github.com:deunix-educ/PyQuest.git /opt/PyQuest && cd /opt/PyQuest
./docker/setup.sh vps --domain pyquest.example.org --email you@example.org
```
The script generates the secrets in `docker/.env.vps` (mode 600, never committed, never overwritten), builds the images,
starts the stack with a temporary certificate (nginx must answer for Let's Encrypt to validate the domain), obtains the
real certificate, activates it, then offers to create the first administrator. Add `--staging` to try with Let's
Encrypt's test server (no rate limits).
## Intranet
```bash
./docker/setup.sh intranet --host pyquest.school.lan,192.168.1.20
```
Same principle: secrets in `docker/.env.intranet`, internal authority and certificate created on first start in the `tls`
volume (the certificate is reissued automatically before it expires, the authority does not change). **Computers must
trust the authority once**: page `http://<server>/ca` (see [The installers](installers.md), intranet section, including
one browser profile per student). **Back up the authority's key off the server**:
`docker compose -f docker/compose.intranet.yaml --env-file docker/.env.intranet cp web:/etc/pyquest/tls/ca.key ./ca.key`.
## Operations
Run all commands from the repository root (replace `vps` with `intranet` as needed):
```bash
PQ="docker compose -f docker/compose.vps.yaml --env-file docker/.env.vps"
$PQ ps # service status
$PQ logs -f backend # logs
$PQ exec backend python manage.py createsuperuser # administrator (author management: /api/admin/)
git pull && $PQ up -d --build # update (data, kept in volumes, is preserved)
$PQ down # stop (WITHOUT -v: "down -v" deletes the volumes, hence the data)
```
- **Data**: Docker volumes `db` (MariaDB) or `data` (SQLite), `letsencrypt`, `tls`. An automatic database backup (daily,
14 kept) is written to `docker/backups/` (`PYQUEST_BACKUP_DIR`); remember to copy it off the server.
- **Restoring**: MariaDB, `gunzip < backup.sql.gz | $PQ exec -T db sh -c 'mariadb -u pyquest -p"$MARIADB_PASSWORD" pyquest'`;
SQLite, stop `backend`, then replace `/var/lib/pyquest/db.sqlite3` in the `data` volume with the decompressed backup.
- **Let's Encrypt renewal**: `certbot` checks twice a day; nginx reloads the certificate within six hours at most (or
immediately: `$PQ exec web pyquest-tls reload`).
- **Ports**: Docker publishes 80 and 443 bypassing `ufw` rules; restrict access with the provider's firewall if needed.
For tests, `--http-port` and `--https-port` pick other ports.
- **Rate limiting**: it relies on the IP address nginx sees. On a standard Docker host this is the client's; behind another
proxy it would be the proxy's.
## Verified
`make test-docker` builds the images, starts both stacks on free ports, queries nginx over HTTPS (isolation headers,
Python engine, protected editor, administration, static files, synchronisation, database, backups, backend restart,
authority persistence) and tears everything down. **Not verified for real**: obtaining the Let's Encrypt certificate (the
HTTP challenge is tested, not the exchange with Let's Encrypt) and a renewal at expiry.
+3
View File
@@ -1,5 +1,8 @@
# The installers: VPS and intranet
!!! tip "With Docker"
If you prefer containers, `./docker/setup.sh vps|intranet` does the same: see [Docker Compose](docker.md).
Two scripts do, **in one command**, everything you would otherwise do by hand. Run them **as root on the server**, from a
clone of the repository (outside `/root` and `/home`, e.g. `/opt/PyQuest`), on **Debian or Ubuntu**. They are
**idempotent**: after an interruption, run the same command again. `--dry-run` prints everything that would be done
+73
View File
@@ -0,0 +1,73 @@
# Docker Compose : VPS et intranet
Alternative aux [installateurs](installers.md) : toute la pile tourne dans des conteneurs, sans rien installer sur
l'hôte à part Docker (avec le plugin `docker compose`). Deux fichiers prêts à l'emploi, un par situation :
| | VPS public | Réseau intranet (lycée) |
|---|---|---|
| Fichier | `docker/compose.vps.yaml` | `docker/compose.intranet.yaml` |
| Commande | `./docker/setup.sh vps` | `./docker/setup.sh intranet` |
| HTTPS | **Let's Encrypt** (service `certbot`, renouvellement automatique) | **autorité de certification interne** créée au premier démarrage |
| Base | **MariaDB** (service `db`) | **SQLite** (volume `data`) |
| Services | `web` (nginx), `backend` (Django), `db`, `certbot`, `backup` | `web`, `backend`, `backup` |
Les images contiennent le site et le moteur Python (Pyodide, téléchargé et vérifié à la construction) : **aucun
`make build` à faire**, et le serveur n'a pas besoin d'Internet une fois les images construites.
## VPS
Prérequis : Docker, le nom de domaine qui pointe vers le VPS, les ports 80 et 443 libres.
```bash
git clone git@github.com:deunix-educ/PyQuest.git /opt/PyQuest && cd /opt/PyQuest
./docker/setup.sh vps --domain pyquest.example.org --email toi@example.org
```
Le script génère les secrets dans `docker/.env.vps` (droits 600, jamais commité, jamais écrasé), construit les images,
démarre la pile avec un certificat provisoire (nginx doit répondre pour que Let's Encrypt valide le domaine), obtient le
vrai certificat, le met en service, puis propose de créer le premier administrateur. Ajoute `--staging` pour essayer avec
le serveur de test de Let's Encrypt (pas de limite de débit).
## Intranet
```bash
./docker/setup.sh intranet --host pyquest.lycee.local,192.168.1.20
```
Même principe : secrets dans `docker/.env.intranet`, autorité et certificat internes créés au premier démarrage dans le
volume `tls` (le certificat est réémis automatiquement avant son expiration, l'autorité ne change pas). Les **postes
doivent faire confiance à l'autorité une fois** : page `http://<serveur>/ca` (voir [Les installateurs](installers.md),
section intranet, y compris le profil de navigateur par élève). **Sauvegarde la clé de l'autorité hors du serveur** :
`docker compose -f docker/compose.intranet.yaml --env-file docker/.env.intranet cp web:/etc/pyquest/tls/ca.key ./ca.key`.
## Exploitation
Toutes les commandes se lancent depuis la racine du dépôt (remplacer `vps` par `intranet` selon le cas) :
```bash
PQ="docker compose -f docker/compose.vps.yaml --env-file docker/.env.vps"
$PQ ps # état des services
$PQ logs -f backend # journaux
$PQ exec backend python manage.py createsuperuser # administrateur (gestion des auteurs : /api/admin/)
git pull && $PQ up -d --build # mise à jour (les données, dans des volumes, sont conservées)
$PQ down # arrêt (SANS -v : « down -v » supprime les volumes, donc les données)
```
- **Données** : volumes Docker `db` (MariaDB) ou `data` (SQLite), `letsencrypt`, `tls`. Une sauvegarde automatique de la
base (quotidienne, 14 conservées) est écrite dans `docker/backups/` (`PYQUEST_BACKUP_DIR`) ; pense à la copier hors du
serveur.
- **Restauration** : MariaDB, `gunzip < sauvegarde.sql.gz | $PQ exec -T db sh -c 'mariadb -u pyquest -p"$MARIADB_PASSWORD" pyquest'` ;
SQLite, arrêter `backend` puis remplacer `/var/lib/pyquest/db.sqlite3` dans le volume `data` par la sauvegarde décompressée.
- **Renouvellement Let's Encrypt** : `certbot` vérifie deux fois par jour ; nginx recharge le certificat au plus tard six
heures après (ou tout de suite : `$PQ exec web pyquest-tls reload`).
- **Ports** : Docker publie 80 et 443 en contournant les règles `ufw` ; restreindre l'accès avec le pare-feu du fournisseur
si besoin. Pour des essais, `--http-port` et `--https-port` choisissent d'autres ports.
- **Limitation de débit** : elle repose sur l'adresse IP vue par nginx. Sur un hôte Docker standard c'est celle du client ;
derrière un autre proxy, elle serait celle du proxy.
## Vérifié
`make test-docker` construit les images, démarre les deux piles sur des ports libres, interroge nginx en HTTPS (en-têtes
d'isolation, moteur Python, éditeur protégé, administration, fichiers statiques, synchronisation, base, sauvegardes,
redémarrage du backend, persistance de l'autorité) et détruit tout. **Non vérifié en réel** : l'obtention du certificat
Let's Encrypt (le défi HTTP est testé, pas l'échange avec Let's Encrypt) et un renouvellement à l'échéance.
+3
View File
@@ -1,5 +1,8 @@
# Les installateurs : VPS et intranet
!!! tip "Avec Docker"
Si tu préfères des conteneurs, `./docker/setup.sh vps|intranet` fait la même chose : voir [Docker Compose](docker.md).
Deux scripts font, **d'une seule commande**, tout ce qu'on ferait à la main. Ils se lancent **en root sur le serveur**,
depuis un clone du dépôt (hors de `/root` et `/home`, par exemple `/opt/PyQuest`), sur **Debian ou Ubuntu**. Ils sont
**idempotents** : après une interruption, on relance la même commande. `--dry-run` affiche tout ce qui serait fait sans