Files
admin 209f81aa3d
🚀 Deploy — JH Photomaton / 🔍 Vérification (push) Has been cancelled
🚀 Deploy — JH Photomaton / 🍓 Deploy sur le Pi (push) Has been cancelled
first commit
2026-07-16 00:55:29 +02:00

122 lines
3.7 KiB
Markdown

# CI/CD — Gitea Actions → Raspberry Pi
## Ce que ça fait
À chaque `git push` sur `main`, Gitea :
1. Vérifie la syntaxe Python (`lint`)
2. SSH sur le Pi → `git pull` + `pip install` + `systemctl restart`
Déclenchement manuel possible (avec option "installation complète").
---
## 1. Préparer le Pi
### Cloner le dépôt la première fois
```bash
cd /home/pi
git clone https://gitea.lespatas.ovh/admin/photoBooth.git jh-photomaton
cd jh-photomaton
sudo bash scripts/install.sh
```
### Installer la règle sudoers (permet au CI de restart sans mot de passe)
```bash
sudo cp scripts/sudoers-jh-photomaton /etc/sudoers.d/jh-photomaton
sudo chmod 440 /etc/sudoers.d/jh-photomaton
sudo visudo -c # doit afficher "parsed OK"
```
### Générer une clé SSH dédiée au CI/CD
Sur le Pi :
```bash
ssh-keygen -t ed25519 -C "gitea-cicd-jh-photomaton" -f ~/.ssh/gitea_deploy -N ""
cat ~/.ssh/gitea_deploy.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
# Afficher la clé privée à copier dans Gitea :
cat ~/.ssh/gitea_deploy
```
---
## 2. Configurer les secrets dans Gitea
`Settings → Secrets and Variables → Actions → New Secret`
| Nom | Valeur |
|-----|--------|
| `PI_SSH_HOST` | IP du Pi (ex: `192.168.1.42`) ou hostname si résolvable depuis le serveur Gitea |
| `PI_SSH_USER` | `pi` |
| `PI_SSH_KEY` | Contenu de `~/.ssh/gitea_deploy` (clé **privée**, commence par `-----BEGIN...`) |
| `PI_SSH_PORT` | `22` (optionnel) |
---
## 3. Configurer le runner Gitea Actions
Le workflow nécessite un runner Gitea Actions avec le label `ubuntu-latest`.
### Option A — Runner sur le serveur Gitea (recommandé)
Sur le serveur qui héberge Gitea :
```bash
# Télécharger l'act runner Gitea
wget https://gitea.com/gitea/act_runner/releases/latest/download/act_runner-linux-amd64 -O act_runner
chmod +x act_runner
# Enregistrer le runner (token dans Gitea : Settings → Actions → Runners)
./act_runner register --instance https://gitea.lespatas.ovh \
--token VOTRE_TOKEN --name "gitea-server" --labels "ubuntu-latest:docker://node:16-bullseye"
# Démarrer
./act_runner daemon
```
### Option B — Runner directement sur le Pi (plus simple, pas de Docker)
```bash
wget https://gitea.com/gitea/act_runner/releases/latest/download/act_runner-linux-arm64 -O act_runner
chmod +x act_runner
./act_runner register --instance https://gitea.lespatas.ovh \
--token VOTRE_TOKEN --name "pi-runner" --labels "ubuntu-latest:host"
./act_runner daemon &
```
> Avec `ubuntu-latest:host`, les jobs s'exécutent directement sur le Pi sans Docker.
> Dans ce cas, le job SSH est superflu — on peut simplifier le workflow pour exécuter
> `scripts/update.sh` directement.
---
## 4. Premier push et vérification
```bash
git add .
git commit -m "feat: ajout CI/CD Gitea Actions"
git push origin main
```
Suivre l'exécution dans Gitea : `Repository → Actions`.
---
## 5. Déclenchement manuel (avec installation forcée)
Dans Gitea : `Actions → Deploy — JH Photomaton → Run workflow`
Choisir `force_install = true` pour relancer `install.sh` complet (re-pip, re-service).
---
## Résolution de problèmes
| Problème | Solution |
|----------|----------|
| `Host key verification failed` | Ajouter le Pi dans `~/.ssh/known_hosts` du runner |
| `Permission denied (publickey)` | Vérifier que la clé publique est dans `authorized_keys` du Pi |
| `sudo: systemctl: command not found` | Utiliser `/bin/systemctl` (déjà dans update.sh) |
| `git stash pop` conflit | SSH sur le Pi, résoudre manuellement : `cd /home/pi/jh-photomaton && git checkout -- config/settings.yaml` |
| Le runner ne démarre pas | Vérifier le token dans `gitea.lespatas.ovh/admin/photoBooth/settings/actions/runners` |