Actualiser .gitea/workflows/promote-prod.yml
This commit is contained in:
1 parent
8f507871c7
commit
fb45cabd9b
1 file changed
+67
-9
@@ -1,14 +1,73 @@
|
|||||||
name: promote-to-prod
|
name: promote-prod
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch: {}
|
# exécution manuelle dans l’onglet Actions
|
||||||
concurrency:
|
workflow_dispatch:
|
||||||
group: promote-prod
|
inputs:
|
||||||
cancel-in-progress: true
|
sha:
|
||||||
|
description: "Commit à promouvoir (optionnel). Vide = commit déclencheur"
|
||||||
|
required: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
promote:
|
promote:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
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 }} # 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
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.SSH_HOST }}
|
host: ${{ secrets.SSH_HOST }}
|
||||||
@@ -16,6 +75,5 @@ jobs:
|
|||||||
username: ${{ secrets.SSH_USER }}
|
username: ${{ secrets.SSH_USER }}
|
||||||
key: ${{ secrets.SSH_KEY }}
|
key: ${{ secrets.SSH_KEY }}
|
||||||
script: |
|
script: |
|
||||||
set -euo pipefail
|
set -e
|
||||||
export IHM_DRY_RUN=0
|
echo "Rollback possible vers: $(cat /srv/ihm/app/.rollback_commit || echo 'inconnu')"
|
||||||
/srv/ihm/scripts/docker-run.sh
|
|
||||||
Reference in new issue
Block a user