From 6c482238e8b7aab4acfff990c5288e130dd8feaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Sun, 29 Mar 2026 19:44:15 +0200 Subject: [PATCH] Add Grafana deploy annotations to all CD workflows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Posts an annotation to Grafana after each successful deploy, tagged with "deploy" and the service name. Annotations appear as vertical markers on dashboards, making it easy to correlate deploys with metric changes. Uses GRAFANA_SERVICE_TOKEN from SOPS secrets — must be added via sops infrastructure/secrets.infra.env. Gracefully skips if the token is not configured. Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/workflows/cd-apps.yml | 10 ++++++++++ .github/workflows/cd-brouter.yml | 10 ++++++++++ .github/workflows/cd-infra.yml | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/.github/workflows/cd-apps.yml b/.github/workflows/cd-apps.yml index ab3e130..133700a 100644 --- a/.github/workflows/cd-apps.yml +++ b/.github/workflows/cd-apps.yml @@ -110,3 +110,13 @@ jobs: # Clean up docker image prune -af docker compose ps + + # Annotate deploy in Grafana + GRAFANA_TOKEN=$(grep GRAFANA_SERVICE_TOKEN app.env | cut -d= -f2-) + if [ -n "$GRAFANA_TOKEN" ]; then + docker compose exec -T grafana wget -q -O /dev/null \ + --header="Authorization: Bearer $GRAFANA_TOKEN" \ + --header="Content-Type: application/json" \ + --post-data='{"text":"Deploy '${{ github.sha }}'","tags":["deploy","apps"]}' \ + http://localhost:3000/api/annotations || true + fi diff --git a/.github/workflows/cd-brouter.yml b/.github/workflows/cd-brouter.yml index ba369df..3ef953d 100644 --- a/.github/workflows/cd-brouter.yml +++ b/.github/workflows/cd-brouter.yml @@ -64,3 +64,13 @@ jobs: docker pull ghcr.io/trails-cool/brouter:latest docker compose up -d brouter docker image prune -af + + # Annotate deploy in Grafana + GRAFANA_TOKEN=$(grep GRAFANA_SERVICE_TOKEN .env | cut -d= -f2- 2>/dev/null) + if [ -n "$GRAFANA_TOKEN" ]; then + docker compose exec -T grafana wget -q -O /dev/null \ + --header="Authorization: Bearer $GRAFANA_TOKEN" \ + --header="Content-Type: application/json" \ + --post-data='{"text":"Deploy brouter ${{ github.sha }}","tags":["deploy","brouter"]}' \ + http://localhost:3000/api/annotations || true + fi diff --git a/.github/workflows/cd-infra.yml b/.github/workflows/cd-infra.yml index dc6ffc2..eb6450a 100644 --- a/.github/workflows/cd-infra.yml +++ b/.github/workflows/cd-infra.yml @@ -85,3 +85,13 @@ jobs: fi docker compose ps + + # Annotate deploy in Grafana + GRAFANA_TOKEN=$(grep GRAFANA_SERVICE_TOKEN .env | cut -d= -f2-) + if [ -n "$GRAFANA_TOKEN" ]; then + docker compose exec -T grafana wget -q -O /dev/null \ + --header="Authorization: Bearer $GRAFANA_TOKEN" \ + --header="Content-Type: application/json" \ + --post-data='{"text":"Deploy infra ${{ github.sha }}","tags":["deploy","infra"]}' \ + http://localhost:3000/api/annotations || true + fi