trails/.github/workflows/cd-brouter.yml
Ullrich Schäfer 3c4c1eebd8
Fix BRouter first-deploy issues discovered during cutover
Three fixes after the first cd-brouter run on the dedicated host:

1. **BRouter 1.7.8 → 1.7.9** (`docker/brouter/Dockerfile`). Planet RD5
   segments on brouter.de are now version 11; 1.7.8's `lookups.dat`
   is v10, causing `lookup version mismatch (old rd5?)
   lookups.dat=10 E10_N45.rd5=11` on every route request.

2. **cd-brouter.yml: docker login to ghcr.io before pull**.
   ghcr.io/trails-cool/brouter is private, and the dedicated host's
   Docker daemon isn't logged in by default. Extract DEPLOY_GHCR_TOKEN
   from SOPS at runner side, pass to the SSH step via envs, and
   `docker login` before `docker compose pull`. Credential is
   `::add-mask::`-ed so it doesn't show in logs.

3. **Drop custom healthcheck** on the brouter service. The image
   strips wget/curl post-build, and /bin/sh in the base doesn't
   support /dev/tcp, so there's no in-image way to do an HTTP probe.
   Real health is observed via Caddy's upstream 502 behavior on
   outage and the Planner-side `brouter_request_duration_seconds`
   metric. caddy's `depends_on` drops from service_healthy to
   service_started.

End-to-end verified on the dedicated host after applying the compose
fix manually:
- Caddy enforces auth: 403 without header, proxies with.
- BRouter 1.7.9 will resolve the segment-version error once the image
  is rebuilt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 23:21:46 +02:00

126 lines
4.7 KiB
YAML

name: CD BRouter
on:
push:
branches: [main]
paths:
- "docker/brouter/**"
- "infrastructure/brouter-host/**"
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 to dedicated host
needs: [build]
runs-on: ubuntu-latest
environment: infra
steps:
- uses: actions/checkout@v6
- name: Decrypt shared secret
id: decrypt
run: |
curl -sLO https://github.com/getsops/sops/releases/download/v3.9.4/sops-v3.9.4.linux.amd64
chmod +x sops-v3.9.4.linux.amd64
# Extract ONLY BROUTER_AUTH_TOKEN from secrets.app.env — the
# rest of that file is app-only and has no business reaching
# the BRouter host.
SOPS_AGE_KEY="${{ secrets.AGE_SECRET_KEY }}" ./sops-v3.9.4.linux.amd64 -d infrastructure/secrets.app.env \
| grep '^BROUTER_AUTH_TOKEN=' > infrastructure/brouter-host/.env
chmod 0600 infrastructure/brouter-host/.env
# GHCR pull credential — not shipped to the host's filesystem;
# passed to the SSH step as an env var so it only lives in
# memory during `docker login`.
GHCR_TOKEN=$(SOPS_AGE_KEY="${{ secrets.AGE_SECRET_KEY }}" ./sops-v3.9.4.linux.amd64 -d infrastructure/secrets.app.env \
| grep '^DEPLOY_GHCR_TOKEN=' | cut -d= -f2-)
echo "::add-mask::$GHCR_TOKEN"
echo "GHCR_TOKEN=$GHCR_TOKEN" >> $GITHUB_ENV
- name: Copy compose project to dedicated host
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.BROUTER_DEPLOY_HOST }}
username: trails
port: ${{ secrets.BROUTER_DEPLOY_SSH_PORT }}
key: ${{ secrets.BROUTER_DEPLOY_SSH_KEY }}
source: "infrastructure/brouter-host/docker-compose.yml,infrastructure/brouter-host/Caddyfile,infrastructure/brouter-host/promtail-config.yml,infrastructure/brouter-host/download-segments.sh,infrastructure/brouter-host/.env"
target: /home/trails/brouter
strip_components: 2
- name: Pull image and restart containers
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.BROUTER_DEPLOY_HOST }}
username: trails
port: ${{ secrets.BROUTER_DEPLOY_SSH_PORT }}
key: ${{ secrets.BROUTER_DEPLOY_SSH_KEY }}
envs: GHCR_TOKEN
script: |
set -euo pipefail
cd /home/trails/brouter
chmod +x download-segments.sh
# Segment download is explicitly NOT run here — it's
# multi-hour and idempotent. Seeding the segments directory
# is a one-shot operator task (see brouter-host/README.md).
# Run `~/brouter/download-segments.sh` by hand (or via cron)
# to refresh.
if [ ! -d segments ] || [ -z "$(ls -A segments 2>/dev/null)" ]; then
echo "WARNING: segments/ is empty. BRouter will start but return 404 until segments are seeded."
mkdir -p segments
fi
# GHCR images (brouter) are private; log in so pull works.
# Credentials stay in ~/.docker/config.json; acceptable on a
# single-tenant trails user.
echo "$GHCR_TOKEN" | docker login ghcr.io -u stigi --password-stdin
docker compose pull
docker compose up -d --remove-orphans
docker compose ps
- name: Annotate deploy in flagship Grafana
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: root
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
cd /opt/trails-cool
GRAFANA_TOKEN=$(grep GRAFANA_SERVICE_TOKEN .env | cut -d= -f2-)
if [ -n "$GRAFANA_TOKEN" ]; then
docker compose exec -T grafana curl -sf -X POST \
-H "Authorization: Bearer $GRAFANA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text":"Deploy brouter ${{ github.sha }}","tags":["deploy","brouter"]}' \
http://localhost:3000/api/annotations || true
fi