56 lines
2.4 KiB
Bash
56 lines
2.4 KiB
Bash
#!/bin/bash
|
|
set -Eeuo pipefail
|
|
|
|
export npm_config_ignore_scripts=true npm_config_ignore_pnpmfile=true
|
|
node /usr/local/lib/dsh-mgr/init-profile.mjs
|
|
if [[ -f "${DSH_HOME}/profiles/web/package.json" ]]; then
|
|
echo "dsh-mgr: plugin prestart reconciliation starting" >&2
|
|
# pnpm otherwise probes registry metadata for the overlapping optional peer.
|
|
# Restrict offline mode to profiles containing only our fixed archives.
|
|
install_env=()
|
|
if node -e 'import("/usr/local/lib/dsh-mgr/reconcile-profile.mjs").then(({BUILTIN_DEPENDENCIES:pins,BUILTIN_OVERRIDES:overrides})=>{const m=require(process.env.DSH_HOME+"/profiles/web/package.json"); process.exit([m.dependencies,m.devDependencies,m.optionalDependencies].every(section=>Object.entries(section||{}).every(([n,v])=>pins[n]===v))&&Object.entries(m.pnpm?.overrides||{}).every(([n,v])=>overrides[n]===v)?0:1)})'; then
|
|
install_env=(npm_config_offline=true)
|
|
fi
|
|
# Only migration installs may refresh the lockfile. Keep the marker on failure
|
|
# so a restart retries even when package.json already contains the new pins.
|
|
pending_lockfile="${DSH_HOME}/profiles/web/.dsh-lockfile-pending"
|
|
install_args=()
|
|
if [[ -f "$pending_lockfile" ]]; then
|
|
install_args+=(--no-frozen-lockfile)
|
|
fi
|
|
# Hide routine progress/peer warnings, but replay diagnostics on any failure.
|
|
if install_output=$(timeout --signal=TERM --kill-after=5s 120s env CI=true "${install_env[@]}" dsh plugin --profile web install --ignore-scripts "${install_args[@]}" 2>&1); then
|
|
rm -f -- "$pending_lockfile"
|
|
echo "dsh-mgr: plugin prestart reconciliation complete" >&2
|
|
else
|
|
status=$?
|
|
printf '%s\n' "$install_output" >&2
|
|
echo "dsh-mgr: plugin prestart reconciliation failed (exit $status); application not started" >&2
|
|
exit "$status"
|
|
fi
|
|
unset install_output
|
|
else
|
|
echo "dsh-mgr: no web plugin manifest; using bundled plugins" >&2
|
|
fi
|
|
|
|
caddy run --config /etc/caddy/Caddyfile --adapter caddyfile &
|
|
proxy_pid=$!
|
|
echo
|
|
dsh "$@" &
|
|
dsh_pid=$!
|
|
cleanup() {
|
|
trap - TERM INT
|
|
kill -TERM "$proxy_pid" "$dsh_pid" 2>/dev/null || true
|
|
wait "$proxy_pid" 2>/dev/null || true
|
|
wait "$dsh_pid" 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT
|
|
trap 'exit 143' TERM
|
|
trap 'exit 130' INT
|
|
# Either child exiting terminates the container; never leave a proxy-only instance.
|
|
set +e
|
|
wait -n "$proxy_pid" "$dsh_pid"
|
|
status=$?
|
|
set -e
|
|
exit "$status"
|