CI: deploy met SSH-sleutel (secret PI_MAIN_SSH_KEY), wachtwoord als terugval

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 14:56:25 +01:00
co-authored by Claude Sonnet 5.5
parent 32d04fe669
commit 548c7185aa
+30 -6
View File
@@ -49,19 +49,43 @@ jobs:
# 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 }}
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.
SUDO=""
if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1; then SUDO="sudo"; fi
if ! command -v sshpass >/dev/null 2>&1 || ! command -v scp >/dev/null 2>&1; then
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
fi
sshpass -e scp \
-P "$PI_MAIN_PORT" \
-o StrictHostKeyChecking=no \
-r ${{ inputs.artifact_name }}/* \
"$PI_MAIN_USERNAME@$PI_MAIN_ADDRESS:${{ inputs.deploy_path }}"
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 }}"
fi