190 lines
4.6 KiB
Markdown
190 lines
4.6 KiB
Markdown
# Déploiement — Git + Portainer + CI/CD
|
|
|
|
## Vue d'ensemble
|
|
|
|
```
|
|
PC (WSL) → git push → Gitea (192.168.5.171:3000)
|
|
↓ webhook (Gitea Actions)
|
|
Act Runner (serveur Portainer)
|
|
↓ curl webhook
|
|
Portainer → git pull → docker compose up --build
|
|
↓
|
|
Conteneur 3d-pricing (port 5010)
|
|
```
|
|
|
|
---
|
|
|
|
## 1. Git — initialiser et pousser le code
|
|
|
|
Depuis WSL sur ton PC :
|
|
|
|
```bash
|
|
cd /mnt/c/Users/jbper/Claude/3d-pricing
|
|
|
|
# Init git si pas encore fait
|
|
git init
|
|
git branch -M main
|
|
|
|
# Connecter au repo Gitea (créer le repo vide sur Gitea d'abord)
|
|
git remote add origin http://192.168.5.171:3000/TON_USER/3d-pricing.git
|
|
|
|
# Premier push
|
|
git add -A
|
|
git commit -m "init: 3d-pricing app"
|
|
git push -u origin main
|
|
```
|
|
|
|
> Créer le repo sur Gitea : **+ → New Repository** → nom `3d-pricing` → ne pas cocher "Initialize"
|
|
|
|
---
|
|
|
|
## 2. Gitea Actions — activer
|
|
|
|
### 2a. Activer dans app.ini
|
|
|
|
```bash
|
|
# Trouver app.ini dans le conteneur Gitea
|
|
docker exec gitea find / -name app.ini 2>/dev/null
|
|
|
|
# Éditer (exemple si monté en volume)
|
|
# Ajouter dans app.ini :
|
|
[actions]
|
|
ENABLED = true
|
|
```
|
|
|
|
Redémarrer :
|
|
```bash
|
|
docker restart gitea
|
|
```
|
|
|
|
### 2b. Activer sur le repo
|
|
|
|
Gitea → ton repo → **Settings → General → cocher "Actions"** → Save
|
|
|
|
### 2c. Récupérer un token runner
|
|
|
|
Gitea → **Site Administration (clé à molette) → Actions → Runners → Create new Runner**
|
|
|
|
Copier le **Registration Token**.
|
|
|
|
---
|
|
|
|
## 3. Act Runner — déployer sur le serveur Portainer
|
|
|
|
Sur le **serveur Portainer** :
|
|
|
|
```bash
|
|
git clone http://192.168.5.171:3000/admin/gitea-act-runner.git /opt/gitea-act-runner
|
|
cd /opt/gitea-act-runner
|
|
|
|
# Créer le fichier .env avec le token copié à l'étape 2c
|
|
echo "RUNNER_TOKEN=COLLER_LE_TOKEN_ICI" > .env
|
|
|
|
# Démarrer
|
|
docker compose up -d --build
|
|
|
|
# Vérifier (attendre ~10s)
|
|
docker logs gitea-act-runner
|
|
# → doit afficher "Runner registered successfully"
|
|
```
|
|
|
|
Vérifier dans Gitea → Site Administration → Actions → Runners → statut **Online**.
|
|
|
|
---
|
|
|
|
## 4. Portainer — déployer le stack depuis Git
|
|
|
|
### 4a. Créer le stack
|
|
|
|
Portainer → **Stacks → Add stack**
|
|
- Name : `3d-pricing`
|
|
- Build method : **Git Repository**
|
|
- Repository URL : `http://192.168.5.171:3000/TON_USER/3d-pricing`
|
|
- Repository reference : `refs/heads/main`
|
|
- Compose path : `docker-compose.yml`
|
|
- Authentication : cocher si repo privé → entrer username + mot de passe Gitea
|
|
|
|
Cliquer **Deploy the stack**.
|
|
|
|
### 4b. Activer le webhook GitOps
|
|
|
|
Une fois le stack déployé :
|
|
|
|
Portainer → ton stack → **GitOps updates → Enable**
|
|
- Interval : laisser vide (on déclenche via webhook, pas par polling)
|
|
- Copier la **Webhook URL** générée (format `http://PORTAINER_IP:9000/api/stacks/webhooks/xxxxxxxx`)
|
|
|
|
### 4c. Vérifier
|
|
|
|
L'app doit répondre sur `http://SERVEUR_PORTAINER:5010`
|
|
|
|
---
|
|
|
|
## 5. CI/CD — connecter Gitea Actions → Portainer webhook
|
|
|
|
### 5a. Ajouter le secret dans Gitea
|
|
|
|
Gitea → ton repo → **Settings → Actions → Secrets → Add secret**
|
|
- Name : `PORTAINER_WEBHOOK`
|
|
- Value : l'URL copiée à l'étape 4b
|
|
|
|
### 5b. Le workflow est déjà en place
|
|
|
|
Fichier `.gitea/workflows/deploy.yml` déjà dans le repo :
|
|
```yaml
|
|
name: Deploy via Portainer
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
jobs:
|
|
deploy:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Trigger Portainer stack redeploy
|
|
run: |
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "${{ secrets.PORTAINER_WEBHOOK }}")
|
|
if [ "$HTTP_CODE" != "200" ] && [ "$HTTP_CODE" != "204" ]; then
|
|
echo "Portainer webhook failed (HTTP $HTTP_CODE)"
|
|
exit 1
|
|
fi
|
|
echo "Redeploy triggered (HTTP $HTTP_CODE)"
|
|
```
|
|
|
|
---
|
|
|
|
## 6. Tester le pipeline complet
|
|
|
|
```bash
|
|
# Depuis WSL
|
|
cd /mnt/c/Users/jbper/Claude/3d-pricing
|
|
git add -A
|
|
git commit -m "test: pipeline CI/CD"
|
|
git push
|
|
```
|
|
|
|
Puis surveiller :
|
|
1. **Gitea → ton repo → Actions** → job doit passer vert
|
|
2. **Portainer → Stacks → 3d-pricing** → heure de dernier déploiement mise à jour
|
|
3. `http://SERVEUR_PORTAINER:5010` → app répond
|
|
|
|
---
|
|
|
|
## Résumé des ports et URLs
|
|
|
|
| Service | URL |
|
|
|---|---|
|
|
| Gitea | http://192.168.5.171:3000 |
|
|
| Portainer | http://SERVEUR_PORTAINER:9000 |
|
|
| 3d-pricing | http://SERVEUR_PORTAINER:5010 |
|
|
|
|
## Données persistantes
|
|
|
|
La base SQLite est dans le volume Docker nommé **`3d-pricing-data`**.
|
|
Visible dans Portainer → **Volumes → 3d-pricing-data**.
|
|
|
|
Backup manuel :
|
|
```bash
|
|
docker run --rm -v 3d-pricing-data:/data -v $(pwd):/backup alpine \
|
|
cp /data/pricing.db /backup/pricing_backup_$(date +%Y%m%d).db
|
|
```
|