239 lines
4.7 KiB
Markdown
239 lines
4.7 KiB
Markdown
|
||
# 08 – Script d'installation & Bootstrapping (install.sh)
|
||
|
||
Objectif : fournir un guide exhaustif et un script d’installation automatisée de l’application
|
||
**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
|
||
- L’installation via Docker ou native
|
||
- La génération automatique de l’arborescence
|
||
- Les variables d’environnement 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 l’application fonctionne via un health check
|
||
8. Afficher les URL utiles et les commandes d’usage
|
||
|
||
---
|
||
|
||
# 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 d’installation Debian/Ubuntu).
|
||
|
||
Exemple :
|
||
|
||
```bash
|
||
if ! command -v docker >/dev/null 2>&1; then
|
||
echo "[ERREUR] Docker n’est 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 l’installation
|
||
|
||
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 d’un certificat TLS
|
||
|