Files
selfheal-lab-gitops/vm/legacy-api/apply.sh
T
seon 4f3188b491 fix: short host name for the instance label; AI VM images 683a2de
GCE의 hostname은 FQDN이라 Mimir의 instance 라벨이 legacy-2n1c.asia-northeast1-b.c....internal로
들어왔다(실측). hostname -s로 VM 이름만 쓴다. vm/ai-env/image.tag를 683a2de(hitl 진단 보존 수정)로.
2026-10-08 01:57:04 +09:00

24 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# legacy-api VM (GCP MIG instance). Idempotent: run at first boot by the startup script and again by `make vm-sync`.
# 1) DB password from Secret Manager via the VM service account (metadata token; no key files, design 6.11)
# 2) docker compose up with the pinned image tag
# 3) Alloy sidecar (WP-15): metrics + logs to the observability VM; INSTANCE = this VM's name for the instance label
set -euo pipefail
cd "$(dirname "$0")"
PROJECT="$(curl -sf -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/project/project-id)"
command -v jq >/dev/null || { apt-get update -qq && apt-get install -y -qq jq >/dev/null; }
TOKEN="$(curl -sf -H 'Metadata-Flavor: Google' 'http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token' | jq -r .access_token)"
DB_PASSWORD="$(curl -sf -H "Authorization: Bearer ${TOKEN}" \
"https://secretmanager.googleapis.com/v1/projects/${PROJECT}/secrets/selfheal-db-password/versions/latest:access" \
| jq -r .payload.data | base64 -d || true)"
unset TOKEN
ENV_FILE=/opt/selfheal/legacy-api.env
umask 077
{
printf 'DB_DSN=postgres://app:%s@10.20.0.20:5432/app?sslmode=require\n' "${DB_PASSWORD}"
printf 'INSTANCE=%s\n' "$(hostname -s)"
} > "$ENV_FILE"
unset DB_PASSWORD
docker compose --env-file "$ENV_FILE" -f compose.yaml up -d --pull always --remove-orphans
docker compose --env-file "$ENV_FILE" -f compose.yaml ps