CI: nieuwe namen voor secrets en variabelen, SSH alleen met sleutel (geen sshpass), ASF-testdeploy zonder schakelaar
Continuous Integration / config-sls (pull_request) Successful in 6s
Continuous Integration / changes (pull_request) Successful in 12s
Continuous Integration / config-asf (pull_request) Successful in 5s
Continuous Integration / compile-sites (pull_request) Successful in 1m12s
Continuous Integration / frontend-prepare (pull_request) Successful in 34s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m13s
Continuous Integration / frontend-build (pull_request) Successful in 41s
Continuous Integration / backend-build (pull_request) Successful in 1m11s
Continuous Integration / frontend-lint (pull_request) Successful in 41s
Continuous Integration / frontend-test (pull_request) Successful in 2m56s
Continuous Integration / backend-test (pull_request) Successful in 3m59s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Continuous Integration / config-sls (pull_request) Successful in 6s
Continuous Integration / changes (pull_request) Successful in 12s
Continuous Integration / config-asf (pull_request) Successful in 5s
Continuous Integration / compile-sites (pull_request) Successful in 1m12s
Continuous Integration / frontend-prepare (pull_request) Successful in 34s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m13s
Continuous Integration / frontend-build (pull_request) Successful in 41s
Continuous Integration / backend-build (pull_request) Successful in 1m11s
Continuous Integration / frontend-lint (pull_request) Successful in 41s
Continuous Integration / frontend-test (pull_request) Successful in 2m56s
Continuous Integration / backend-test (pull_request) Successful in 3m59s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,10 @@ name: Deploy (SCP)
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
host:
|
||||
description: 'Which host to deploy to: the prefix of its secrets, one of SLS_TEST, SLS_PROD, ASF_TEST (<host>_HOST_ADDRESS, _PORT, _USERNAME, _SSH_KEY)'
|
||||
required: true
|
||||
type: string
|
||||
artifact_name:
|
||||
description: 'Build artifact to download and deploy'
|
||||
required: true
|
||||
@@ -45,70 +49,88 @@ jobs:
|
||||
# Runner-independent: only installs what is missing, and only uses sudo when not already root and sudo exists
|
||||
# (a container on the PC runner has neither sudo nor a need for it; the Pi runner may need it).
|
||||
#
|
||||
# Authentication: the Pi-Main host only allows password login from the Pi runner's address, so every runner other
|
||||
# than that one needs a key. If the secret PI_MAIN_SSH_KEY (private key of the deploy account) is set and works,
|
||||
# the wrappers `rssh` / `rscp` below use it (-i, IdentitiesOnly, BatchMode); otherwise they fall back to sshpass
|
||||
# with the password, which keeps working from the Pi runner. The key lives in a temp directory that is removed
|
||||
# at the end of the job; it is never printed.
|
||||
# Authentication is by SSH key only (no password). The deploy key of the chosen host (<host>_HOST_SSH_KEY) is
|
||||
# written to a temp directory with mode 600; the wrappers `rssh` / `rscp` below use it (-i, IdentitiesOnly,
|
||||
# BatchMode, StrictHostKeyChecking=accept-new with a known_hosts file of this job only) and read the address,
|
||||
# port and user of the chosen host from files in the same directory, so no other step needs the secrets. The
|
||||
# directory is removed at the end of the job; the key is never printed.
|
||||
#
|
||||
# All twelve secrets are mapped here and the right group is chosen in the shell: an expression like
|
||||
# `a && secrets.X || secrets.Y` would silently fall through to another host when a secret is empty.
|
||||
- name: Ensure ssh tooling and authentication
|
||||
env:
|
||||
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
||||
SSH_PASS: ${{ secrets.PI_MAIN_PASSWORD }}
|
||||
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
||||
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
||||
SSH_KEY: ${{ secrets.PI_MAIN_SSH_KEY }}
|
||||
TARGET: ${{ inputs.host }}
|
||||
SLS_TEST_HOST_ADDRESS: ${{ secrets.SLS_TEST_HOST_ADDRESS }}
|
||||
SLS_TEST_HOST_PORT: ${{ secrets.SLS_TEST_HOST_PORT }}
|
||||
SLS_TEST_HOST_USERNAME: ${{ secrets.SLS_TEST_HOST_USERNAME }}
|
||||
SLS_TEST_HOST_SSH_KEY: ${{ secrets.SLS_TEST_HOST_SSH_KEY }}
|
||||
SLS_PROD_HOST_ADDRESS: ${{ secrets.SLS_PROD_HOST_ADDRESS }}
|
||||
SLS_PROD_HOST_PORT: ${{ secrets.SLS_PROD_HOST_PORT }}
|
||||
SLS_PROD_HOST_USERNAME: ${{ secrets.SLS_PROD_HOST_USERNAME }}
|
||||
SLS_PROD_HOST_SSH_KEY: ${{ secrets.SLS_PROD_HOST_SSH_KEY }}
|
||||
ASF_TEST_HOST_ADDRESS: ${{ secrets.ASF_TEST_HOST_ADDRESS }}
|
||||
ASF_TEST_HOST_PORT: ${{ secrets.ASF_TEST_HOST_PORT }}
|
||||
ASF_TEST_HOST_USERNAME: ${{ secrets.ASF_TEST_HOST_USERNAME }}
|
||||
ASF_TEST_HOST_SSH_KEY: ${{ secrets.ASF_TEST_HOST_SSH_KEY }}
|
||||
IN_DEPLOY_PATH: ${{ inputs.deploy_path }}
|
||||
IN_SERVICE_NAME: ${{ inputs.service_name }}
|
||||
IN_HEALTH_URL: ${{ inputs.health_check_url }}
|
||||
run: |
|
||||
# Inputs are not secret: print them so an empty one is visible, and stop before anything touches the host.
|
||||
echo "Inputs: deploy_path='$IN_DEPLOY_PATH' service_name='$IN_SERVICE_NAME' health_check_url='$IN_HEALTH_URL'"
|
||||
echo "Inputs: host='$TARGET' deploy_path='$IN_DEPLOY_PATH' service_name='$IN_SERVICE_NAME' health_check_url='$IN_HEALTH_URL'"
|
||||
for v in IN_DEPLOY_PATH IN_SERVICE_NAME IN_HEALTH_URL; do
|
||||
if [ -z "${!v}" ]; then echo "Input $v is empty; refusing to deploy."; exit 1; fi
|
||||
done
|
||||
case "$TARGET" in
|
||||
SLS_TEST|SLS_PROD|ASF_TEST) ;;
|
||||
*) echo "Unknown host '$TARGET' (expected SLS_TEST, SLS_PROD or ASF_TEST); refusing to deploy."; exit 1;;
|
||||
esac
|
||||
SSH_HOST_VALUE=$(printenv "${TARGET}_HOST_ADDRESS")
|
||||
SSH_PORT_VALUE=$(printenv "${TARGET}_HOST_PORT")
|
||||
SSH_USER_VALUE=$(printenv "${TARGET}_HOST_USERNAME")
|
||||
SSH_KEY_VALUE=$(printenv "${TARGET}_HOST_SSH_KEY")
|
||||
for n in HOST_ADDRESS HOST_PORT HOST_USERNAME HOST_SSH_KEY; do
|
||||
if [ -z "$(printenv "${TARGET}_${n}")" ]; then echo "The secret ${TARGET}_${n} is empty or not set; refusing to deploy."; exit 1; fi
|
||||
done
|
||||
|
||||
SUDO=""
|
||||
if [ "$(id -u)" != "0" ] && command -v sudo >/dev/null 2>&1; then SUDO="sudo"; fi
|
||||
if ! command -v sshpass >/dev/null 2>&1 || ! command -v ssh >/dev/null 2>&1 || ! command -v scp >/dev/null 2>&1; then
|
||||
$SUDO apt-get update && $SUDO apt-get install -y sshpass openssh-client
|
||||
if ! command -v ssh >/dev/null 2>&1 || ! command -v scp >/dev/null 2>&1; then
|
||||
$SUDO apt-get update && $SUDO apt-get install -y openssh-client
|
||||
fi
|
||||
|
||||
D=$(mktemp -d)
|
||||
chmod 700 "$D"
|
||||
mkdir -p "$D/bin"
|
||||
echo "DEPLOY_TMP=$D" >> "$GITHUB_ENV"
|
||||
echo "$D/bin" >> "$GITHUB_PATH"
|
||||
|
||||
if [ -n "$SSH_KEY" ]; then
|
||||
printf '%s\n' "$SSH_KEY" > "$D/key"
|
||||
chmod 600 "$D/key"
|
||||
if ssh -i "$D/key" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=15 \
|
||||
-p "$SSH_PORT" "$SSH_USER@$SSH_HOST" true; then
|
||||
touch "$D/key_ok"
|
||||
echo "Authentication: deploy key"
|
||||
else
|
||||
echo "Deploy key rejected or host unreachable with it; falling back to password"
|
||||
fi
|
||||
else
|
||||
echo "No deploy key set; using password"
|
||||
fi
|
||||
printf '%s\n' "$SSH_KEY_VALUE" > "$D/key"
|
||||
chmod 600 "$D/key"
|
||||
printf '%s' "$SSH_HOST_VALUE" > "$D/host"
|
||||
printf '%s' "$SSH_PORT_VALUE" > "$D/port"
|
||||
printf '%s' "$SSH_USER_VALUE" > "$D/user"
|
||||
: > "$D/known_hosts"
|
||||
|
||||
cat > "$D/bin/rssh" <<'WRAP'
|
||||
#!/bin/sh
|
||||
D="$(dirname "$0")/.."
|
||||
if [ -f "$D/key_ok" ]; then
|
||||
exec ssh -i "$D/key" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=no -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" "$@"
|
||||
fi
|
||||
exec sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" "$@"
|
||||
exec ssh -i "$D/key" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile="$D/known_hosts" \
|
||||
-p "$(cat "$D/port")" "$(cat "$D/user")@$(cat "$D/host")" "$@"
|
||||
WRAP
|
||||
cat > "$D/bin/rscp" <<'WRAP'
|
||||
#!/bin/sh
|
||||
# The remote side of a copy is written as @REMOTE@:<path>; it is replaced by user@host.
|
||||
D="$(dirname "$0")/.."
|
||||
if [ -f "$D/key_ok" ]; then
|
||||
exec scp -i "$D/key" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=no -P "$SSH_PORT" "$@"
|
||||
fi
|
||||
exec sshpass -p "$SSH_PASS" scp -o StrictHostKeyChecking=no -P "$SSH_PORT" "$@"
|
||||
REMOTE="$(cat "$D/user")@$(cat "$D/host")"
|
||||
for a in "$@"; do shift; set -- "$@" "$(printf '%s' "$a" | sed "s|^@REMOTE@:|$REMOTE:|")"; done
|
||||
exec scp -i "$D/key" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile="$D/known_hosts" \
|
||||
-P "$(cat "$D/port")" "$@"
|
||||
WRAP
|
||||
chmod +x "$D/bin/rssh" "$D/bin/rscp"
|
||||
|
||||
# Connection check: fails the job here, with a clear message, instead of in the first real step.
|
||||
if "$D/bin/rssh" true; then echo "Authentication: deploy key accepted by ${TARGET}"; else echo "The deploy key of ${TARGET} was rejected or the host is unreachable."; exit 1; fi
|
||||
|
||||
- name: Compute release timestamp
|
||||
id: release
|
||||
run: echo "timestamp=$(date -u +%Y%m%d%H%M%S)" >> "$GITHUB_OUTPUT"
|
||||
@@ -128,11 +150,6 @@ jobs:
|
||||
# literal, unresolved `${{ inputs.environment }}` text in the log.
|
||||
- name: Back up database
|
||||
if: ${{ inputs.run_db_backup }}
|
||||
env:
|
||||
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
||||
SSH_PASS: ${{ secrets.PI_MAIN_PASSWORD }}
|
||||
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
||||
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
||||
run: |
|
||||
echo "Environment: ${{ inputs.environment }}"
|
||||
rssh \
|
||||
@@ -148,11 +165,6 @@ jobs:
|
||||
# actions rely on (D-05). A plain scp command needs no nested container.
|
||||
# Same Gitea Actions limitation as the step above — static name, value logged via echo instead.
|
||||
- name: Upload release
|
||||
env:
|
||||
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
||||
SSH_PASS: ${{ secrets.PI_MAIN_PASSWORD }}
|
||||
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
||||
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
||||
run: |
|
||||
echo "Environment: ${{ inputs.environment }}, transport: ${{ inputs.transport }}"
|
||||
RELEASE_DIR="${{ inputs.deploy_path }}/releases/${{ steps.release.outputs.timestamp }}"
|
||||
@@ -160,7 +172,7 @@ jobs:
|
||||
"mkdir -p $RELEASE_DIR"
|
||||
rscp \
|
||||
-r ${{ inputs.artifact_name }}/* \
|
||||
"$SSH_USER@$SSH_HOST:$RELEASE_DIR/"
|
||||
"@REMOTE@:$RELEASE_DIR/"
|
||||
|
||||
# The customer's public website (wwwroot/web) must survive every CMS deploy (FR-08, ASM-01).
|
||||
# It lives outside the swapped release directory in a persistent shared/ folder, and is
|
||||
@@ -173,11 +185,6 @@ jobs:
|
||||
# source project has one with actual content, so a release built before any frontend content
|
||||
# exists can land with no wwwroot/ directory whatsoever, not merely an empty wwwroot/web/.
|
||||
- name: Link persistent website content
|
||||
env:
|
||||
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
||||
SSH_PASS: ${{ secrets.PI_MAIN_PASSWORD }}
|
||||
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
||||
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
||||
run: |
|
||||
RELEASE_DIR="${{ inputs.deploy_path }}/releases/${{ steps.release.outputs.timestamp }}"
|
||||
rssh \
|
||||
@@ -197,11 +204,6 @@ jobs:
|
||||
# `ls ... 2>/dev/null` piped to a `while read` (rather than a bare glob loop) keeps this
|
||||
# POSIX-sh safe and correct when shared/modules is empty, which is the common case today.
|
||||
- name: Link persistent modules
|
||||
env:
|
||||
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
||||
SSH_PASS: ${{ secrets.PI_MAIN_PASSWORD }}
|
||||
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
||||
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
||||
run: |
|
||||
RELEASE_DIR="${{ inputs.deploy_path }}/releases/${{ steps.release.outputs.timestamp }}"
|
||||
rssh \
|
||||
@@ -216,11 +218,6 @@ jobs:
|
||||
# directory. The process is then restarted so it picks up the new assemblies — a running .NET
|
||||
# process holds on to the ones it already loaded.
|
||||
- name: Switch current release and restart service
|
||||
env:
|
||||
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
||||
SSH_PASS: ${{ secrets.PI_MAIN_PASSWORD }}
|
||||
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
||||
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
||||
run: |
|
||||
RELEASE_DIR="${{ inputs.deploy_path }}/releases/${{ steps.release.outputs.timestamp }}"
|
||||
rssh \
|
||||
@@ -252,11 +249,6 @@ jobs:
|
||||
# a re-point-and-restart away without rebuilding. Only runs after a passing health check —
|
||||
# pruning after a failed check could leave the only other release as the sole survivor.
|
||||
- name: Prune old releases
|
||||
env:
|
||||
SSH_USER: ${{ secrets.PI_MAIN_USERNAME }}
|
||||
SSH_PASS: ${{ secrets.PI_MAIN_PASSWORD }}
|
||||
SSH_PORT: ${{ secrets.PI_MAIN_PORT }}
|
||||
SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }}
|
||||
run: |
|
||||
rssh \
|
||||
"cd ${{ inputs.deploy_path }}/releases && ls -1t | tail -n +3 | xargs -r rm -rf"
|
||||
|
||||
Reference in New Issue
Block a user