Merge pull request #501 from trails-cool/refactor/config-directory-mounts

refactor(infra): directory-mount configs so deploys actually apply them
This commit is contained in:
Ullrich Schäfer 2026-06-09 13:16:29 +02:00 committed by GitHub
commit 16375f8050
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 48 additions and 16 deletions

View file

@ -100,7 +100,7 @@ jobs:
host: ${{ secrets.DEPLOY_HOST }} host: ${{ secrets.DEPLOY_HOST }}
username: root username: root
key: ${{ secrets.DEPLOY_SSH_KEY }} key: ${{ secrets.DEPLOY_SSH_KEY }}
source: "infrastructure/docker-compose.yml,infrastructure/Caddyfile" source: "infrastructure/docker-compose.yml,infrastructure/caddy"
target: /opt/trails-cool target: /opt/trails-cool
strip_components: 1 strip_components: 1

View file

@ -43,7 +43,7 @@ jobs:
host: ${{ secrets.DEPLOY_HOST }} host: ${{ secrets.DEPLOY_HOST }}
username: root username: root
key: ${{ secrets.DEPLOY_SSH_KEY }} key: ${{ secrets.DEPLOY_SSH_KEY }}
source: "infrastructure/docker-compose.yml,infrastructure/Caddyfile,infrastructure/prometheus/prometheus.yml,infrastructure/loki/loki-config.yml,infrastructure/promtail/promtail-config.yml,infrastructure/postgres/queries.yml,infrastructure/postgres/init-grafana-user.sql,infrastructure/grafana/provisioning,infrastructure/grafana/dashboards" source: "infrastructure/docker-compose.yml,infrastructure/caddy,infrastructure/prometheus/prometheus.yml,infrastructure/loki/loki-config.yml,infrastructure/promtail/promtail-config.yml,infrastructure/postgres/queries.yml,infrastructure/postgres/init-grafana-user.sql,infrastructure/grafana/provisioning,infrastructure/grafana/dashboards"
target: /opt/trails-cool target: /opt/trails-cool
strip_components: 1 strip_components: 1
@ -88,14 +88,25 @@ jobs:
if [ "${{ github.event.inputs.restart_all }}" = "true" ]; then if [ "${{ github.event.inputs.restart_all }}" = "true" ]; then
docker compose --env-file .env up -d --remove-orphans docker compose --env-file .env up -d --remove-orphans
else else
# Restart infra services (except Caddy — just reload its config). # Restart infra services (config reloads handled below).
# --remove-orphans cleans up containers whose service was deleted # --remove-orphans cleans up containers whose service was deleted
# from the compose file (e.g., the flagship `brouter` removal in # from the compose file (e.g., the flagship `brouter` removal in
# PR #297 left an orphan that had to be removed by hand). # PR #297 left an orphan that had to be removed by hand).
docker compose --env-file .env up -d --remove-orphans postgres prometheus loki promtail grafana postgres-exporter node-exporter cadvisor docker compose --env-file .env up -d --remove-orphans postgres prometheus loki promtail grafana postgres-exporter node-exporter cadvisor
docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile
fi fi
# Apply config-only changes that `up -d` skips — it recreates a
# container only when its compose *definition* changes, not when a
# mounted config file's content changes. The configs are mounted as
# directories (not single files), so a reload/restart re-reads the
# freshly scp'd file; a single-file mount would have pinned the old
# inode. Prometheus hot-reloads on SIGHUP (zero downtime); Loki and
# Promtail reload their main config only on restart; Caddy reloads
# gracefully (validates, swaps live, no downtime).
docker compose --env-file .env kill -s SIGHUP prometheus
docker compose --env-file .env restart loki promtail
docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile
docker compose ps docker compose ps
# Gate on the stack actually being up: postgres healthy and — # Gate on the stack actually being up: postgres healthy and —

View file

@ -36,7 +36,9 @@ services:
ports: ports:
- "9090:9090" - "9090:9090"
volumes: volumes:
- ./infrastructure/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro # Directory mount (not the file) to match prod — a single-file bind
# mount pins the host inode, so a replaced config is never seen.
- ./infrastructure/prometheus:/etc/prometheus:ro
- prometheus_data:/prometheus - prometheus_data:/prometheus
grafana: grafana:
@ -60,9 +62,10 @@ services:
ports: ports:
- "3100:3100" - "3100:3100"
volumes: volumes:
- ./infrastructure/loki/loki-config.yml:/etc/loki/local-config.yaml:ro # Directory mount (not the file) to match prod.
- ./infrastructure/loki:/etc/loki:ro
- loki_data:/loki - loki_data:/loki
command: ["-config.file=/etc/loki/local-config.yaml"] command: ["-config.file=/etc/loki/loki-config.yml"]
volumes: volumes:
pgdata: pgdata:

View file

@ -0,0 +1,3 @@
# Mountpoint for the runtime ./sites overlay (per-PR staging snippets).
# Caddy reads site blocks from /etc/caddy/sites; this keeps the dir present
# inside the read-only ./caddy bind mount so the overlay can attach.

View file

@ -14,10 +14,17 @@ services:
environment: environment:
DOMAIN: ${DOMAIN:-trails.cool} DOMAIN: ${DOMAIN:-trails.cool}
volumes: volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro # Mount the caddy/ DIRECTORY, not the Caddyfile directly. A single-
# Per-PR staging snippets dropped in by cd-staging.yml. Bind mount # file bind mount pins to the host file's inode at create time, so a
# auto-creates the host directory if it doesn't exist, so a fresh # deploy that replaces the file (scp) leaves the container reading the
# server doesn't need pre-provisioning. # old inode — `caddy reload` then reloads stale config. A directory
# mount resolves children live, so reload picks up the new Caddyfile.
# The container path /etc/caddy/Caddyfile is unchanged.
- ./caddy:/etc/caddy:ro
# Per-PR staging snippets dropped in by cd-staging.yml, overlaid onto
# the read-only caddy dir above (caddy/sites/.gitkeep keeps the
# mountpoint present). Bind mount auto-creates the host directory if
# it doesn't exist, so a fresh server doesn't need pre-provisioning.
- ./sites:/etc/caddy/sites:ro - ./sites:/etc/caddy/sites:ro
- caddy_data:/data - caddy_data:/data
- caddy_config:/config - caddy_config:/config
@ -187,8 +194,10 @@ services:
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro - /var/run/docker.sock:/var/run/docker.sock:ro
- /var/lib/docker/containers:/var/lib/docker/containers:ro - /var/lib/docker/containers:/var/lib/docker/containers:ro
- ./promtail/promtail-config.yml:/etc/promtail/config.yml:ro # Directory mount (not the file) so a deploy's replaced config is seen
command: ["-config.file=/etc/promtail/config.yml"] # live and a SIGHUP reload picks it up — see the caddy note above.
- ./promtail:/etc/promtail:ro
command: ["-config.file=/etc/promtail/promtail-config.yml"]
depends_on: depends_on:
- loki - loki
@ -196,7 +205,10 @@ services:
image: prom/prometheus:latest image: prom/prometheus:latest
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro # Directory mount (not the file) so config changes are seen live and a
# SIGHUP reload applies them without recreating the container — see the
# caddy note above. --config.file path below is unchanged.
- ./prometheus:/etc/prometheus:ro
- prometheus_data:/prometheus - prometheus_data:/prometheus
command: command:
- "--config.file=/etc/prometheus/prometheus.yml" - "--config.file=/etc/prometheus/prometheus.yml"
@ -207,9 +219,12 @@ services:
image: grafana/loki:latest image: grafana/loki:latest
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ./loki/loki-config.yml:/etc/loki/local-config.yaml:ro # Directory mount (not the file) so a replaced config is seen live —
# see the caddy note above. Loki only reloads its main config on
# restart (no SIGHUP), so cd-infra restarts loki rather than HUPs it.
- ./loki:/etc/loki:ro
- loki_data:/loki - loki_data:/loki
command: ["-config.file=/etc/loki/local-config.yaml"] command: ["-config.file=/etc/loki/loki-config.yml"]
# Publish only on the vSwitch IP so Promtail running on the # Publish only on the vSwitch IP so Promtail running on the
# dedicated BRouter host can push logs in. Hetzner Cloud firewall # dedicated BRouter host can push logs in. Hetzner Cloud firewall
# still blocks 3100 from the public internet. Internal services on # still blocks 3100 from the public internet. Internal services on