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>
64 lines
4.1 KiB
Bash
64 lines
4.1 KiB
Bash
#!/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)."
|