- npm audit fix (multer 2.5.0, body-parser, qs, proxy-addr): 0 vulnerabilities - engines node >=22.9 and .nvmrc (prod runs Node 26) - GET /healthz for deployment checks - workflow: check job (npm ci, npm test, npm audit) on every push; deploy only on main after checks, with pinned host key, BatchMode and exact commit SHA - ops/deploy-gameservers-control.sh: lock, refuse dirty tree, fast-forward to the commit, npm ci --omit=dev, wait for /healthz, roll back on failure - stop tracking storage/servers.json (prod storage now lives outside the repo) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.4 KiB
YAML
69 lines
2.4 KiB
YAML
name: Deploy Gameservers Control
|
|
|
|
# Les contrôles tournent à chaque push, sur toutes les branches (une PR est donc contrôlée par
|
|
# le push de sa branche) ; le déploiement, seulement après un push sur main dont les
|
|
# contrôles ont réussi.
|
|
on:
|
|
push:
|
|
|
|
jobs:
|
|
check:
|
|
runs-on: docker
|
|
timeout-minutes: 10
|
|
# Même version majeure de Node que la prod (v26 sur webapps).
|
|
container:
|
|
image: node:26-bookworm
|
|
|
|
steps:
|
|
- uses: https://data.forgejo.org/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
- name: Install dependencies
|
|
run: npm ci --no-fund
|
|
- name: Tests
|
|
run: npm test
|
|
- name: Audit des dépendances de production
|
|
run: npm audit --omit=dev --audit-level=high
|
|
|
|
deploy:
|
|
needs: check
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
runs-on: docker
|
|
timeout-minutes: 10
|
|
container:
|
|
image: node:26-bookworm
|
|
|
|
steps:
|
|
- name: Deploy on WebApps
|
|
env:
|
|
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
# Clé d'hôte de la VM (sortie de `ssh-keyscan -p 2911 192.168.0.100`) : sans elle,
|
|
# n'importe quelle machine qui répondrait à cette adresse recevrait la connexion.
|
|
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
|
|
DEPLOY_COMMIT: ${{ github.sha }}
|
|
run: |
|
|
if ! command -v ssh >/dev/null; then
|
|
apt-get update
|
|
apt-get install -y --no-install-recommends openssh-client
|
|
fi
|
|
|
|
if [ -z "$DEPLOY_KNOWN_HOSTS" ]; then
|
|
echo "Secret DEPLOY_KNOWN_HOSTS manquant (ssh-keyscan -p 2911 192.168.0.100)" >&2
|
|
exit 1
|
|
fi
|
|
printf '%s' "$DEPLOY_COMMIT" | grep -Eq '^[0-9a-f]{40}$'
|
|
|
|
umask 077
|
|
mkdir -p ~/.ssh
|
|
printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
|
|
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
|
|
|
# La clé n'autorise que des commandes précises côté serveur
|
|
# (/usr/local/sbin/deploy-ssh-gate) : garder exactement cette forme.
|
|
ssh -o BatchMode=yes -o StrictHostKeyChecking=yes \
|
|
-i ~/.ssh/id_ed25519 \
|
|
-p 2911 \
|
|
shinuwa@192.168.0.100 \
|
|
"sudo /usr/local/bin/deploy-gameservers-control --commit '$DEPLOY_COMMIT'"
|
|
|
|
- name: Remove the deployment key
|
|
if: always()
|
|
run: rm -f ~/.ssh/id_ed25519
|