trails/.github/workflows/cd-brouter.yml
Ullrich Schäfer 6c482238e8
Add Grafana deploy annotations to all CD workflows
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) <noreply@anthropic.com>
2026-03-29 19:44:15 +02:00

76 lines
2.3 KiB
YAML

name: CD BRouter
on:
push:
branches: [main]
paths:
- "docker/brouter/**"
workflow_dispatch: {}
concurrency:
group: deploy-brouter
cancel-in-progress: true
jobs:
build:
name: Build & Push BRouter Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v7
with:
context: docker/brouter
push: true
tags: |
ghcr.io/trails-cool/brouter:latest
ghcr.io/trails-cool/brouter:${{ github.sha }}
deploy:
name: Deploy BRouter
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: root
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
cd /opt/trails-cool
# Download BRouter segments if missing
if [ ! -d /opt/trails-cool/segments ] || [ -z "$(ls /opt/trails-cool/segments/*.rd5 2>/dev/null)" ]; then
mkdir -p /opt/trails-cool/segments
echo "Downloading Germany BRouter segments..."
for tile in E5_N45 E5_N50 E10_N45 E10_N50; do
[ -f "/opt/trails-cool/segments/${tile}.rd5" ] || \
wget -q "https://brouter.de/brouter/segments4/${tile}.rd5" -O "/opt/trails-cool/segments/${tile}.rd5"
done
fi
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