279 lines
6.1 KiB
Markdown
279 lines
6.1 KiB
Markdown
# Guide de déploiement — Groupe Méditation
|
|
|
|
## 27 modules · Debian Bookworm + NGINX + PostgreSQL 16
|
|
|
|
Testé sur Debian 12 (Bookworm) avec un utilisateur `ansible` ayant accès sudo.
|
|
|
|
---
|
|
|
|
## 0. Prérequis système
|
|
|
|
```bash
|
|
sudo apt update
|
|
sudo apt install -y curl ca-certificates gnupg
|
|
```
|
|
|
|
---
|
|
|
|
## 1. Installer PostgreSQL 16
|
|
|
|
Debian Bookworm inclut PostgreSQL 15 par défaut. Pour le 16, ajouter le dépôt officiel PGDG :
|
|
|
|
```bash
|
|
sudo install -d /usr/share/postgresql-common/pgdg
|
|
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc \
|
|
--fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
|
|
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" \
|
|
| sudo tee /etc/apt/sources.list.d/pgdg.list
|
|
|
|
sudo apt update
|
|
sudo apt install -y postgresql-16 postgresql-client-16
|
|
|
|
sudo systemctl enable postgresql
|
|
sudo systemctl start postgresql
|
|
```
|
|
|
|
Créer l'utilisateur et la base :
|
|
|
|
```bash
|
|
sudo -u postgres psql << 'SQL'
|
|
CREATE USER grpmed WITH PASSWORD 'CHANGEZ_CE_MOT_DE_PASSE';
|
|
CREATE DATABASE groupe_meditation OWNER grpmed;
|
|
GRANT ALL PRIVILEGES ON DATABASE groupe_meditation TO grpmed;
|
|
\c groupe_meditation
|
|
GRANT ALL ON SCHEMA public TO grpmed;
|
|
SQL
|
|
```
|
|
|
|
Vérifier :
|
|
|
|
```bash
|
|
sudo -u postgres psql -c "SELECT version();"
|
|
```
|
|
|
|
---
|
|
|
|
## 2. Installer Node.js 20
|
|
|
|
Debian Bookworm inclut Node.js 18. Pour le 20 :
|
|
|
|
```bash
|
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
|
sudo apt install -y nodejs
|
|
```
|
|
|
|
Vérifier :
|
|
|
|
```bash
|
|
node --version
|
|
npm --version
|
|
```
|
|
|
|
---
|
|
|
|
## 3. Installer Python et les dépendances système
|
|
|
|
```bash
|
|
sudo apt install -y python3 python3-pip python3-venv
|
|
|
|
# Dépendances système pour WeasyPrint (rapports PDF)
|
|
sudo apt install -y libpango-1.0-0 libpangocairo-1.0-0 \
|
|
libgdk-pixbuf2.0-0 libffi-dev libcairo2
|
|
```
|
|
|
|
---
|
|
|
|
## 4. Installer NGINX
|
|
|
|
```bash
|
|
sudo apt install -y nginx
|
|
sudo systemctl enable nginx
|
|
sudo systemctl start nginx
|
|
```
|
|
|
|
---
|
|
|
|
## 5. Déployer le code source
|
|
|
|
```bash
|
|
# Copier l'archive sur le serveur, puis :
|
|
cd ~
|
|
tar xzf groupe-meditation-complet.tar.gz
|
|
|
|
# Backend
|
|
sudo mkdir -p /opt/groupe-meditation
|
|
sudo cp -r ~/groupe-meditation/backend/ /opt/groupe-meditation/backend/
|
|
sudo cp -r ~/groupe-meditation/deploy/ /opt/groupe-meditation/deploy/
|
|
|
|
# Environnement virtuel Python
|
|
cd /opt/groupe-meditation/backend
|
|
sudo python3 -m venv venv
|
|
sudo /opt/groupe-meditation/backend/venv/bin/pip install -r requirements.txt
|
|
```
|
|
|
|
---
|
|
|
|
## 6. Configurer le backend
|
|
|
|
```bash
|
|
cd /opt/groupe-meditation/backend
|
|
sudo cp .env.example .env
|
|
sudo nano .env
|
|
```
|
|
|
|
Modifier `.env` :
|
|
|
|
```
|
|
DATABASE_URL=postgresql+asyncpg://grpmed:VOTRE_MOT_DE_PASSE@localhost:5432/groupe_meditation
|
|
JWT_SECRET=COLLEZ_ICI_LA_SORTIE_DE_LA_COMMANDE_SUIVANTE
|
|
CORS_ORIGINS=["https://groupe-meditation.chezlepro.ca"]
|
|
INVITATION_EXPIRE_HOURS=48
|
|
```
|
|
|
|
Générer le secret JWT :
|
|
|
|
```bash
|
|
openssl rand -base64 48
|
|
```
|
|
|
|
---
|
|
|
|
## 7. Initialiser la base de données (23 tables)
|
|
|
|
```bash
|
|
cd /opt/groupe-meditation
|
|
sudo /opt/groupe-meditation/backend/venv/bin/python deploy/seed.py
|
|
```
|
|
|
|
Le script crée **interactivement** :
|
|
- Les 23 tables
|
|
- Les 10 postes prédéfinis
|
|
- La répartition par défaut des contributions (30/30/30/10)
|
|
- La littérature de base (5 titres)
|
|
- Le premier groupe et le premier membre
|
|
- Un code d'invitation valide 7 jours
|
|
|
|
---
|
|
|
|
## 8. Créer le service systemd
|
|
|
|
```bash
|
|
sudo cp /opt/groupe-meditation/deploy/groupe-meditation.service /etc/systemd/system/
|
|
sudo chown -R www-data:www-data /opt/groupe-meditation
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable groupe-meditation
|
|
sudo systemctl start groupe-meditation
|
|
```
|
|
|
|
Vérifier :
|
|
|
|
```bash
|
|
sudo systemctl status groupe-meditation
|
|
curl -s http://127.0.0.1:8000/api/health
|
|
```
|
|
|
|
Doit retourner `{"status":"ok","app":"Groupe Méditation","version":"0.1.0"}`
|
|
|
|
---
|
|
|
|
## 9. Construire et déployer le frontend
|
|
|
|
```bash
|
|
cd ~/groupe-meditation/frontend
|
|
npm install
|
|
npm run build
|
|
|
|
sudo mkdir -p /var/www/groupe-meditation
|
|
sudo cp -r dist/* /var/www/groupe-meditation/
|
|
sudo chown -R www-data:www-data /var/www/groupe-meditation
|
|
```
|
|
|
|
---
|
|
|
|
## 10. Configurer NGINX
|
|
|
|
NGINX fait tout : fichiers statiques du frontend + reverse proxy vers FastAPI.
|
|
|
|
```bash
|
|
sudo cp ~/groupe-meditation/deploy/nginx-groupe-meditation.conf \
|
|
/etc/nginx/sites-available/groupe-meditation
|
|
sudo ln -sf /etc/nginx/sites-available/groupe-meditation /etc/nginx/sites-enabled/
|
|
|
|
# Retirer le site par défaut si présent
|
|
sudo rm -f /etc/nginx/sites-enabled/default
|
|
|
|
sudo nginx -t
|
|
sudo systemctl reload nginx
|
|
```
|
|
|
|
Tester en HTTP :
|
|
|
|
```bash
|
|
curl -s http://groupe-meditation.chezlepro.ca/api/health
|
|
```
|
|
|
|
---
|
|
|
|
## 11. Certificat TLS (Let's Encrypt)
|
|
|
|
```bash
|
|
sudo apt install -y certbot python3-certbot-nginx
|
|
sudo certbot --nginx -d groupe-meditation.chezlepro.ca
|
|
```
|
|
|
|
Certbot modifie automatiquement la config NGINX pour ajouter HTTPS et la redirection 80→443.
|
|
|
|
---
|
|
|
|
## 12. Sauvegarde automatique
|
|
|
|
```bash
|
|
sudo cp ~/groupe-meditation/deploy/backup.sh /etc/cron.daily/groupe-meditation-backup
|
|
sudo chmod +x /etc/cron.daily/groupe-meditation-backup
|
|
```
|
|
|
|
---
|
|
|
|
## 13. Vérification finale
|
|
|
|
```bash
|
|
# API en HTTPS
|
|
curl -s https://groupe-meditation.chezlepro.ca/api/health | python3 -m json.tool
|
|
|
|
# Documentation OpenAPI
|
|
# Ouvrir https://groupe-meditation.chezlepro.ca/api/docs
|
|
|
|
# Frontend
|
|
# Ouvrir https://groupe-meditation.chezlepro.ca
|
|
# Se connecter avec le prénom et le PIN créés lors du seed
|
|
```
|
|
|
|
---
|
|
|
|
## Dépannage
|
|
|
|
| Problème | Commande |
|
|
|----------|----------|
|
|
| API ne démarre pas | `sudo journalctl -u groupe-meditation -f` |
|
|
| Erreur base de données | `sudo -u postgres psql -d groupe_meditation -c "SELECT count(*) FROM groupes;"` |
|
|
| NGINX 502 | `sudo systemctl status groupe-meditation` |
|
|
| WeasyPrint échoue | `sudo apt install libpango-1.0-0 libpangocairo-1.0-0` |
|
|
| seed.py ImportError | Vérifier les noms de classes dans `backend/app/models/` |
|
|
|
|
## Mise à jour de l'application
|
|
|
|
```bash
|
|
# Backend
|
|
cd /opt/groupe-meditation/backend
|
|
sudo venv/bin/pip install -r requirements.txt
|
|
sudo systemctl restart groupe-meditation
|
|
|
|
# Frontend
|
|
cd ~/groupe-meditation/frontend
|
|
npm install && npm run build
|
|
sudo cp -r dist/* /var/www/groupe-meditation/
|
|
```
|
|
|
|
---
|
|
|
|
**Hébergé au Québec · 100% logiciel libre · Zéro traçage**
|