Continuous Integration / check (pull_request) Successful in 2m9s
Continuous Integration / build-test (pull_request) Skipped
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / lighthouse (pull_request) Successful in 9m9s
Continuous Integration / deploy-production (pull_request) Skipped
The hosting partner offers FTP over TLS after all. upload-production.sh now forces AUTH TLS (ssl-force, protect-data, protect-list), verifies the certificate and stays passive; the three rounds and the folder restrictions are unchanged. Docs, workflow comments and the lftp tests follow. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
99 lines
4.0 KiB
Bash
99 lines
4.0 KiB
Bash
#!/usr/bin/env bash
|
|
# Upload naar productie in drie rondes (BR-HST-14, 15; FR-PR-18).
|
|
# Gebruik: upload-production.sh <dist-map> <doelmap-op-de-server>
|
|
# De doelmap is de map met voorgerenderde pagina's van de CMS-host; de host
|
|
# (en zijn web.config) staat er los van en wordt door de CMS-pijplijn gedeployd.
|
|
# Verbinding: FTP_HOST, FTP_USER en LFTP_PASSWORD uit de omgeving, optioneel
|
|
# FTP_PORT. Alleen FTP over TLS (FTPS, explicit: AUTH TLS): de inlog en de
|
|
# bestanden gaan versleuteld, zonder terugval naar gewone FTP, en het
|
|
# certificaat van de server wordt gecontroleerd (zie docs/deploy-and-ci.md,
|
|
# "FTPS to production"). Gebruik een eigen FTP-account met rechten alleen op
|
|
# deze map.
|
|
# Alleen voor de test: LFTP_OPEN (bijvoorbeeld file:///) vervangt de
|
|
# verbinding, en UPLOAD_PASS=1|2|3 voert maar één ronde uit.
|
|
set -euo pipefail
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "Gebruik: $0 <dist-map> <doelmap>" >&2
|
|
exit 2
|
|
fi
|
|
dist="${1%/}"
|
|
remote="${2%/}"
|
|
|
|
# De paden komen in een lftp-opdracht; daarom geen spaties of quotes. Ook geen
|
|
# '.' of '..' (ronde 3 verwijdert: '.' is de FTP-thuismap, '..' de map erboven),
|
|
# geen lege segmenten en niets dat met '-' begint (zou een optie worden).
|
|
safe='^[A-Za-z0-9._/-]+$'
|
|
valid_path() {
|
|
local value="$1" segment
|
|
[[ "$value" =~ $safe ]] || return 1
|
|
[[ "$value" != -* ]] || return 1
|
|
[[ "$value" != *//* ]] || return 1
|
|
local IFS=/
|
|
for segment in ${value#/}; do
|
|
case "$segment" in . | ..) return 1 ;; esac
|
|
done
|
|
}
|
|
for value in "$dist" "$remote"; do
|
|
if ! valid_path "$value"; then
|
|
echo "Ongeldig pad: '$value'" >&2
|
|
exit 2
|
|
fi
|
|
done
|
|
|
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
bash "$here/check-artifact.sh" "$dist"
|
|
|
|
pass="${UPLOAD_PASS:-all}"
|
|
case "$pass" in
|
|
all | 1 | 2 | 3) ;;
|
|
*) echo "Ongeldige UPLOAD_PASS: '$pass'" >&2; exit 2 ;;
|
|
esac
|
|
wants() { [ "$pass" = all ] || [ "$pass" = "$1" ]; }
|
|
|
|
# Geen back-ups: lftp zet standaard een kopie met een tijdstempel
|
|
# (web.config~20261101221045~) naast elk bestand dat het overschrijft. Op de
|
|
# host zou elke deploy er een achterlaten, bereikbaar voor wie de naam raadt.
|
|
# TLS: explicit FTPS afdwingen (de sessie weigert inloggen zonder TLS, ook de
|
|
# datakanalen en de lijsten zijn versleuteld) en het certificaat controleren.
|
|
tls="set ftp:ssl-allow yes; set ftp:ssl-auth TLS; set ftp:ssl-force yes; set ftp:ssl-protect-data yes; set ftp:ssl-protect-list yes; set ssl:verify-certificate yes;"
|
|
settings="$tls set ftp:passive-mode on; set net:max-retries 3; set xfer:make-backup no;"
|
|
|
|
# Elke opdracht krijgt een eigen lftp-sessie, zodat het script bij een mislukte
|
|
# ronde stopt (set -e) voordat de volgende ronde begint: de HTML gaat nooit
|
|
# omhoog na een mislukte asset-ronde (FR-PR-18).
|
|
run_lftp() {
|
|
local commands="$settings $1 quit"
|
|
if [ -n "${LFTP_OPEN:-}" ]; then
|
|
lftp -e "$commands" "$LFTP_OPEN"
|
|
else
|
|
: "${FTP_HOST:?FTP_HOST ontbreekt}" "${FTP_USER:?FTP_USER ontbreekt}"
|
|
: "${LFTP_PASSWORD:?LFTP_PASSWORD ontbreekt}"
|
|
local port=()
|
|
if [ -n "${FTP_PORT:-}" ]; then
|
|
[[ "$FTP_PORT" =~ ^[0-9]+$ ]] || { echo "Ongeldige FTP_PORT" >&2; exit 2; }
|
|
port=(-p "$FTP_PORT")
|
|
fi
|
|
lftp --env-password -u "$FTP_USER" "${port[@]}" "ftp://$FTP_HOST" -e "$commands"
|
|
fi
|
|
}
|
|
|
|
# Ronde 1: alles behalve HTML, dus ook /assets. Nieuwe bestanden met hash in
|
|
# de naam storen de oude release niet.
|
|
if wants 1; then
|
|
echo "== Ronde 1: alles behalve HTML"
|
|
run_lftp "mirror --reverse --verbose --exclude-glob '*.html' $dist/ $remote/;"
|
|
fi
|
|
# Ronde 2: alle HTML, ook de geneste pagina's en 404.html. Pas nu verwijst
|
|
# iets naar de nieuwe assets.
|
|
if wants 2; then
|
|
echo "== Ronde 2: alle HTML"
|
|
run_lftp "mirror --reverse --verbose --include-glob '*.html' $dist/ $remote/;"
|
|
fi
|
|
# Ronde 3: opruimen als laatste, zodat bezoekers met de oude HTML hun oude
|
|
# assets nog vinden tot de nieuwe HTML helemaal staat.
|
|
if wants 3; then
|
|
echo "== Ronde 3: oude bestanden opruimen"
|
|
run_lftp "mirror --reverse --delete --verbose $dist/ $remote/;"
|
|
fi
|