Actualiser .gitea/workflows/promote-prod.yml

This commit is contained in:
moham committed 2025-09-19 12:59:57 +02:00
1 parent 8f507871c7
commit fb45cabd9b
1 file changed
+70 -12
+70 -12
View File
@@ -1,21 +1,79 @@
name: promote-to-prod
name: promote-prod
on:
workflow_dispatch: {}
concurrency:
group: promote-prod
cancel-in-progress: true
# exécution manuelle dans l’onglet Actions
workflow_dispatch:
inputs:
sha:
description: "Commit à promouvoir (optionnel). Vide = commit déclencheur"
required: false
jobs:
promote:
runs-on: ubuntu-latest
steps:
- name: Promote to PROD
# 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
- name: Promote commit sur PROD (via SSH)
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 }}
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
host: ${{ secrets.SSH_HOST }} # srv.ephaitek.com
port: ${{ secrets.SSH_PORT }} # 2224
username: ${{ secrets.SSH_USER }} # deployer
key: ${{ secrets.SSH_KEY }}
envs: DEPLOY_PULL_TOKEN,PROMOTE_SHA
script: |
set -euo pipefail
export IHM_DRY_RUN=0
/srv/ihm/scripts/docker-run.sh
repo=/srv/ihm/app/IHMKOS
rollback_file=/srv/ihm/app/.rollback_commit
# (sécurité git)
git config --global --add safe.directory "${repo}" || true
# Auth HTTPS non interactive pour fetch/pull
umask 077
cat > ~/.netrc <<EOF
machine ephagit.ephaitek.com
login moham
password ${DEPLOY_PULL_TOKEN}
EOF
cd "${repo}"
# 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
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')"