CI: ASF-productie win-x64 publish (alleen dispatch) en uitgeschakelde FTPS-upload naar IIS
publish-asf-production: self-contained win-x64, web.config-sjabloon, artefactcontrole, artefact 30 dagen. deploy-asf-production: drie sloten (dispatch-input, release/*, ASF_PROD_DEPLOY_ENABLED), expliciete FTPS, app_offline.htm, geen delete behalve wwwroot/admin, nooit appsettings.Production.json/uploads/logs/wwwroot/web. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
# Guard for the ASF production publish output (win-x64, IIS). Fails (exit 1) when the directory
|
||||
# contains something that must NEVER be in the artifact or misses something a working IIS host needs.
|
||||
#
|
||||
# Usage: scripts/check-asf-publish.sh <publish-dir>
|
||||
set -u
|
||||
|
||||
dir="${1:-}"
|
||||
[ -n "$dir" ] && [ -d "$dir" ] || { echo "Usage: $0 <publish-dir>" >&2; exit 2; }
|
||||
|
||||
fail=0
|
||||
bad() { echo "FAIL: $1" >&2; fail=1; }
|
||||
|
||||
# --- Must NOT be present: server-only files, data folders, secrets ---
|
||||
[ -e "$dir/appsettings.Production.json" ] && bad "appsettings.Production.json is in the artifact (server-only file)"
|
||||
for d in uploads logs wwwroot/web; do
|
||||
[ -e "$dir/$d" ] && bad "folder '$d' is in the artifact (owned by the server or by the website upload)"
|
||||
done
|
||||
# Any other environment file: only appsettings.json may ship.
|
||||
while IFS= read -r f; do
|
||||
bad "unexpected configuration file: ${f#"$dir"/}"
|
||||
done < <(find "$dir" -type f \( -name 'appsettings.*.json' -o -name '.env' -o -name '.env.*' -o -name '*.pfx' -o -name '*.pem' -o -name '*.key' -o -name '*.p12' \) -print)
|
||||
# An accidental redirect map would be overwritten by the website upload; it belongs to the website.
|
||||
[ -e "$dir/wwwroot/redirects.json" ] && bad "wwwroot/redirects.json is in the artifact"
|
||||
|
||||
# --- Must be present ---
|
||||
[ -f "$dir/appsettings.json" ] || bad "appsettings.json is missing"
|
||||
[ -f "$dir/SlpModularCms.Api.AndreaSlopFotografie.exe" ] || bad "SlpModularCms.Api.AndreaSlopFotografie.exe is missing (self-contained win-x64 publish expected)"
|
||||
[ -f "$dir/SlpModularCms.Api.AndreaSlopFotografie.dll" ] || bad "SlpModularCms.Api.AndreaSlopFotografie.dll is missing"
|
||||
[ -f "$dir/wwwroot/admin/index.html" ] || bad "wwwroot/admin/index.html is missing (admin frontend not built into the publish)"
|
||||
[ -f "$dir/app_offline.htm" ] && bad "app_offline.htm is in the artifact (the deploy script manages it)"
|
||||
# Self-contained: the runtime ships with the app; native image library for win-x64.
|
||||
[ -f "$dir/coreclr.dll" ] || bad "coreclr.dll is missing: not a self-contained publish"
|
||||
if ! find "$dir" -type f -iname 'Magick.Native-*x64*.dll' | grep -q .; then
|
||||
bad "no win-x64 Magick.Native-*.dll found: uploads would stay switched off"
|
||||
fi
|
||||
|
||||
# --- web.config: the template, with its required fields ---
|
||||
wc="$dir/web.config"
|
||||
if [ ! -f "$wc" ]; then
|
||||
bad "web.config is missing"
|
||||
else
|
||||
grep -q 'hostingModel="inprocess"' "$wc" || bad "web.config: hostingModel is not inprocess"
|
||||
grep -q 'stdoutLogEnabled="true"' "$wc" || bad "web.config: stdoutLogEnabled must be \"true\" in the artifact (set to false by hand after the first start)"
|
||||
grep -q 'stdoutLogFile="\.\\logs\\stdout"' "$wc" || bad "web.config: stdoutLogFile is not .\\logs\\stdout"
|
||||
grep -q 'name="ASPNETCORE_ENVIRONMENT" value="Production"' "$wc" || bad "web.config: ASPNETCORE_ENVIRONMENT=Production is missing"
|
||||
grep -q 'maxAllowedContentLength="31457280"' "$wc" || bad "web.config: upload limit is missing"
|
||||
grep -q 'hiddenSegments' "$wc" || bad "web.config: requestFiltering hiddenSegments is missing"
|
||||
grep -q 'SlpModularCms.Api.AndreaSlopFotografie.exe' "$wc" || bad "web.config: processPath does not point at the ASF host"
|
||||
# Only ASPNETCORE_ENVIRONMENT may be set here; secrets and settings live in appsettings.Production.json.
|
||||
n=$(grep -c '<environmentVariable ' "$wc" || true)
|
||||
[ "${n:-0}" -eq 1 ] || bad "web.config: expected exactly one environmentVariable, found ${n:-0}"
|
||||
# Comments may talk about secrets; only the configuration itself (comments stripped) must not contain any.
|
||||
if awk 'BEGIN{c=0} {l=$0; while(1){ if(c){i=index(l,"-->"); if(!i){l="";break} l=substr(l,i+3); c=0} else {i=index(l,"<!--"); if(!i)break; pre=substr(l,1,i-1); rest=substr(l,i+4); j=index(rest,"-->"); if(j){l=pre substr(rest,j+3)} else {l=pre; c=1; break}} } print l}' "$wc" | grep -Eiq 'password|secret|token|dsn|connectionstring'; then
|
||||
bad "web.config mentions a secret-like word (password/secret/token/dsn/connectionstring)"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$fail" -ne 0 ]; then
|
||||
echo "The ASF production artifact check FAILED." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "ASF production artifact check passed ($(find "$dir" -type f | wc -l) files)."
|
||||
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env bash
|
||||
# Uploads the ASF production publish output (win-x64, IIS) over explicit FTPS, directory by directory,
|
||||
# with app_offline.htm in place while the files change (IIS then releases the locked DLLs).
|
||||
#
|
||||
# Same FTPS style as the website upload of the ASF repo (upload-production.sh): explicit FTPS (AUTH TLS),
|
||||
# TLS forced for control and data, certificate checked, passive mode, password only via LFTP_PASSWORD.
|
||||
#
|
||||
# What this script NEVER touches on the server: appsettings.Production.json, uploads/, logs/, wwwroot/web/
|
||||
# (the website upload owns that one). The only place where files are deleted is wwwroot/admin (the admin
|
||||
# frontend is entirely owned by this artifact and its hashed files would otherwise pile up). There is no
|
||||
# mirror --delete anywhere else, in particular never over the root or over wwwroot.
|
||||
#
|
||||
# Usage: scripts/deploy-asf-iis-ftps.sh <publish-dir>
|
||||
# Env: FTP_HOST (required), FTP_USER (required), LFTP_PASSWORD (required), FTP_PORT (optional, numeric),
|
||||
# REMOTE_DIR (required: the host folder, relative to the FTP home, characters A-Za-z0-9._/- only),
|
||||
# HEALTH_URL (optional: checked after the upload), DRY_RUN=1 (list what would be uploaded, change nothing).
|
||||
#
|
||||
# Failure: when the upload fails, app_offline.htm is LEFT in place (visitors get the maintenance page rather than
|
||||
# a half-updated app). See docs/deploy-asf-productie.md for recovery.
|
||||
set -euo pipefail
|
||||
|
||||
src="${1:-}"
|
||||
[ -n "$src" ] && [ -d "$src" ] || { echo "Usage: $0 <publish-dir>" >&2; exit 2; }
|
||||
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
: "${FTP_HOST:?FTP_HOST is not set}"
|
||||
: "${FTP_USER:?FTP_USER is not set}"
|
||||
: "${LFTP_PASSWORD:?LFTP_PASSWORD is not set}"
|
||||
: "${REMOTE_DIR:?REMOTE_DIR is not set}"
|
||||
export LFTP_PASSWORD
|
||||
|
||||
port_args=()
|
||||
if [ -n "${FTP_PORT:-}" ]; then
|
||||
[[ "$FTP_PORT" =~ ^[0-9]{1,5}$ ]] || { echo "FTP_PORT must be numeric." >&2; exit 2; }
|
||||
port_args=(-p "$FTP_PORT")
|
||||
fi
|
||||
[[ "$FTP_HOST" =~ ^[A-Za-z0-9.:-]+$ ]] || { echo "FTP_HOST contains unexpected characters." >&2; exit 2; }
|
||||
|
||||
# Path validation: only [A-Za-z0-9._/-], no '.', '..' or empty segments.
|
||||
validate_path() {
|
||||
local p="$1" seg
|
||||
[[ "$p" =~ ^[A-Za-z0-9._/-]+$ ]] || { echo "Unsafe path: '$p'" >&2; exit 2; }
|
||||
IFS='/' read -ra segs <<< "$p"
|
||||
for seg in "${segs[@]}"; do
|
||||
[ -n "$seg" ] && [ "$seg" != "." ] && [ "$seg" != ".." ] || { echo "Unsafe path segment in '$p'" >&2; exit 2; }
|
||||
done
|
||||
}
|
||||
validate_path "$REMOTE_DIR"
|
||||
remote="${REMOTE_DIR%/}"
|
||||
case "$remote" in
|
||||
*wwwroot/web|*wwwroot/web/*) echo "REMOTE_DIR must be the host folder, not the website folder (wwwroot/web)." >&2; exit 2;;
|
||||
esac
|
||||
|
||||
# Never upload what must not be there (same rules as the artifact check; this also covers a local run).
|
||||
bash "$here/check-asf-publish.sh" "$src"
|
||||
|
||||
settings='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; set ftp:passive-mode on; set net:max-retries 3; set net:timeout 30; set net:reconnect-interval-base 5; set xfer:make-backup no;'
|
||||
dry="${DRY_RUN:-0}"
|
||||
|
||||
# One lftp session per step (a failing step stops the run).
|
||||
lftp_run() {
|
||||
lftp --env-password -u "$FTP_USER" ${port_args[@]+"${port_args[@]}"} "ftp://$FTP_HOST" -e "$settings $1 quit"
|
||||
}
|
||||
|
||||
excl="--exclude-glob appsettings.Production.json --exclude-glob uploads --exclude-glob logs"
|
||||
mirror_opts="--reverse --verbose=1 --no-perms --parallel=2 $excl"
|
||||
[ "$dry" = "1" ] && mirror_opts="$mirror_opts --dry-run"
|
||||
|
||||
echo "== Target: ftp://$FTP_HOST/$remote (dry run: $dry)"
|
||||
|
||||
echo "== 1/6 Check connection and remote folder"
|
||||
lftp_run "cd '$remote'; cls -1"
|
||||
|
||||
if [ "$dry" != "1" ]; then
|
||||
echo "== 2/6 app_offline.htm (IIS stops the app and releases the DLLs)"
|
||||
lftp_run "cd '$remote'; put -O . '$here/../deploy/asf-iis/app_offline.htm' -o app_offline.htm"
|
||||
sleep 5
|
||||
else
|
||||
echo "== 2/6 (dry run) skipping app_offline.htm"
|
||||
fi
|
||||
|
||||
echo "== 3/6 Directories (no deletes except wwwroot/admin)"
|
||||
while IFS= read -r d; do
|
||||
name="$(basename "$d")"
|
||||
validate_path "$name"
|
||||
case "$name" in
|
||||
uploads|logs) echo "refusing to upload '$name'" >&2; exit 1;;
|
||||
wwwroot)
|
||||
# wwwroot: only the admin is owned by this artifact. Everything else in it is mirrored without deleting;
|
||||
# wwwroot/web belongs to the website upload and is never touched.
|
||||
while IFS= read -r sd; do
|
||||
sname="$(basename "$sd")"
|
||||
validate_path "$sname"
|
||||
[ "$sname" = "web" ] && { echo "refusing to upload wwwroot/web" >&2; exit 1; }
|
||||
if [ "$sname" = "admin" ]; then
|
||||
lftp_run "mirror $mirror_opts --delete '$sd' '$remote/wwwroot/admin'"
|
||||
else
|
||||
lftp_run "mirror $mirror_opts '$sd' '$remote/wwwroot/$sname'"
|
||||
fi
|
||||
done < <(find "$d" -mindepth 1 -maxdepth 1 -type d | sort)
|
||||
lftp_run "mirror $mirror_opts --no-recursion '$d' '$remote/wwwroot'"
|
||||
;;
|
||||
*)
|
||||
lftp_run "mirror $mirror_opts '$d' '$remote/$name'"
|
||||
;;
|
||||
esac
|
||||
done < <(find "$src" -mindepth 1 -maxdepth 1 -type d | sort)
|
||||
|
||||
echo "== 4/6 Files in the root (program files; web.config last)"
|
||||
lftp_run "mirror $mirror_opts --no-recursion --exclude-glob web.config '$src' '$remote'"
|
||||
if [ "$dry" != "1" ]; then
|
||||
lftp_run "cd '$remote'; put -O . '$src/web.config' -o web.config"
|
||||
fi
|
||||
|
||||
if [ "$dry" = "1" ]; then
|
||||
echo "== Dry run finished; nothing was changed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "== 5/6 Remove app_offline.htm (the app starts: migrations run on the first start)"
|
||||
lftp_run "cd '$remote'; rm app_offline.htm"
|
||||
|
||||
echo "== 6/6 Health check"
|
||||
if [ -n "${HEALTH_URL:-}" ]; then
|
||||
# The first start can take a while (migrations, image library self-test).
|
||||
if ! curl -fsS --max-time 30 --retry 12 --retry-delay 10 --retry-all-errors "$HEALTH_URL" >/dev/null; then
|
||||
echo "Health check FAILED for $HEALTH_URL. app_offline.htm has been removed; see the stdout log (logs/stdout_*.log) on the host and docs/deploy-asf-productie.md (recovery)." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Health check passed: $HEALTH_URL"
|
||||
else
|
||||
echo "No HEALTH_URL set; skipped."
|
||||
fi
|
||||
echo "Done."
|
||||
Reference in New Issue
Block a user