Actualiser .gitea/workflows/promote-prod.yml

This commit is contained in:
moham committed 2025-09-19 13:51:43 +02:00
1 parent fb45cabd9b
commit 80db81a444
1 file changed
+18 -39
+18 -39
View File
@@ -1,49 +1,39 @@
name: promote-prod
on:
# exécution manuelle dans l’onglet Actions
workflow_dispatch:
inputs:
sha:
description: "Commit à promouvoir (optionnel). Vide = commit déclencheur"
description: "Commit SHA à promouvoir (vide = SHA du push)"
required: false
jobs:
promote:
runs-on: ubuntu-latest
steps:
# on garde le mapping LAN pour le runner
- name: Force LAN host mapping (ephagit & srv)
run: |
echo "10.90.0.10 ephagit.ephaitek.com" >> /etc/hosts
echo "10.10.0.10 srv.ephaitek.com" >> /etc/hosts
getent hosts ephagit.ephaitek.com || true
getent hosts srv.ephaitek.com || true
- uses: actions/checkout@v4
with: { fetch-depth: 1 }
- name: Promote commit sur PROD (via SSH)
- name: Promote sur PROD (checkout + restart systemd)
uses: appleboy/ssh-action@v1.0.3
env:
# PAT Gitea déjà créé comme secret
DEPLOY_PULL_TOKEN: ${{ secrets.DEPLOY_PULL_TOKEN }}
# commit à déployer (input si fourni sinon SHA du workflow)
PROMOTE_SHA: ${{ inputs.sha != '' && inputs.sha || github.sha }}
SYSTEMD_SERVICE: ${{ vars.SYSTEMD_SERVICE }} # ihm-ephapoc
with:
host: ${{ secrets.SSH_HOST }} # srv.ephaitek.com
port: ${{ secrets.SSH_PORT }} # 2224
username: ${{ secrets.SSH_USER }} # deployer
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
envs: DEPLOY_PULL_TOKEN,PROMOTE_SHA
envs: DEPLOY_PULL_TOKEN,PROMOTE_SHA,SYSTEMD_SERVICE
script: |
set -euo pipefail
repo=/srv/ihm/app/IHMKOS
rollback_file=/srv/ihm/app/.rollback_commit
svc="${SYSTEMD_SERVICE:-ihm-ephapoc}"
# (sécurité git)
git config --global --add safe.directory "${repo}" || true
# Auth HTTPS non interactive pour fetch/pull
# Auth non interactive vers Gitea (HTTPS)
umask 077
cat > ~/.netrc <<EOF
machine ephagit.ephaitek.com
@@ -52,28 +42,17 @@ jobs:
EOF
cd "${repo}"
# enregistrer le commit courant pour rollback (dans le dépôt)
git rev-parse HEAD > .rollback_commit
# mémoriser le commit courant pour rollback
git rev-parse HEAD > "${rollback_file}" 2>/dev/null || true
# récupérer & positionner exactement le commit à promouvoir
# se positionner exactement sur le commit demandé
git fetch origin main --depth=50
git checkout -f "${PROMOTE_SHA}"
git submodule update --init --recursive || true
# nettoie les traces d'auth
rm -f ~/.netrc
# redémarrer la prod
/srv/ihm/scripts/docker-run-prod.sh
- name: Afficher le commit de sauvegarde (info)
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
set -e
echo "Rollback possible vers: $(cat /srv/ihm/app/.rollback_commit || echo 'inconnu')"
# restart du service systemd (appelle ton docker-run.sh)
sudo -n systemctl daemon-reload || true
sudo -n systemctl restart "${svc}.service"
sudo -n systemctl --no-pager --full status "${svc}.service" -l || true