243 lines
6.8 KiB
Markdown
243 lines
6.8 KiB
Markdown
# Guide de déploiement — Groupe Méditation
|
||
|
||
## 27 modules · Phases 0 à 9 · Infrastructure Debian + Apache + NGINX + PostgreSQL
|
||
|
||
---
|
||
|
||
## Prérequis
|
||
|
||
- Debian 12+ ou Ubuntu 24.04+
|
||
- PostgreSQL 16+
|
||
- Python 3.11+
|
||
- Node.js 20+ (pour le build frontend)
|
||
- Apache 2.4+ avec mod_rewrite et mod_headers
|
||
- NGINX 1.24+ (reverse proxy)
|
||
- Certbot (Let's Encrypt)
|
||
|
||
---
|
||
|
||
## 1. Installer PostgreSQL
|
||
|
||
```bash
|
||
sudo apt update
|
||
sudo apt install -y postgresql-16 postgresql-client-16
|
||
|
||
sudo systemctl enable postgresql
|
||
sudo systemctl start postgresql
|
||
|
||
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
|
||
```
|
||
|
||
## 2. Installer Python et les dépendances
|
||
|
||
```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
|
||
|
||
sudo mkdir -p /opt/groupe-meditation
|
||
sudo chown $USER:$USER /opt/groupe-meditation
|
||
|
||
cp -r backend/ /opt/groupe-meditation/backend/
|
||
cp -r deploy/ /opt/groupe-meditation/deploy/
|
||
|
||
cd /opt/groupe-meditation/backend
|
||
python3 -m venv venv
|
||
source venv/bin/activate
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
### Dépendances Python (requirements.txt)
|
||
|
||
| Paquet | Rôle |
|
||
|--------|------|
|
||
| fastapi | API REST async |
|
||
| uvicorn | Serveur ASGI |
|
||
| sqlalchemy[asyncio] + asyncpg | ORM + driver PostgreSQL |
|
||
| pydantic-settings | Configuration .env |
|
||
| python-jose + bcrypt | JWT + hachage PIN |
|
||
| weasyprint | Génération PDF (rapports C1) |
|
||
|
||
## 3. Configurer le backend
|
||
|
||
```bash
|
||
cd /opt/groupe-meditation/backend
|
||
cp .env.example .env
|
||
nano .env
|
||
```
|
||
|
||
Modifier `.env` :
|
||
```
|
||
DATABASE_URL=postgresql+asyncpg://grpmed:VOTRE_MOT_DE_PASSE@localhost:5432/groupe_meditation
|
||
JWT_SECRET=GENEREZ_AVEC_openssl_rand_base64_48
|
||
CORS_ORIGINS=["https://groupe-meditation.chezlepro.ca"]
|
||
INVITATION_EXPIRE_HOURS=48
|
||
```
|
||
|
||
Générer le secret JWT :
|
||
```bash
|
||
openssl rand -base64 48
|
||
```
|
||
|
||
## 4. Initialiser la base de données (23 tables)
|
||
|
||
```bash
|
||
cd /opt/groupe-meditation
|
||
source backend/venv/bin/activate
|
||
python deploy/seed.py
|
||
```
|
||
|
||
Le script crée **interactivement** :
|
||
- Les 23 tables (groupes, membres, postes, affectations, collectes, dépenses, réunions, présences, PV, décisions, rotations, rapports RSG, jetons, littérature, ventes, contributions, config_repartition, sondages, options_sondage, votes, jumelages, sync_log)
|
||
- Les 10 postes prédéfinis (RSG, RSG Substitut, Trésorier, Secrétaire, Animateur, Accueil, Café, Littérature, Jetons, Clés)
|
||
- La répartition par défaut des contributions (30/30/30/10)
|
||
- La littérature de base (Gros Livre, 12×12, Vivre sans alcool, brochures)
|
||
- Le premier groupe et le premier membre avec son poste
|
||
- Un code d'invitation valide 7 jours
|
||
|
||
## 5. Créer le service systemd
|
||
|
||
```bash
|
||
sudo cp 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
|
||
curl http://127.0.0.1:8000/api/health
|
||
```
|
||
|
||
Le service expose 25 routers API sur le port 8000 :
|
||
- Auth (login, register)
|
||
- Membres, postes, accueil, invitations
|
||
- Collectes, réunions, dépenses, décisions
|
||
- Calendrier, rapports PDF, rotations, paramètres
|
||
- Présences, PV, rapports RSG
|
||
- Jetons, anniversaires, commandes jetons
|
||
- Littérature, ventes littérature
|
||
- Contributions, config répartition
|
||
- Sondages (votes), jumelages (parrainage)
|
||
|
||
## 6. Construire le frontend
|
||
|
||
```bash
|
||
cd 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
|
||
```
|
||
|
||
Le build produit une PWA installable avec :
|
||
- 30 pages React (27 modules + Login + Inscription + Accueil)
|
||
- Tailwind CSS mobile-first
|
||
- Service Worker pour le mode hors ligne
|
||
|
||
## 7. Configurer Apache
|
||
|
||
```bash
|
||
sudo cp deploy/apache-groupe-meditation.conf /etc/apache2/sites-available/
|
||
sudo a2enmod rewrite headers
|
||
sudo a2ensite groupe-meditation
|
||
sudo systemctl reload apache2
|
||
```
|
||
|
||
Apache écoute sur 127.0.0.1:8080 et sert :
|
||
- Les fichiers statiques du build React
|
||
- Le SPA routing (toutes les routes → index.html)
|
||
- Le cache immutable sur les assets (JS, CSS, images)
|
||
|
||
## 8. Configurer NGINX
|
||
|
||
```bash
|
||
sudo cp deploy/nginx-groupe-meditation.conf /etc/nginx/sites-available/groupe-meditation
|
||
sudo ln -s /etc/nginx/sites-available/groupe-meditation /etc/nginx/sites-enabled/
|
||
|
||
# Ajouter dans /etc/nginx/nginx.conf (section http) :
|
||
# limit_req_zone $binary_remote_addr zone=api_limit:10m rate=5r/s;
|
||
|
||
# Obtenir le certificat Let's Encrypt
|
||
sudo certbot certonly --nginx -d groupe-meditation.chezlepro.ca
|
||
|
||
sudo nginx -t
|
||
sudo systemctl reload nginx
|
||
```
|
||
|
||
NGINX est le point d'entrée unique HTTPS :
|
||
- `/` → Apache (fichiers statiques frontend)
|
||
- `/api/*` → FastAPI (Uvicorn port 8000)
|
||
- HSTS, CSP, X-Frame-Options, rate limiting
|
||
|
||
## 9. Sauvegarde automatique
|
||
|
||
```bash
|
||
sudo cp deploy/backup.sh /etc/cron.daily/groupe-meditation-backup
|
||
sudo chmod +x /etc/cron.daily/groupe-meditation-backup
|
||
```
|
||
|
||
- pg_dump quotidien en format custom (-Fc)
|
||
- Rétention 30 jours
|
||
- Stockage Ceph (réplication triple copie)
|
||
- **Test de restauration mensuel recommandé** :
|
||
|
||
```bash
|
||
pg_restore -U grpmed -d groupe_meditation_test /var/backups/groupe-meditation/grpmed_DERNIER.dump
|
||
```
|
||
|
||
## 10. Vérification finale
|
||
|
||
```bash
|
||
# API
|
||
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` (vérifier que FastAPI tourne) |
|
||
| WeasyPrint échoue | `sudo apt install libpango-1.0-0 libpangocairo-1.0-0` |
|
||
| Mise à jour frontend | `cd frontend && npm run build && sudo cp -r dist/* /var/www/groupe-meditation/` |
|
||
| Mise à jour backend | `sudo systemctl restart groupe-meditation` |
|
||
| Ajouter un groupe | Utiliser l'API : `POST /api/groupes/` ou ajouter via le seed |
|
||
|
||
## Mise à jour de l'application
|
||
|
||
```bash
|
||
# Backend
|
||
cd /opt/groupe-meditation/backend
|
||
source venv/bin/activate
|
||
pip install -r requirements.txt
|
||
sudo systemctl restart groupe-meditation
|
||
|
||
# Frontend
|
||
cd 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 · 23 tables · 25 routers · 27 modules**
|