80 lines
2.6 KiB
YAML
80 lines
2.6 KiB
YAML
name: promote-prod
|
||
|
||
on:
|
||
# 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:
|
||
# 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 }} # 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
|
||
|
||
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')"
|