Files
serv_benchmark/docs/08_installation_bootstrap.md
2025-12-14 10:40:54 +01:00

239 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 08 Script d'installation & Bootstrapping (install.sh)
Objectif : fournir un guide exhaustif et un script dinstallation automatisée de lapplication
**Linux BenchTools** (backend + frontend + dépendances) ainsi que son organisation dans le dépôt.
Ce fichier décrit :
- Le rôle du script `install.sh`
- Les prérequis système
- Linstallation via Docker ou native
- La génération automatique de larborescence
- Les variables denvironnement nécessaires
- Le lancement des services
---
# 1. Objectifs du script `install.sh`
Le script doit :
1. Vérifier les prérequis (Docker, Docker Compose, Python si installation native)
2. Créer l'arborescence du projet si inexistante
3. Générer les fichiers `.env` nécessaires
4. Installer le backend (FastAPI)
5. Installer le frontend (fichiers statiques)
6. Construire et lancer les conteneurs
7. Vérifier que lapplication fonctionne via un health check
8. Afficher les URL utiles et les commandes dusage
---
# 2. Arborescence créée automatiquement
```
linux-benchtools/
├── backend/
│ ├── app/
│ ├── Dockerfile
│ ├── requirements.txt
│ └── data/ (auto)
├── frontend/
│ ├── index.html
│ ├── devices.html
│ ├── device_detail.html
│ ├── settings.html
│ ├── css/
│ └── js/
├── uploads/ (auto)
├── docker-compose.yml
├── .env
└── install.sh
```
---
# 3. Prérequis système
Le script doit vérifier la présence de :
- **curl**
- **git**
- **Docker**
- **Docker Compose (plugin)**
Si absent → afficher un message clair (avec commande dinstallation Debian/Ubuntu).
Exemple :
```bash
if ! command -v docker >/dev/null 2>&1; then
echo "[ERREUR] Docker nest pas installé."
echo "Installez-le avec :"
echo " curl -fsSL https://get.docker.com | sh"
exit 1
fi
```
---
# 4. Fichier `.env` généré
Le script crée automatiquement un fichier `.env` si absent.
Exemple :
```
API_TOKEN=$(openssl rand -hex 32)
DATABASE_URL=sqlite:////app/data/data.db
UPLOAD_DIR=/app/uploads
BACKEND_PORT=8007
FRONTEND_PORT=8087
```
---
# 5. docker-compose.yml généré
Le script crée un fichier minimal :
```
version: "3.9"
services:
backend:
build: ./backend
ports:
- "${BACKEND_PORT}:8007"
volumes:
- ./backend/data:/app/data
- ./uploads:/app/uploads
env_file: .env
restart: unless-stopped
frontend:
image: nginx:latest
volumes:
- ./frontend:/usr/share/nginx/html:ro
ports:
- "${FRONTEND_PORT}:80"
restart: unless-stopped
```
---
# 6. Installation native (option)
Si l'utilisateur passe `install.sh --native` :
- Installation Python + venv
- Installation requirements.txt
- Exécution via :
```
uvicorn app.main:app --host 0.0.0.0 --port 8007
```
Frontend servi via un simple `python3 -m http.server`.
---
# 7. Vérification de linstallation
Une fois les services lancés :
```
curl -s http://localhost:${BACKEND_PORT}/api/health
```
Si réponse :
```
{"status":"ok"}
```
→ installation validée.
---
# 8. Affichage final après installation
Le script doit afficher :
```
Installation terminée !
Backend API : http://localhost:8007
Frontend UI : http://localhost:8087
Token API : <xxx>
Pour exécuter un benchmark sur une machine :
curl -s <URL bench.sh> | bash -s -- --server http://<ip>:8007/api/benchmark --token <TOKEN>
```
---
# 9. Structure du script `install.sh`
### Exemple de squelette :
```bash
#!/usr/bin/env bash
set -e
echo "[INFO] Vérification des prérequis..."
# test docker, docker compose, curl...
echo "[INFO] Création des dossiers..."
mkdir -p backend/data
mkdir -p uploads
echo "[INFO] Génération du fichier .env..."
if [ ! -f .env ]; then
API_TOKEN=$(openssl rand -hex 32)
cat <<EOF > .env
API_TOKEN=$API_TOKEN
DATABASE_URL=sqlite:////app/data/data.db
UPLOAD_DIR=/app/uploads
BACKEND_PORT=8007
FRONTEND_PORT=8087
EOF
fi
echo "[INFO] Construction des containers..."
docker compose build
echo "[INFO] Lancement..."
docker compose up -d
echo "[INFO] Vérification..."
sleep 2
curl -s http://localhost:8007/api/health || {
echo "[ERREUR] Le backend ne répond pas."
exit 1
}
echo "----------------------------------------------"
echo " Linux BenchTools installé avec succès !"
echo " Backend : http://localhost:8007"
echo " Frontend : http://localhost:8087"
echo " Token : $(grep API_TOKEN .env | cut -d= -f2)"
echo "----------------------------------------------"
```
---
# 10. Améliorations futures
- Choix interactif du port
- Installation sans Docker (automatique)
- Ajout d'un mode "cluster" (plusieurs workers backend)
- Génération automatique dun certificat TLS