#!/usr/bin/env bash # # Generate the reverse proxy's Caddyfile from CoreSystemConfig.json. # # Called by the container-host ISO builder and by setup-container-host.sh, so the proxy # is configured from the same single source as everything else — the hostname it serves, # the ports it forwards to, and which services exist at all. # # tools/generate-caddyfile.sh # # See proxy/README.md for why this exists (short version: the admin panel's token is in # a URL, the registration camera needs a secure context, and a mixed-content page can't # call its own API). set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=lib/coreconfig.sh source "${SCRIPT_DIR}/lib/coreconfig.sh" DEST="${1:-}" [[ -n "$DEST" ]] || core_die "Usage: $0 " core_load if [[ "$CORE_PROXY_ENABLED" != "true" ]]; then core_warn "proxy.enabled is false — nothing to generate." exit 0 fi # TLS directive. `tls internal` is Caddy's own CA; the custom branch points at mounted # files. Note the paths are the CONTAINER's, not the host's — the compose service # mounts them read-only at these locations. if [[ "$CORE_PROXY_TLS" == "custom" ]]; then TLS_LINE=" tls /etc/caddy/certs/cert.pem /etc/caddy/certs/key.pem" else TLS_LINE=" tls internal" fi # Only proxy services that exist. A route to a container that was never started would # give a 502 that looks like a proxy fault rather than a service that isn't enabled. PANTRY_ROUTE="" if [[ "$CORE_ENABLE_PANTRY_VISION" == "true" ]]; then PANTRY_ROUTE=" # pantry-vision's API, same prefix-stripping as identity's. handle_path /api/pantry/* { reverse_proxy pantry-vision:${CORE_PORT_PANTRY_VISION} } " fi mkdir -p "$(dirname "$DEST")" cat > "$DEST" <