- FastAPI backend with JWT authentication - ElGamal, RSA-PSS, ZK-proofs crypto modules - HTML5/JS frontend SPA - MariaDB database with 5 tables - Docker Compose with 3 services (frontend, backend, mariadb) - Comprehensive tests for cryptography - Typst technical report (30+ pages) - Makefile with development commands
224 lines
4.2 KiB
Markdown
224 lines
4.2 KiB
Markdown
# Guide de Déploiement
|
|
|
|
## Prérequis
|
|
|
|
- **Docker** 20.10+
|
|
- **Docker Compose** 1.29+
|
|
- **Python** 3.12 (pour développement local)
|
|
- **Git**
|
|
|
|
## Installation Rapide
|
|
|
|
### 1. Cloner le projet
|
|
|
|
```bash
|
|
cd /home/paul/CIA
|
|
git clone <repo-url> e-voting-system
|
|
cd e-voting-system
|
|
```
|
|
|
|
### 2. Configurer l'environnement
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
# Éditer .env si nécessaire
|
|
```
|
|
|
|
### 3. Démarrer avec Docker
|
|
|
|
```bash
|
|
./start.sh
|
|
# Ou
|
|
docker-compose up -d
|
|
```
|
|
|
|
L'application est maintenant accessible à :
|
|
- **Frontend** : http://localhost:3000
|
|
- **Backend API** : http://localhost:8000
|
|
- **API Documentation** : http://localhost:8000/docs
|
|
|
|
## Développement Local
|
|
|
|
### Installation de l'environnement Python
|
|
|
|
```bash
|
|
# Installer Poetry (si nécessaire)
|
|
curl -sSL https://install.python-poetry.org | python3 -
|
|
|
|
# Installer les dépendances
|
|
make install
|
|
# Ou
|
|
poetry install
|
|
```
|
|
|
|
### Démarrer le backend en mode développement
|
|
|
|
```bash
|
|
make dev
|
|
# Ou
|
|
poetry run uvicorn src.backend.main:app --reload
|
|
```
|
|
|
|
Le backend s'auto-recharge à chaque modification de fichier.
|
|
|
|
### Accéder au frontend en développement
|
|
|
|
Ouvrir un navigateur sur : http://localhost:3000
|
|
|
|
### Commandes utiles
|
|
|
|
```bash
|
|
# Voir les logs
|
|
make logs
|
|
# ou
|
|
docker-compose logs -f
|
|
|
|
# Arrêter les conteneurs
|
|
make down
|
|
# ou
|
|
docker-compose down
|
|
|
|
# Voir l'état des conteneurs
|
|
docker-compose ps
|
|
|
|
# Exécuter les tests
|
|
make test
|
|
# ou
|
|
poetry run pytest tests/ -v
|
|
|
|
# Vérifier la qualité du code
|
|
make lint
|
|
# ou
|
|
poetry run ruff check src/
|
|
|
|
# Formater le code
|
|
make format
|
|
# ou
|
|
poetry run black src/
|
|
```
|
|
|
|
## Structure de la Base de Données
|
|
|
|
### Tables principales
|
|
|
|
1. **voters** : Électeurs enregistrés
|
|
2. **elections** : Élections disponibles
|
|
3. **candidates** : Candidats par élection
|
|
4. **votes** : Votes chiffrés
|
|
5. **audit_logs** : Journal d'audit
|
|
|
|
Voir `docker/init.sql` pour le schéma complet.
|
|
|
|
## Configuration de Production
|
|
|
|
### Variables d'environnement
|
|
|
|
```bash
|
|
# Changez ces valeurs en production !
|
|
DB_ROOT_PASSWORD=<random-string>
|
|
DB_PASSWORD=<random-string>
|
|
SECRET_KEY=<random-key-min-32-chars>
|
|
DEBUG=false
|
|
|
|
# CORS (restreindre les origines)
|
|
CORS_ORIGINS="https://domain.com"
|
|
|
|
# HTTPS
|
|
HTTPS_ONLY=true
|
|
```
|
|
|
|
### Recommandations
|
|
|
|
1. **Mots de passe** : Utilisez des chaînes aléatoires longues
|
|
2. **Secret Key** : Générer avec `openssl rand -hex 32`
|
|
3. **HTTPS** : Configurer avec un certificat SSL/TLS
|
|
4. **Base de données** : Sauvegarde régulière
|
|
5. **Logs** : Centraliser les logs
|
|
6. **Monitoring** : Configurer des alertes
|
|
|
|
### Exemple de déploiement production
|
|
|
|
```bash
|
|
# Générer des secrets
|
|
export DB_PASSWORD=$(openssl rand -hex 16)
|
|
export SECRET_KEY=$(openssl rand -hex 32)
|
|
|
|
# Créer .env.production
|
|
cat > .env.production << EOF
|
|
DB_HOST=db.production.com
|
|
DB_PORT=3306
|
|
DB_NAME=evoting_prod
|
|
DB_USER=evoting_user
|
|
DB_PASSWORD=$DB_PASSWORD
|
|
SECRET_KEY=$SECRET_KEY
|
|
DEBUG=false
|
|
CORS_ORIGINS="https://vote.company.com"
|
|
EOF
|
|
|
|
# Démarrer avec le fichier .env.production
|
|
docker-compose --env-file .env.production up -d
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### MariaDB ne démarre pas
|
|
|
|
```bash
|
|
# Vérifier les logs
|
|
docker-compose logs mariadb
|
|
|
|
# Réinitialiser la BD
|
|
docker-compose down -v
|
|
docker-compose up -d
|
|
```
|
|
|
|
### Port déjà utilisé
|
|
|
|
```bash
|
|
# Changer les ports dans .env
|
|
# Ou libérer le port
|
|
lsof -i :3000 # Trouver le processus
|
|
kill -9 <PID> # Le terminer
|
|
```
|
|
|
|
### Problèmes de connexion API
|
|
|
|
1. Vérifier que les conteneurs tournent : `docker-compose ps`
|
|
2. Vérifier la configuration réseau : `docker-compose exec backend ping mariadb`
|
|
3. Consulter les logs : `docker-compose logs backend`
|
|
|
|
## Sauvegarde et Restauration
|
|
|
|
### Sauvegarder la BD
|
|
|
|
```bash
|
|
docker-compose exec mariadb mysqldump -u evoting_user -p evoting_db > backup.sql
|
|
```
|
|
|
|
### Restaurer la BD
|
|
|
|
```bash
|
|
docker-compose exec -T mariadb mysql -u evoting_user -p evoting_db < backup.sql
|
|
```
|
|
|
|
## Arrêt et Nettoyage
|
|
|
|
```bash
|
|
# Arrêter les conteneurs (données conservées)
|
|
make down
|
|
|
|
# Arrêter et supprimer les volumes (ATTENTION: données supprimées)
|
|
docker-compose down -v
|
|
|
|
# Nettoyage complet
|
|
./clean.sh
|
|
```
|
|
|
|
## Performance
|
|
|
|
- **Frontend** : Serveur HTTP statique (http-server)
|
|
- **Backend** : Uvicorn ASGI (4 workers par défaut)
|
|
- **BD** : Connection pooling (10 connexions par défaut)
|
|
|
|
Ajuster les paramètres dans `docker-compose.yml` si nécessaire.
|