#!/usr/bin/env bash # Render the prod main-host runtime env.sh from the workflow job environment. # # Sourced identically by prod-deploy (deploy-main) and prod-rollback # (rollback-main) so the two paths cannot drift: a rollback recreates the # containers, so it must re-render the SAME runtime env a full deploy does — # otherwise transactional email, VK login and Grafana alerts silently go dark # after a rollback until the next full deploy. # # Usage: APP_VERSION= bash deploy/write-prod-env.sh # # Every other value comes from the caller's environment (the job `env:` block, # vars.* / secrets.*). Mirrors the compose interpolation contract in # deploy/.env.example; keep in sync with deploy/docker-compose{,.prod}.yml. out="${1:?usage: write-prod-env.sh }" # Derive the public URLs from the one canonical origin instead of storing each # under its own variable. The path suffixes are structural (SPA routes / the # Caddy /_gm sub-path), identical on every contour. base="${PUBLIC_BASE_URL%/}" TELEGRAM_MINIAPP_URL="$base/telegram/" GRAFANA_ROOT_URL="$base/_gm/grafana/" VITE_VK_ID_REDIRECT_URL="$base/app/" # Grafana needs a BARE from-address (it rejects the "Name" form the backend # go-mail accepts, and validates it even when SMTP is disabled — a bad value # crash-loops Grafana). Split the display-format SERVICE From into address + name; # the backend keeps the full form. svc_from="${SMTP_RELAY_SERVICE_FROM:-}" GRAFANA_SMTP_FROM_NAME='' case "$svc_from" in *"<"*">"*) GRAFANA_SMTP_FROM_ADDRESS="$(printf '%s' "$svc_from" | sed -E 's/.*<([^>]+)>.*/\1/')" GRAFANA_SMTP_FROM_NAME="$(printf '%s' "$svc_from" | sed -E 's/[[:space:]]*<[^>]*>.*$//; s/^"//; s/"$//')" ;; *) GRAFANA_SMTP_FROM_ADDRESS="$svc_from" ;; esac cat > "$out" <