Merge pull request 'Pipeline: nieuwe Gitea-namen en deploy met SSH-sleutel' (#22) from feature/gitea-namen into master
Continuous Integration / config (push) Successful in 8s
Continuous Integration / prepare (push) Successful in 27s
Continuous Integration / build-production (push) Skipped
Continuous Integration / build (push) Successful in 1m47s
Continuous Integration / test (push) Successful in 41s
Deploy / deploy (push) Successful in 24s
Continuous Integration / deploy-test (push) Successful in 26s
Continuous Integration / lighthouse (push) Successful in 2m19s
Continuous Integration / deploy-production (push) Skipped
Continuous Integration / config (push) Successful in 8s
Continuous Integration / prepare (push) Successful in 27s
Continuous Integration / build-production (push) Skipped
Continuous Integration / build (push) Successful in 1m47s
Continuous Integration / test (push) Successful in 41s
Deploy / deploy (push) Successful in 24s
Continuous Integration / deploy-test (push) Successful in 26s
Continuous Integration / lighthouse (push) Successful in 2m19s
Continuous Integration / deploy-production (push) Skipped
This commit was merged in pull request #22.
This commit is contained in:
@@ -50,9 +50,9 @@ env:
|
|||||||
# (Repository → Settings → Actions → Variables), zodat het pad per omgeving
|
# (Repository → Settings → Actions → Variables), zodat het pad per omgeving
|
||||||
# aangepast kan worden zonder de workflow zelf te wijzigen. Zie
|
# aangepast kan worden zonder de workflow zelf te wijzigen. Zie
|
||||||
# deployment-instructions.md voor de eenmalige setup van deze variable.
|
# deployment-instructions.md voor de eenmalige setup van deze variable.
|
||||||
DEPLOY_PATH: ${{ vars.DEPLOY_PATH_TEST }}
|
DEPLOY_PATH: ${{ vars.TEST_DEPLOY_PATH }}
|
||||||
DEPLOY_ENVIRONMENT_PRODUCTION: production
|
DEPLOY_ENVIRONMENT_PRODUCTION: production
|
||||||
DEPLOY_PATH_PRODUCTION: ${{ vars.DEPLOY_PATH_PRODUCTION }}
|
DEPLOY_PATH_PRODUCTION: ${{ vars.PROD_DEPLOY_PATH }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Geeft de env-variabelen hierboven door als job-outputs, zodat ze ook
|
# Geeft de env-variabelen hierboven door als job-outputs, zodat ze ook
|
||||||
@@ -133,18 +133,17 @@ jobs:
|
|||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
env:
|
env:
|
||||||
VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }}
|
VITE_UMAMI_SCRIPT_URL: ${{ vars.TEST_UMAMI_SCRIPT_URL }}
|
||||||
# Gitea-variable heet VITE_UMAMI_WEBSITE_ID_TEST (niet zonder suffix),
|
# Gitea-variable heet TEST_UMAMI_WEBSITE_ID (PROD_UMAMI_WEBSITE_ID in de
|
||||||
# analoog aan VITE_UMAMI_WEBSITE_ID_PRODUCTION in de build-production
|
# build-production job hieronder). Linkerkant (VITE_UMAMI_WEBSITE_ID) is wél altijd
|
||||||
# job hieronder. Linkerkant (VITE_UMAMI_WEBSITE_ID) is wél altijd
|
|
||||||
# gelijk: dat is de Vite-buildtime-envvar-naam die de app verwacht
|
# gelijk: dat is de Vite-buildtime-envvar-naam die de app verwacht
|
||||||
# (zie src/components/UmamiAnalytics.tsx), niet aan te passen.
|
# (zie src/components/UmamiAnalytics.tsx), niet aan te passen.
|
||||||
VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_TEST }}
|
VITE_UMAMI_WEBSITE_ID: ${{ vars.TEST_UMAMI_WEBSITE_ID }}
|
||||||
# Sentry DSN is niet gevoelig (veilig om in de client-bundle te zitten),
|
# Sentry DSN is niet gevoelig (veilig om in de client-bundle te zitten),
|
||||||
# daarom een Gitea Actions "vars"-waarde i.p.v. een secret. Optioneel:
|
# daarom een Gitea Actions "vars"-waarde i.p.v. een secret. Optioneel:
|
||||||
# als deze niet is ingesteld, wordt Sentry-logging simpelweg overgeslagen
|
# als deze niet is ingesteld, wordt Sentry-logging simpelweg overgeslagen
|
||||||
# (zie src/main.tsx) en blijft alleen console-logging actief.
|
# (zie src/main.tsx) en blijft alleen console-logging actief.
|
||||||
VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }}
|
VITE_SENTRY_DSN: ${{ vars.TEST_SENTRY_DSN }}
|
||||||
# Build-time tag die de Sentry environment (test vs. production) bepaalt;
|
# Build-time tag die de Sentry environment (test vs. production) bepaalt;
|
||||||
# zie src/main.tsx. De SentryTestButton zelf is hier los van: die is
|
# zie src/main.tsx. De SentryTestButton zelf is hier los van: die is
|
||||||
# uitsluitend zichtbaar bij `pnpm dev`, in geen enkele build (zie
|
# uitsluitend zichtbaar bij `pnpm dev`, in geen enkele build (zie
|
||||||
@@ -203,14 +202,14 @@ jobs:
|
|||||||
# "website"-entry (test.slpsoftware.nl vs slpsoftware.nl) heeft een
|
# "website"-entry (test.slpsoftware.nl vs slpsoftware.nl) heeft een
|
||||||
# eigen ID, anders komt productieverkeer in de teststatistieken
|
# eigen ID, anders komt productieverkeer in de teststatistieken
|
||||||
# terecht (of andersom). Vereist dus een eigen Umami-website +
|
# terecht (of andersom). Vereist dus een eigen Umami-website +
|
||||||
# Gitea-variable VITE_UMAMI_WEBSITE_ID_PRODUCTION — zie umami-setup.md.
|
# Gitea-variable PROD_UMAMI_WEBSITE_ID — zie umami-setup.md.
|
||||||
VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }}
|
VITE_UMAMI_SCRIPT_URL: ${{ vars.PROD_UMAMI_SCRIPT_URL }}
|
||||||
VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_PRODUCTION }}
|
VITE_UMAMI_WEBSITE_ID: ${{ vars.PROD_UMAMI_WEBSITE_ID }}
|
||||||
# VITE_SENTRY_DSN wordt wél gedeeld met de testbuild: één Sentry-
|
# TEST_SENTRY_DSN en PROD_SENTRY_DSN hebben dezelfde waarde: één Sentry-
|
||||||
# project voor beide omgevingen, VITE_APP_ENV hieronder tagt de
|
# project voor beide omgevingen, VITE_APP_ENV hieronder tagt de
|
||||||
# events al als 'test' vs 'production'. Splits dit pas op als je
|
# events al als 'test' vs 'production'. Splits dit pas op als je
|
||||||
# ooit aparte Sentry-projecten per omgeving wilt.
|
# ooit aparte Sentry-projecten per omgeving wilt.
|
||||||
VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }}
|
VITE_SENTRY_DSN: ${{ vars.PROD_SENTRY_DSN }}
|
||||||
VITE_APP_ENV: ${{ env.DEPLOY_ENVIRONMENT_PRODUCTION }}
|
VITE_APP_ENV: ${{ env.DEPLOY_ENVIRONMENT_PRODUCTION }}
|
||||||
run: pnpm run build
|
run: pnpm run build
|
||||||
|
|
||||||
|
|||||||
@@ -25,67 +25,42 @@ jobs:
|
|||||||
path: ${{ inputs.artifact_name }}
|
path: ${{ inputs.artifact_name }}
|
||||||
|
|
||||||
# Uploadt de inhoud van dist/ via SCP (over SSH) naar de webroot van de
|
# 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
|
# omgeving (een Raspberry Pi achter een andere Raspberry Pi met nginx
|
||||||
# nginx reverse proxy - zie operations/deployment/nginx/ voor de
|
# reverse proxy - zie operations/deployment/nginx/). Inloggen gaat met
|
||||||
# bijbehorende nginx-voorbeeldconfiguratie). Inloggegevens komen uit
|
# een SSH-sleutel; de secrets heten per omgeving TEST_HOST_* en PROD_HOST_*
|
||||||
# Gitea Actions Secrets (wachtwoord-login voor nu; zie
|
# (naamgeving: aidlc-docs/_shared/gitea-naamgeving-variabelen.md).
|
||||||
# deployment-instructions.md voor hoe je later naar een SSH-key omzet).
|
|
||||||
#
|
#
|
||||||
# Let op: dit gebeurt via een gewone shell-stap in plaats van de
|
# Let op: dit gebeurt via een gewone shell-stap in plaats van de
|
||||||
# appleboy/scp-action Docker-container-action. Die laatste faalt op
|
# appleboy/scp-action Docker-container-action. Die laatste faalt op
|
||||||
# deze runner met "failed to attach to container: unable to upgrade
|
# deze runner met "failed to attach to container: unable to upgrade
|
||||||
# to tcp, received 409" - een bekende beperking van Podman's
|
# to tcp, received 409" (Podman). Een scp-commando in een normale run-stap
|
||||||
# Docker-compatibele API, die het attach/log-streaming-mechanisme
|
# heeft die geneste container niet nodig.
|
||||||
# voor containeracties niet volledig ondersteunt. Een scp-commando
|
|
||||||
# in een normale run-stap heeft die geneste container niet nodig.
|
|
||||||
- name: Upload dist to ${{ inputs.environment }} web server via SCP
|
- name: Upload dist to ${{ inputs.environment }} web server via SCP
|
||||||
env:
|
env:
|
||||||
# Secrets via env: in plaats van rechtstreeks in het `run:`-script
|
# Secrets via env: in plaats van in het script te interpoleren, zodat
|
||||||
# ge-interpoleerd: Gitea Actions plakt ${{ secrets.* }} als platte
|
# shell-metatekens in een waarde niet alsnog worden uitgevoerd.
|
||||||
# tekst in het script vóórdat bash het uitvoert. Staat er een
|
HOST_SSH_KEY: ${{ inputs.environment == 'production' && secrets.PROD_HOST_SSH_KEY || secrets.TEST_HOST_SSH_KEY }}
|
||||||
# shell-metateken in de waarde (zoals '$' of '`'), dan probeert
|
HOST_PORT: ${{ inputs.environment == 'production' && secrets.PROD_HOST_PORT || secrets.TEST_HOST_PORT }}
|
||||||
# bash dat alsnog te interpreteren, waardoor een ander wachtwoord
|
HOST_USERNAME: ${{ inputs.environment == 'production' && secrets.PROD_HOST_USERNAME || secrets.TEST_HOST_USERNAME }}
|
||||||
# bij sshpass terechtkomt dan verwacht ("Permission denied"). Via
|
HOST_ADDRESS: ${{ inputs.environment == 'production' && secrets.PROD_HOST_ADDRESS || secrets.TEST_HOST_ADDRESS }}
|
||||||
# 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: |
|
run: |
|
||||||
# Runner-onafhankelijk: werkt op elke Linux-runner (Pi of pc, arm64 of x64, host of
|
# Runner-onafhankelijk: werkt op elke Linux-runner met scp. De tool wordt alleen
|
||||||
# container, met of zonder sudo). Tools worden alleen geinstalleerd als ze ontbreken.
|
# geinstalleerd als hij ontbreekt. Er is geen wachtwoord-terugval meer.
|
||||||
# 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=""
|
SUDO=""
|
||||||
if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1; then SUDO="sudo"; fi
|
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
|
if ! command -v scp >/dev/null 2>&1; then
|
||||||
$SUDO apt-get update && $SUDO apt-get install -y sshpass openssh-client
|
$SUDO apt-get update && $SUDO apt-get install -y openssh-client
|
||||||
|
fi
|
||||||
|
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
|
fi
|
||||||
DONE=0
|
|
||||||
if [ -n "$SSH_KEY" ]; then
|
|
||||||
KEYFILE="$(mktemp)"
|
KEYFILE="$(mktemp)"
|
||||||
trap 'rm -f "$KEYFILE"' EXIT
|
trap 'rm -f "$KEYFILE"' EXIT
|
||||||
printf '%s\n' "$SSH_KEY" > "$KEYFILE"
|
printf '%s\n' "$HOST_SSH_KEY" > "$KEYFILE"
|
||||||
chmod 600 "$KEYFILE"
|
chmod 600 "$KEYFILE"
|
||||||
if scp \
|
scp \
|
||||||
-P "$PI_MAIN_PORT" \
|
-P "$HOST_PORT" \
|
||||||
-i "$KEYFILE" -o IdentitiesOnly=yes -o BatchMode=yes \
|
-i "$KEYFILE" -o IdentitiesOnly=yes -o BatchMode=yes \
|
||||||
-o StrictHostKeyChecking=no \
|
-o StrictHostKeyChecking=accept-new \
|
||||||
-r ${{ inputs.artifact_name }}/* \
|
-r ${{ inputs.artifact_name }}/* \
|
||||||
"$PI_MAIN_USERNAME@$PI_MAIN_ADDRESS:${{ inputs.deploy_path }}"; then
|
"$HOST_USERNAME@$HOST_ADDRESS:${{ inputs.deploy_path }}"
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user