Actualiser .gitea/workflows/promote-prod.yml

This commit is contained in:
moham committed 2025-09-19 16:35:53 +02:00
1 parent 3d70181aff
commit a0f40a6c1d
1 file changed
+43 -8
+43 -8
View File
@@ -11,9 +11,42 @@ jobs:
promote:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 1 }
# 1) Forcer la résolution vers l’IP LAN
- name: Force LAN host mapping (ephagit & srv)
run: |
echo "10.90.0.10 ephagit.ephaitek.com" | sudo tee -a /etc/hosts
echo "10.10.0.10 srv.ephaitek.com" | sudo tee -a /etc/hosts
getent hosts ephagit.ephaitek.com
getent hosts srv.ephaitek.com
# 2) Debug réseau non bloquant
- name: Debug réseau/Git (non bloquant)
shell: bash
continue-on-error: true
run: |
set -xeuo pipefail
git --version
getent hosts ephagit.ephaitek.com
getent hosts srv.ephaitek.com
curl -sI https://ephagit.ephaitek.com/ | head -n1 || true
# 3) Rendre Git “impatient”
- name: Tweaks Git (fail fast)
run: |
git config --global http.lowSpeedLimit 1000
git config --global http.lowSpeedTime 5
# 4) Checkout rapide
- name: actions/checkout (shallow)
uses: actions/checkout@v4
timeout-minutes: 2
with:
fetch-depth: 1
persist-credentials: false
# Si besoin, passe ton PAT pour lever tout doute d’auth :
token: ${{ secrets.CHECKOUT_TOKEN }}
# 5) Promote prod: checkout commit + restart + healthcheck + rollback
- name: Promote sur PROD (checkout + restart + healthcheck + rollback auto)
uses: appleboy/ssh-action@v1.0.3
env:
@@ -33,8 +66,10 @@ jobs:
svc="${SYSTEMD_SERVICE:-ihm-ephapoc}"
url="${HEALTHCHECK_URL:-http://127.0.0.1:15080/}"
# Préparer git
# Préparer git (dépôt local sur srv)
git config --global --add safe.directory "${repo}" || true
# Auth HTTPS non interactive pour le pull si besoin
umask 077
cat > ~/.netrc <<EOF
machine ephagit.ephaitek.com
@@ -42,8 +77,8 @@ jobs:
password ${DEPLOY_PULL_TOKEN}
EOF
# Sauvegarde commit courant pour rollback
cd "${repo}"
# Sauvegarde commit courant pour rollback
git rev-parse HEAD > .rollback_commit
# Se placer sur le commit demandé
@@ -51,11 +86,11 @@ jobs:
git checkout -f "${PROMOTE_SHA}"
git submodule update --init --recursive || true
# Redémarrer le service (qui lance docker-run.sh)
# Redémarrer le service (appelle docker-run.sh)
sudo -n systemctl daemon-reload || true
sudo -n systemctl restart "${svc}.service"
# Health-check (60s, 1s d’intervalle)
# Health-check (60s)
ok=0
for i in $(seq 1 60); do
code="$(curl -sk -o /dev/null -w '%{http_code}' "$url" || true)"
@@ -68,7 +103,7 @@ jobs:
rm -f ~/.netrc
if [ "$ok" -ne 1 ]; then
echo "Health-check KO sur $url -> rollback automatique"
echo "Health-check KO -> rollback"
if [ -s .rollback_commit ]; then
prev="$(cat .rollback_commit)"
git checkout -f "$prev" || { echo "Rollback checkout échoué"; exit 1; }
@@ -77,4 +112,4 @@ jobs:
exit 1
fi
echo "Health-check OK sur $url"
echo "Health-check OK"