fix(deploy): extract TELEGRAM vars from .env without sourcing it
`. ./.env` choked on shell-hostile values (SMTP_PASS special chars), aborting before TELEGRAM vars loaded and rendering an empty alertmanager.yml. Extract just the two keys with sed instead, and warn if either is empty.
This commit is contained in:
parent
7670608c1a
commit
dba7632ce2
1 changed files with 9 additions and 3 deletions
12
deploy.sh
12
deploy.sh
|
|
@ -36,14 +36,20 @@ python3 scripts/sync_nav.py
|
|||
# / ${TELEGRAM_CHAT_ID}) crash-loops it ("cannot unmarshal !!str `${TELEG...`").
|
||||
# We substitute the real values here from .env at deploy time. Only those two
|
||||
# vars are expanded so Alertmanager's own {{ }} Go-template message is untouched.
|
||||
# NB: we extract just these two keys (not `source .env`) because .env holds values
|
||||
# with shell-hostile chars (e.g. SMTP_PASS) that break `. ./.env`.
|
||||
echo ""
|
||||
echo "=== Rendering monitoring/alertmanager.yml from template ==="
|
||||
if [ -f monitoring/alertmanager.yml.template ]; then
|
||||
set -a; [ -f .env ] && . ./.env; set +a
|
||||
get_env() { sed -n "s/^$1=//p" .env | head -n1; }
|
||||
TELEGRAM_BOT_TOKEN="$(get_env TELEGRAM_BOT_TOKEN)"
|
||||
TELEGRAM_CHAT_ID="$(get_env TELEGRAM_CHAT_ID)"
|
||||
export TELEGRAM_BOT_TOKEN TELEGRAM_CHAT_ID
|
||||
envsubst '${TELEGRAM_BOT_TOKEN} ${TELEGRAM_CHAT_ID}' \
|
||||
< monitoring/alertmanager.yml.template > monitoring/alertmanager.yml
|
||||
if grep -q '\${TELEGRAM' monitoring/alertmanager.yml; then
|
||||
echo "WARN: TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID not set in .env; Alertmanager will crash-loop." >&2
|
||||
if grep -q '\${TELEGRAM' monitoring/alertmanager.yml \
|
||||
|| [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then
|
||||
echo "WARN: TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID missing in .env; Alertmanager will crash-loop." >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue