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 name: promote-prod
on: on:
# exécution manuelle dans l’onglet Actions
workflow_dispatch: workflow_dispatch:
inputs: inputs:
sha: sha:
description: "Commit à promouvoir (optionnel). Vide = commit déclencheur" description: "Commit SHA à promouvoir (vide = SHA du push)"
required: false required: false
jobs: jobs:
promote: promote:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# on garde le mapping LAN pour le runner - uses: actions/checkout@v4
- name: Force LAN host mapping (ephagit & srv) with: { fetch-depth: 1 }
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
- name: Promote commit sur PROD (via SSH) - name: Promote sur PROD (checkout + restart systemd)
uses: appleboy/ssh-action@v1.0.3 uses: appleboy/ssh-action@v1.0.3
env: env:
# PAT Gitea déjà créé comme secret
DEPLOY_PULL_TOKEN: ${{ secrets.DEPLOY_PULL_TOKEN }} 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 }} PROMOTE_SHA: ${{ inputs.sha != '' && inputs.sha || github.sha }}
SYSTEMD_SERVICE: ${{ vars.SYSTEMD_SERVICE }} # ihm-ephapoc
with: with:
host: ${{ secrets.SSH_HOST }} # srv.ephaitek.com host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }} # 2224 port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USER }} # deployer username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }} key: ${{ secrets.SSH_KEY }}
envs: DEPLOY_PULL_TOKEN,PROMOTE_SHA envs: DEPLOY_PULL_TOKEN,PROMOTE_SHA,SYSTEMD_SERVICE
script: | script: |
set -euo pipefail set -euo pipefail
repo=/srv/ihm/app/IHMKOS 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 git config --global --add safe.directory "${repo}" || true
# Auth HTTPS non interactive pour fetch/pull # Auth non interactive vers Gitea (HTTPS)
umask 077 umask 077
cat > ~/.netrc <<EOF cat > ~/.netrc <<EOF
machine ephagit.ephaitek.com machine ephagit.ephaitek.com
@@ -52,28 +42,17 @@ jobs:
EOF EOF
cd "${repo}" 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 # se positionner exactement sur le commit demandé
git rev-parse HEAD > "${rollback_file}" 2>/dev/null || true
# récupérer & positionner exactement le commit à promouvoir
git fetch origin main --depth=50 git fetch origin main --depth=50
git checkout -f "${PROMOTE_SHA}" git checkout -f "${PROMOTE_SHA}"
git submodule update --init --recursive || true git submodule update --init --recursive || true
# nettoie les traces d'auth
rm -f ~/.netrc rm -f ~/.netrc
# redémarrer la prod # restart du service systemd (appelle ton docker-run.sh)
/srv/ihm/scripts/docker-run-prod.sh sudo -n systemctl daemon-reload || true
sudo -n systemctl restart "${svc}.service"
- name: Afficher le commit de sauvegarde (info) sudo -n systemctl --no-pager --full status "${svc}.service" -l || true
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')"