Add a verified exact-commit deployment pipeline
Some checks failed
Validate Sokko G / validate (push) Failing after 6m43s
Some checks failed
Validate Sokko G / validate (push) Failing after 6m43s
This commit is contained in:
parent
ca39b76282
commit
daef542474
10 changed files with 525 additions and 24 deletions
|
|
@ -1,30 +1,114 @@
|
|||
# Rôle : valide puis livre manuellement un commit précis de main en production.
|
||||
name: Deploy Sokko G
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
commit:
|
||||
description: Full commit SHA to deploy or roll back to
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
validate:
|
||||
runs-on: docker
|
||||
outputs:
|
||||
commit: ${{ steps.commit.outputs.sha }}
|
||||
|
||||
steps:
|
||||
- name: Deploy on WebApps
|
||||
- name: Validate the requested deployment SHA
|
||||
env:
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
REQUESTED_COMMIT: ${{ inputs.commit }}
|
||||
run: printf '%s' "$REQUESTED_COMMIT" | grep -Eq '^[0-9a-f]{40}$'
|
||||
|
||||
- name: Check out the requested commit
|
||||
uses: https://data.forgejo.org/actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ inputs.commit }}
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up the pinned Node version
|
||||
uses: https://data.forgejo.org/actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24.11.1
|
||||
cache: npm
|
||||
|
||||
- name: Set up the pinned npm version
|
||||
run: npm install --global npm@11.17.0
|
||||
|
||||
- name: Record the validated commit
|
||||
id: commit
|
||||
run: |
|
||||
if ! command -v ssh >/dev/null 2>&1; then
|
||||
commit="$(git rev-parse HEAD)"
|
||||
printf '%s' "$commit" | grep -Eq '^[0-9a-f]{40}$'
|
||||
git merge-base --is-ancestor "$commit" origin/main
|
||||
printf 'sha=%s\n' "$commit" >> "$GITEA_OUTPUT"
|
||||
node --version
|
||||
npm --version
|
||||
|
||||
- name: Install dependencies from the lockfile
|
||||
run: npm ci
|
||||
|
||||
- name: Install the Chromium test runtime
|
||||
run: npx playwright install --with-deps chromium
|
||||
|
||||
- name: Run the complete validation gate
|
||||
run: npm run check:full
|
||||
|
||||
deploy:
|
||||
needs: validate
|
||||
runs-on: docker
|
||||
env:
|
||||
DEPLOY_COMMIT: ${{ needs.validate.outputs.commit }}
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
DEPLOY_SSH_KNOWN_HOSTS: ${{ secrets.DEPLOY_SSH_KNOWN_HOSTS }}
|
||||
|
||||
steps:
|
||||
- name: Install the deployment clients
|
||||
run: |
|
||||
if ! command -v ssh >/dev/null 2>&1 || ! command -v curl >/dev/null 2>&1; then
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends openssh-client
|
||||
apt-get install -y --no-install-recommends curl openssh-client
|
||||
fi
|
||||
|
||||
mkdir -p ~/.ssh
|
||||
printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
- name: Configure the pinned production host key
|
||||
run: |
|
||||
test -n "$DEPLOY_SSH_KEY"
|
||||
test -n "$DEPLOY_SSH_KNOWN_HOSTS"
|
||||
umask 077
|
||||
mkdir -p "$HOME/.ssh"
|
||||
printf '%s\n' "$DEPLOY_SSH_KEY" > "$HOME/.ssh/id_ed25519"
|
||||
printf '%s\n' "$DEPLOY_SSH_KNOWN_HOSTS" > "$HOME/.ssh/known_hosts"
|
||||
ssh-keygen -F '[webapps.shinuwa.fr]:2911' -f "$HOME/.ssh/known_hosts" >/dev/null
|
||||
|
||||
ssh -o StrictHostKeyChecking=no \
|
||||
-i ~/.ssh/id_ed25519 \
|
||||
-p 2911 \
|
||||
shinuwa@192.168.0.100 \
|
||||
"sudo -u shinuwa git -C /data/webapps/sites/sokko-g clean -f -- package-lock.json && sudo /usr/local/bin/deploy-sokko-g"
|
||||
- name: Verify the remote deployment contract
|
||||
run: |
|
||||
contract="$(ssh -o BatchMode=yes -o StrictHostKeyChecking=yes \
|
||||
-o UserKnownHostsFile="$HOME/.ssh/known_hosts" \
|
||||
-i "$HOME/.ssh/id_ed25519" -p 2911 shinuwa@webapps.shinuwa.fr \
|
||||
'cat /usr/local/share/sokko-g/deploy-contract')"
|
||||
test "$contract" = 'exact-commit-v1'
|
||||
|
||||
- name: Deploy the validated commit
|
||||
run: |
|
||||
ssh -o BatchMode=yes -o StrictHostKeyChecking=yes \
|
||||
-o UserKnownHostsFile="$HOME/.ssh/known_hosts" \
|
||||
-i "$HOME/.ssh/id_ed25519" -p 2911 shinuwa@webapps.shinuwa.fr \
|
||||
"sudo /usr/local/bin/deploy-sokko-g --commit '$DEPLOY_COMMIT'"
|
||||
|
||||
- name: Verify the deployed commit and public origin
|
||||
run: |
|
||||
deployed_commit="$(ssh -o BatchMode=yes -o StrictHostKeyChecking=yes \
|
||||
-o UserKnownHostsFile="$HOME/.ssh/known_hosts" \
|
||||
-i "$HOME/.ssh/id_ed25519" -p 2911 shinuwa@webapps.shinuwa.fr \
|
||||
'sudo -u shinuwa git -C /data/webapps/sites/sokko-g rev-parse HEAD')"
|
||||
test "$deployed_commit" = "$DEPLOY_COMMIT"
|
||||
curl --fail --silent --show-error --retry 5 --retry-all-errors \
|
||||
--retry-delay 2 https://sokkog.shinuwa.fr/ >/dev/null
|
||||
curl --fail --silent --show-error --retry 5 --retry-all-errors \
|
||||
--retry-delay 2 https://sokkog.shinuwa.fr/data/site.json >/dev/null
|
||||
|
||||
- name: Remove the deployment key
|
||||
if: always()
|
||||
run: rm -f "$HOME/.ssh/id_ed25519"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue