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:
@@ -42,12 +42,12 @@ env:
|
||||
ARTIFACT_NAME_SLS_PRODUCTION: app-sls-production
|
||||
DEPLOY_ENVIRONMENT_SLS_TEST: test
|
||||
DEPLOY_ENVIRONMENT_SLS_PRODUCTION: production
|
||||
DEPLOY_PATH_TEST: ${{ vars.DEPLOY_PATH_TEST }}
|
||||
DEPLOY_PATH_PRODUCTION: ${{ vars.DEPLOY_PATH_PRODUCTION }}
|
||||
SERVICE_NAME_TEST: ${{ vars.SERVICE_NAME_TEST }}
|
||||
SERVICE_NAME_PRODUCTION: ${{ vars.SERVICE_NAME_PRODUCTION }}
|
||||
HEALTH_CHECK_URL_TEST: ${{ vars.HEALTH_CHECK_URL_TEST }}
|
||||
HEALTH_CHECK_URL_PRODUCTION: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }}
|
||||
DEPLOY_PATH_TEST: ${{ vars.SLS_TEST_DEPLOY_PATH }}
|
||||
DEPLOY_PATH_PRODUCTION: ${{ vars.SLS_PROD_DEPLOY_PATH }}
|
||||
SERVICE_NAME_TEST: ${{ vars.SLS_TEST_SERVICE_NAME }}
|
||||
SERVICE_NAME_PRODUCTION: ${{ vars.SLS_PROD_SERVICE_NAME }}
|
||||
HEALTH_CHECK_URL_TEST: ${{ vars.SLS_TEST_HEALTH_URL }}
|
||||
HEALTH_CHECK_URL_PRODUCTION: ${{ vars.SLS_PROD_HEALTH_URL }}
|
||||
|
||||
jobs:
|
||||
# Passes the env: values above through as job outputs, since the env context is unavailable in
|
||||
@@ -78,16 +78,16 @@ jobs:
|
||||
# step-level env works on both runners. The test trio must be set, otherwise fail here instead of in the deploy.
|
||||
- id: set
|
||||
env:
|
||||
DEPLOY_PATH_TEST: ${{ vars.DEPLOY_PATH_TEST }}
|
||||
DEPLOY_PATH_PRODUCTION: ${{ vars.DEPLOY_PATH_PRODUCTION }}
|
||||
SERVICE_NAME_TEST: ${{ vars.SERVICE_NAME_TEST }}
|
||||
SERVICE_NAME_PRODUCTION: ${{ vars.SERVICE_NAME_PRODUCTION }}
|
||||
HEALTH_CHECK_URL_TEST: ${{ vars.HEALTH_CHECK_URL_TEST }}
|
||||
HEALTH_CHECK_URL_PRODUCTION: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }}
|
||||
DEPLOY_PATH_TEST: ${{ vars.SLS_TEST_DEPLOY_PATH }}
|
||||
DEPLOY_PATH_PRODUCTION: ${{ vars.SLS_PROD_DEPLOY_PATH }}
|
||||
SERVICE_NAME_TEST: ${{ vars.SLS_TEST_SERVICE_NAME }}
|
||||
SERVICE_NAME_PRODUCTION: ${{ vars.SLS_PROD_SERVICE_NAME }}
|
||||
HEALTH_CHECK_URL_TEST: ${{ vars.SLS_TEST_HEALTH_URL }}
|
||||
HEALTH_CHECK_URL_PRODUCTION: ${{ vars.SLS_PROD_HEALTH_URL }}
|
||||
run: |
|
||||
for v in DEPLOY_PATH_TEST SERVICE_NAME_TEST HEALTH_CHECK_URL_TEST; do
|
||||
if [ -z "${!v}" ]; then
|
||||
echo "The Gitea variable $v is empty or not set on this runner; the deploy would use an empty path."
|
||||
echo "The value for $v (a SLS_TEST_* Gitea variable) is empty or not set on this runner; the deploy would use an empty path."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
@@ -418,11 +418,11 @@ jobs:
|
||||
version: ${{ env.PNPM_VERSION }}
|
||||
|
||||
- name: Verify Umami origin is permitted (REF-U5-01)
|
||||
if: ${{ vars.VITE_UMAMI_SCRIPT_URL != '' }}
|
||||
if: ${{ vars.SLS_TEST_UMAMI_SCRIPT_URL != '' }}
|
||||
run: |
|
||||
ORIGIN=$(echo "${{ vars.VITE_UMAMI_SCRIPT_URL }}" | sed -E 's#^(https?://[^/]+).*#\1#')
|
||||
if ! echo ",${{ vars.SECURITY_ALLOWED_SCRIPT_ORIGINS_TEST }}," | grep -qF ",$ORIGIN,"; then
|
||||
echo "Umami origin '$ORIGIN' is not present in the SECURITY_ALLOWED_SCRIPT_ORIGINS_TEST Gitea variable."
|
||||
ORIGIN=$(echo "${{ vars.SLS_TEST_UMAMI_SCRIPT_URL }}" | sed -E 's#^(https?://[^/]+).*#\1#')
|
||||
if ! echo ",${{ vars.SLS_TEST_SECURITY_ALLOWED_SCRIPT_ORIGINS }}," | grep -qF ",$ORIGIN,"; then
|
||||
echo "Umami origin '$ORIGIN' is not present in the SLS_TEST_SECURITY_ALLOWED_SCRIPT_ORIGINS Gitea variable."
|
||||
echo "Fix the variable, or the test environment's SecurityHeaders CSP config it must mirror (D-16)."
|
||||
exit 1
|
||||
fi
|
||||
@@ -441,9 +441,9 @@ jobs:
|
||||
VITE_APP_ENV: test
|
||||
VITE_APP_TITLE: SLP Software
|
||||
VITE_THEME: slpsoftware
|
||||
VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }}
|
||||
VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_TEST }}
|
||||
VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }}
|
||||
VITE_UMAMI_SCRIPT_URL: ${{ vars.SLS_TEST_UMAMI_SCRIPT_URL }}
|
||||
VITE_UMAMI_WEBSITE_ID: ${{ vars.SLS_TEST_UMAMI_WEBSITE_ID }}
|
||||
VITE_SENTRY_DSN: ${{ vars.SLS_TEST_SENTRY_DSN }}
|
||||
run: |
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm build
|
||||
@@ -496,11 +496,11 @@ jobs:
|
||||
version: ${{ env.PNPM_VERSION }}
|
||||
|
||||
- name: Verify Umami origin is permitted (REF-U5-01)
|
||||
if: ${{ vars.VITE_UMAMI_SCRIPT_URL != '' }}
|
||||
if: ${{ vars.SLS_PROD_UMAMI_SCRIPT_URL != '' }}
|
||||
run: |
|
||||
ORIGIN=$(echo "${{ vars.VITE_UMAMI_SCRIPT_URL }}" | sed -E 's#^(https?://[^/]+).*#\1#')
|
||||
if ! echo ",${{ vars.SECURITY_ALLOWED_SCRIPT_ORIGINS_PRODUCTION }}," | grep -qF ",$ORIGIN,"; then
|
||||
echo "Umami origin '$ORIGIN' is not present in the SECURITY_ALLOWED_SCRIPT_ORIGINS_PRODUCTION Gitea variable."
|
||||
ORIGIN=$(echo "${{ vars.SLS_PROD_UMAMI_SCRIPT_URL }}" | sed -E 's#^(https?://[^/]+).*#\1#')
|
||||
if ! echo ",${{ vars.SLS_PROD_SECURITY_ALLOWED_SCRIPT_ORIGINS }}," | grep -qF ",$ORIGIN,"; then
|
||||
echo "Umami origin '$ORIGIN' is not present in the SLS_PROD_SECURITY_ALLOWED_SCRIPT_ORIGINS Gitea variable."
|
||||
echo "Fix the variable, or the production environment's SecurityHeaders CSP config it must mirror (D-16)."
|
||||
exit 1
|
||||
fi
|
||||
@@ -513,9 +513,9 @@ jobs:
|
||||
VITE_APP_ENV: production
|
||||
VITE_APP_TITLE: SLP Software
|
||||
VITE_THEME: slpsoftware
|
||||
VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }}
|
||||
VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_PRODUCTION }}
|
||||
VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }}
|
||||
VITE_UMAMI_SCRIPT_URL: ${{ vars.SLS_PROD_UMAMI_SCRIPT_URL }}
|
||||
VITE_UMAMI_WEBSITE_ID: ${{ vars.SLS_PROD_UMAMI_WEBSITE_ID }}
|
||||
VITE_SENTRY_DSN: ${{ vars.SLS_PROD_SENTRY_DSN }}
|
||||
run: |
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm build
|
||||
@@ -549,11 +549,12 @@ jobs:
|
||||
uses: ./.gitea/workflows/deploy-scp.yaml
|
||||
secrets: inherit
|
||||
with:
|
||||
host: SLS_TEST
|
||||
artifact_name: ${{ needs.config-sls.outputs.artifact_name_sls_test }}
|
||||
environment: ${{ needs.config-sls.outputs.deploy_environment_sls_test }}
|
||||
deploy_path: ${{ vars.DEPLOY_PATH_TEST }}
|
||||
service_name: ${{ vars.SERVICE_NAME_TEST }}
|
||||
health_check_url: ${{ vars.HEALTH_CHECK_URL_TEST }}
|
||||
deploy_path: ${{ vars.SLS_TEST_DEPLOY_PATH }}
|
||||
service_name: ${{ vars.SLS_TEST_SERVICE_NAME }}
|
||||
health_check_url: ${{ vars.SLS_TEST_HEALTH_URL }}
|
||||
run_db_backup: false
|
||||
|
||||
# Production deploy ONLY on an explicit workflow_dispatch run with deploy_sls_production checked, and
|
||||
@@ -566,11 +567,12 @@ jobs:
|
||||
uses: ./.gitea/workflows/deploy-scp.yaml
|
||||
secrets: inherit
|
||||
with:
|
||||
host: SLS_PROD
|
||||
artifact_name: ${{ needs.config-sls.outputs.artifact_name_sls_production }}
|
||||
environment: ${{ needs.config-sls.outputs.deploy_environment_sls_production }}
|
||||
deploy_path: ${{ vars.DEPLOY_PATH_PRODUCTION }}
|
||||
service_name: ${{ vars.SERVICE_NAME_PRODUCTION }}
|
||||
health_check_url: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }}
|
||||
deploy_path: ${{ vars.SLS_PROD_DEPLOY_PATH }}
|
||||
service_name: ${{ vars.SLS_PROD_SERVICE_NAME }}
|
||||
health_check_url: ${{ vars.SLS_PROD_HEALTH_URL }}
|
||||
run_db_backup: true
|
||||
|
||||
# ==========================================================================================
|
||||
@@ -578,15 +580,12 @@ jobs:
|
||||
# SlpSoftware jobs, the env block, deploy-scp.yaml) is changed, a failure here never blocks the
|
||||
# SlpSoftware deploy and vice versa.
|
||||
#
|
||||
# Everything below is switched on by ONE Gitea variable, ASF_TEST_DEPLOY_ENABLED == 'true'.
|
||||
# While it is unset (or anything else) all three jobs are skipped and the pipeline behaves
|
||||
# exactly as before. Secrets cannot be tested in an `if:`, hence an explicit variable; it is set
|
||||
# only after the Pi and the other ASF_* variables exist.
|
||||
# No switch: the ASF test deploy runs like the SlpSoftware one. The Gitea variables ASF_TEST_DEPLOY_PATH,
|
||||
# ASF_TEST_SERVICE_NAME and ASF_TEST_HEALTH_URL and the secrets ASF_TEST_HOST_* must exist; config-asf fails clearly if not.
|
||||
# Runs: on every push to master (like the SlpSoftware test deploy) or manually with the
|
||||
# "Deploy ASF test" box ticked. Test only: there is no production path for ASF.
|
||||
# ==========================================================================================
|
||||
config-asf:
|
||||
if: ${{ vars.ASF_TEST_DEPLOY_ENABLED == 'true' }}
|
||||
runs-on: linux
|
||||
outputs:
|
||||
deploy_path: ${{ steps.set.outputs.deploy_path }}
|
||||
@@ -595,13 +594,13 @@ jobs:
|
||||
steps:
|
||||
- id: set
|
||||
env:
|
||||
DEPLOY_PATH: ${{ vars.DEPLOY_PATH_ASF_TEST }}
|
||||
SERVICE_NAME: ${{ vars.SERVICE_NAME_ASF_TEST }}
|
||||
HEALTH_CHECK_URL: ${{ vars.HEALTH_CHECK_URL_ASF_TEST }}
|
||||
DEPLOY_PATH: ${{ vars.ASF_TEST_DEPLOY_PATH }}
|
||||
SERVICE_NAME: ${{ vars.ASF_TEST_SERVICE_NAME }}
|
||||
HEALTH_CHECK_URL: ${{ vars.ASF_TEST_HEALTH_URL }}
|
||||
run: |
|
||||
for v in DEPLOY_PATH SERVICE_NAME HEALTH_CHECK_URL; do
|
||||
if [ -z "${!v}" ]; then
|
||||
echo "The Gitea variable for $v (…_ASF_TEST) is not set; set it or switch ASF_TEST_DEPLOY_ENABLED off."
|
||||
echo "The Gitea variable for $v (ASF_TEST_*) is not set."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
@@ -612,10 +611,9 @@ jobs:
|
||||
publish-asf-test:
|
||||
needs: [changes, backend-build, backend-test, vulnerability-scan, frontend-build, frontend-test, frontend-lint]
|
||||
# Same gate handling as publish-sls-test (see there for why always() and explicit results), plus the
|
||||
# ASF switch, and built only when it will actually be deployed.
|
||||
# fact that it is built only when it will actually be deployed.
|
||||
if: |
|
||||
always() &&
|
||||
vars.ASF_TEST_DEPLOY_ENABLED == 'true' &&
|
||||
needs.changes.result == 'success' &&
|
||||
needs.backend-build.result != 'failure' && needs.backend-build.result != 'cancelled' &&
|
||||
needs.backend-test.result != 'failure' && needs.backend-test.result != 'cancelled' &&
|
||||
@@ -648,7 +646,7 @@ jobs:
|
||||
VITE_APP_TITLE: Andrea Slop Fotografie
|
||||
VITE_THEME: asf
|
||||
VITE_DEFAULT_LANGUAGE: nl
|
||||
VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN_ASF }}
|
||||
VITE_SENTRY_DSN: ${{ vars.ASF_TEST_SENTRY_DSN }}
|
||||
run: |
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm build
|
||||
@@ -672,15 +670,16 @@ jobs:
|
||||
# here the deploy account name in the path, arrives empty). config-asf still validates that they are set.
|
||||
deploy-asf-test:
|
||||
needs: [publish-asf-test, config-asf]
|
||||
if: vars.ASF_TEST_DEPLOY_ENABLED == 'true' && ((github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_asf_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master'))
|
||||
if: ((github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_asf_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master'))
|
||||
uses: ./.gitea/workflows/deploy-scp.yaml
|
||||
secrets: inherit
|
||||
with:
|
||||
host: ASF_TEST
|
||||
artifact_name: app-asf-test
|
||||
environment: test
|
||||
deploy_path: ${{ vars.DEPLOY_PATH_ASF_TEST }}
|
||||
service_name: ${{ vars.SERVICE_NAME_ASF_TEST }}
|
||||
health_check_url: ${{ vars.HEALTH_CHECK_URL_ASF_TEST }}
|
||||
deploy_path: ${{ vars.ASF_TEST_DEPLOY_PATH }}
|
||||
service_name: ${{ vars.ASF_TEST_SERVICE_NAME }}
|
||||
health_check_url: ${{ vars.ASF_TEST_HEALTH_URL }}
|
||||
run_db_backup: false
|
||||
|
||||
# --- Smoke tests of the deployed compositions (anonymous requests, see scripts/smoke-site.sh) ---
|
||||
@@ -694,7 +693,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Smoke test SLS test
|
||||
env:
|
||||
HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_TEST }}
|
||||
HEALTH_URL: ${{ vars.SLS_TEST_HEALTH_URL }}
|
||||
run: bash scripts/smoke-site.sh "$HEALTH_URL" sls-test
|
||||
|
||||
smoke-asf-test:
|
||||
@@ -705,5 +704,5 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Smoke test ASF test
|
||||
env:
|
||||
HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_ASF_TEST }}
|
||||
HEALTH_URL: ${{ vars.ASF_TEST_HEALTH_URL }}
|
||||
run: bash scripts/smoke-site.sh "$HEALTH_URL" asf-test
|
||||
|
||||
@@ -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