Pipeline: nieuwe Gitea-namen en deploy met SSH-sleutel (geen wachtwoord meer)
Continuous Integration / config (pull_request) Successful in 6s
Continuous Integration / prepare (pull_request) Successful in 29s
Continuous Integration / build-production (pull_request) Skipped
Continuous Integration / test (pull_request) Successful in 36s
Continuous Integration / build (pull_request) Successful in 44s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / lighthouse (pull_request) Successful in 2m16s
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / config (pull_request) Successful in 6s
Continuous Integration / prepare (pull_request) Successful in 29s
Continuous Integration / build-production (pull_request) Skipped
Continuous Integration / test (pull_request) Successful in 36s
Continuous Integration / build (pull_request) Successful in 44s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / lighthouse (pull_request) Successful in 2m16s
Continuous Integration / deploy-production (pull_request) Skipped
TEST_/PROD_-variabelen (DEPLOY_PATH, UMAMI, SENTRY) en TEST_HOST_*/PROD_HOST_* secrets. Wachtwoord-terugval (sshpass) verwijderd; StrictHostKeyChecking=accept-new. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,67 +25,42 @@ jobs:
|
||||
path: ${{ inputs.artifact_name }}
|
||||
|
||||
# Uploadt de inhoud van dist/ via SCP (over SSH) naar de webroot van de
|
||||
# test-omgeving (een Raspberry Pi achter een andere Raspberry Pi met
|
||||
# nginx reverse proxy - zie operations/deployment/nginx/ voor de
|
||||
# bijbehorende nginx-voorbeeldconfiguratie). Inloggegevens komen uit
|
||||
# Gitea Actions Secrets (wachtwoord-login voor nu; zie
|
||||
# deployment-instructions.md voor hoe je later naar een SSH-key omzet).
|
||||
# omgeving (een Raspberry Pi achter een andere Raspberry Pi met nginx
|
||||
# reverse proxy - zie operations/deployment/nginx/). Inloggen gaat met
|
||||
# een SSH-sleutel; de secrets heten per omgeving TEST_HOST_* en PROD_HOST_*
|
||||
# (naamgeving: aidlc-docs/_shared/gitea-naamgeving-variabelen.md).
|
||||
#
|
||||
# Let op: dit gebeurt via een gewone shell-stap in plaats van de
|
||||
# appleboy/scp-action Docker-container-action. Die laatste faalt op
|
||||
# deze runner met "failed to attach to container: unable to upgrade
|
||||
# to tcp, received 409" - een bekende beperking van Podman's
|
||||
# Docker-compatibele API, die het attach/log-streaming-mechanisme
|
||||
# voor containeracties niet volledig ondersteunt. Een scp-commando
|
||||
# in een normale run-stap heeft die geneste container niet nodig.
|
||||
# to tcp, received 409" (Podman). Een scp-commando in een normale run-stap
|
||||
# heeft die geneste container niet nodig.
|
||||
- name: Upload dist to ${{ inputs.environment }} web server via SCP
|
||||
env:
|
||||
# Secrets via env: in plaats van rechtstreeks in het `run:`-script
|
||||
# ge-interpoleerd: Gitea Actions plakt ${{ secrets.* }} als platte
|
||||
# tekst in het script vóórdat bash het uitvoert. Staat er een
|
||||
# shell-metateken in de waarde (zoals '$' of '`'), dan probeert
|
||||
# bash dat alsnog te interpreteren, waardoor een ander wachtwoord
|
||||
# bij sshpass terechtkomt dan verwacht ("Permission denied"). Via
|
||||
# env: krijgt bash de waarde als kant-en-klare string doorgegeven,
|
||||
# zonder die tweede interpretatieslag.
|
||||
SSHPASS: ${{ secrets.PI_MAIN_PASSWORD }}
|
||||
SSH_KEY: ${{ secrets.PI_MAIN_SSH_KEY }}
|
||||
PI_MAIN_PORT: ${{ secrets.PI_MAIN_PORT }}
|
||||
PI_MAIN_USERNAME: ${{ secrets.PI_MAIN_USERNAME }}
|
||||
PI_MAIN_ADDRESS: ${{ secrets.PI_MAIN_ADDRESS }}
|
||||
# Secrets via env: in plaats van in het script te interpoleren, zodat
|
||||
# shell-metatekens in een waarde niet alsnog worden uitgevoerd.
|
||||
HOST_SSH_KEY: ${{ inputs.environment == 'production' && secrets.PROD_HOST_SSH_KEY || secrets.TEST_HOST_SSH_KEY }}
|
||||
HOST_PORT: ${{ inputs.environment == 'production' && secrets.PROD_HOST_PORT || secrets.TEST_HOST_PORT }}
|
||||
HOST_USERNAME: ${{ inputs.environment == 'production' && secrets.PROD_HOST_USERNAME || secrets.TEST_HOST_USERNAME }}
|
||||
HOST_ADDRESS: ${{ inputs.environment == 'production' && secrets.PROD_HOST_ADDRESS || secrets.TEST_HOST_ADDRESS }}
|
||||
run: |
|
||||
# Runner-onafhankelijk: werkt op elke Linux-runner (Pi of pc, arm64 of x64, host of
|
||||
# container, met of zonder sudo). Tools worden alleen geinstalleerd als ze ontbreken.
|
||||
# Inloggen met de deploy-sleutel (secret PI_MAIN_SSH_KEY) werkt vanaf elk LAN-adres; het
|
||||
# wachtwoord (sshpass) is alleen nog een terugval en werkt op de Pi-server alleen vanaf
|
||||
# de Pi-runner zelf.
|
||||
# Runner-onafhankelijk: werkt op elke Linux-runner met scp. De tool wordt alleen
|
||||
# geinstalleerd als hij ontbreekt. Er is geen wachtwoord-terugval meer.
|
||||
SUDO=""
|
||||
if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1; then SUDO="sudo"; fi
|
||||
if ! command -v scp >/dev/null 2>&1 || { [ -z "$SSH_KEY" ] && ! command -v sshpass >/dev/null 2>&1; }; then
|
||||
$SUDO apt-get update && $SUDO apt-get install -y sshpass openssh-client
|
||||
if ! command -v scp >/dev/null 2>&1; then
|
||||
$SUDO apt-get update && $SUDO apt-get install -y openssh-client
|
||||
fi
|
||||
DONE=0
|
||||
if [ -n "$SSH_KEY" ]; then
|
||||
KEYFILE="$(mktemp)"
|
||||
trap 'rm -f "$KEYFILE"' EXIT
|
||||
printf '%s\n' "$SSH_KEY" > "$KEYFILE"
|
||||
chmod 600 "$KEYFILE"
|
||||
if scp \
|
||||
-P "$PI_MAIN_PORT" \
|
||||
-i "$KEYFILE" -o IdentitiesOnly=yes -o BatchMode=yes \
|
||||
-o StrictHostKeyChecking=no \
|
||||
-r ${{ inputs.artifact_name }}/* \
|
||||
"$PI_MAIN_USERNAME@$PI_MAIN_ADDRESS:${{ inputs.deploy_path }}"; then
|
||||
DONE=1
|
||||
else
|
||||
echo "Sleutel-login mislukt; terugval op wachtwoord (werkt alleen vanaf de Pi-runner)."
|
||||
fi
|
||||
fi
|
||||
if [ "$DONE" -eq 0 ]; then
|
||||
command -v sshpass >/dev/null 2>&1 || $SUDO apt-get install -y sshpass
|
||||
sshpass -e scp \
|
||||
-P "$PI_MAIN_PORT" \
|
||||
-o StrictHostKeyChecking=no \
|
||||
-r ${{ inputs.artifact_name }}/* \
|
||||
"$PI_MAIN_USERNAME@$PI_MAIN_ADDRESS:${{ inputs.deploy_path }}"
|
||||
if [ -z "$HOST_SSH_KEY" ]; then
|
||||
echo "SSH-sleutel ontbreekt (secret ${{ inputs.environment == 'production' && 'PROD_HOST_SSH_KEY' || 'TEST_HOST_SSH_KEY' }})"; exit 1
|
||||
fi
|
||||
KEYFILE="$(mktemp)"
|
||||
trap 'rm -f "$KEYFILE"' EXIT
|
||||
printf '%s\n' "$HOST_SSH_KEY" > "$KEYFILE"
|
||||
chmod 600 "$KEYFILE"
|
||||
scp \
|
||||
-P "$HOST_PORT" \
|
||||
-i "$KEYFILE" -o IdentitiesOnly=yes -o BatchMode=yes \
|
||||
-o StrictHostKeyChecking=accept-new \
|
||||
-r ${{ inputs.artifact_name }}/* \
|
||||
"$HOST_USERNAME@$HOST_ADDRESS:${{ inputs.deploy_path }}"
|
||||
|
||||
Reference in New Issue
Block a user