thermograph/infra/deploy/stack/env-entrypoint.sh
emi a4ecb51401
Some checks failed
secrets-guard / encrypted (push) Successful in 24s
shell-lint / shellcheck (push) Successful in 26s
Deploy frontend to LAN dev server / build (push) Successful in 2m11s
Build + push frontend image (Forgejo registry) / build-push (push) Successful in 2m20s
Build + push backend image (Forgejo registry) / build-push (push) Successful in 2m28s
Deploy backend to LAN dev server / build (push) Successful in 2m45s
PR build (required check) / changes (pull_request) Successful in 16s
secrets-guard / encrypted (pull_request) Successful in 16s
shell-lint / shellcheck (pull_request) Successful in 15s
PR build (required check) / build-frontend (pull_request) Has been skipped
PR build (required check) / validate-observability (pull_request) Has been skipped
Deploy frontend to LAN dev server / deploy (push) Successful in 39s
PR build (required check) / build-backend (pull_request) Successful in 1m21s
PR build (required check) / gate (pull_request) Successful in 3s
Deploy backend to LAN dev server / deploy (push) Failing after 2m31s
web/worker: add a process-level liveness heartbeat (#80)
2026-07-25 04:13:47 +00:00

51 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Stack-task entrypoint shim: source the host-rendered secrets env, then hand
# off to the image's real entrypoint.
#
# Why: `docker stack deploy` does not support compose's `env_file:`, and
# enumerating every vault key in the stack yml's `environment:` blocks would
# drift the moment a key is added to deploy/secrets/. Instead deploy-stack.sh
# installs a uid-10001-readable copy of the rendered env at
# /etc/thermograph/stack.env, the stack bind-mounts it (with this script) into
# every app task, and this shim exports each KEY=value — but ONLY for keys not
# already set, so the yml's `environment:` blocks keep compose's env_file
# precedence (environment always wins). Same set-if-unset contract as the
# image's own /run/secrets shim in deploy/entrypoint.sh, which still runs
# after this and stays a no-op here.
set -euo pipefail
ENV_FILE="${THERMOGRAPH_HOST_ENV:-/host/thermograph.env}"
if [ -f "$ENV_FILE" ]; then
while IFS= read -r line || [ -n "$line" ]; do
case "$line" in
''|'#'*) continue ;;
*=*)
key="${line%%=*}"
# Only sane identifiers; only if not already set by `environment:`.
case "$key" in
*[!A-Za-z0-9_]*|'') continue ;;
esac
if [ -z "${!key:-}" ]; then
export "$key=${line#*=}"
fi
;;
esac
done < "$ENV_FILE"
fi
# Hand off: the backend image has a real entrypoint script and takes that
# branch. Anything else needs an explicit `command:` in the stack yml's
# service block -- overriding `entrypoint:` here drops the image's own CMD
# entirely (Docker/Swarm does not merge them), so `$@` is empty unless the
# stack file supplies one. The frontend service does exactly that. The
# uvicorn fallback below is what ran, silently, whenever that expectation
# didn't hold; it is Python-specific and kept only as a loud, familiar-looking
# failure for a misconfigured non-Python image, not a real handoff path.
if [ -x /app/deploy/entrypoint.sh ]; then
exec /app/deploy/entrypoint.sh "$@"
elif [ "$#" -gt 0 ]; then
exec "$@"
else
exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-8080}"
fi