8000 GitHub - driverog/homelab: Infrastructure-as-code for my homelab: five GitOps-managed Docker Compose stacks behind a Cloudflare Tunnel, with full OTel observability · GitHub
[go: up one dir, main page]

Skip to content
driverogPublic
forked from lorainemg/homelab

About

Infrastructure-as-code for my homelab: five GitOps-managed Docker Compose stacks behind a Cloudflare Tunnel, with full OTel observability

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

🏠 Homelab

Infrastructure-as-code for my single-node homelab: ~25 containers across five Docker Compose stacks (plus a self-deploying app stack), published to the internet through a Cloudflare Tunnel and fully observable with a Grafana/Prometheus/Loki/Tempo stack.

Everything needed to rebuild the server from scratch lives in this repo. Pushing to main deploys: GitHub Actions builds config-baked images, pushes them to GHCR and updates the affected Portainer stacks through the Cloudflare Tunnel. Only the data stays on the machine; deploy secrets live in GitHub Actions secrets.

Architecture

flowchart LR
    subgraph internet[Internet]
        CF[Cloudflare Tunnel]
    end

    subgraph edge[Edge]
        CADDY[Caddy reverse proxy]
    end

    CF -->|outbound-only tunnel| CADDY

    subgraph apps[Applications]
        IMMICH[Immich photos]
        HA[Home Assistant]
        GRAFANA[Grafana]
        PORTAINER[Portainer]
        REGISTRY[Docker registry]
    end

    CADDY --> IMMICH
    CADDY --> HA
    CADDY --> GRAFANA
    CADDY --> PORTAINER
    CADDY --> REGISTRY

    subgraph voice[Local voice & AI]
        WHISPER[Whisper STT]
        PIPER[Piper TTS]
        OLLAMA[Ollama LLM]
        MQTT[Mosquitto MQTT]
    end

    HA --- WHISPER
    HA --- PIPER
    HA --- OLLAMA
    HA --- MQTT

    subgraph obs[Observability]
        PROM[Prometheus]
        LOKI[Loki]
        TEMPO[Tempo]
        OTEL[OTel Collector]
    end

    BOT[Trakt Telegram bot] -->|OTLP| OTEL
    OTEL --> TEMPO
    OTEL --> LOKI
    PROM --> GRAFANA
    LOKI --> GRAFANA
    TEMPO --> GRAFANA
    PROM -.scrapes.-> HA
    PROM -.scrapes.-> IMMICH
    REGISTRY -->|pulls| BOT
Loading

No inbound ports are open on the router: cloudflared maintains an outbound-only tunnel to Cloudflare, which routes *.{domain} hostnames to Caddy, which reverse-proxies to each service over a shared Docker bridge network (internal). TLS terminates at Cloudflare's edge. The tunnel runs in the host-managed portainer compose (the control plane CI deploys through), so no CI deploy can take it down.

Stacks

Stack What it runs Why
config/ Caddy 2.8 + config-agent Reverse proxy for every published service, plus the one container that flows repo config (HA yaml, mosquitto.conf, Caddyfile) to the live dirs and UI edits back to git
immich/ Immich v3, Postgres (pgvector), Valkey, ML service Self-hosted Google Photos replacement with on-device ML
home-assistant/ Home Assistant, Mosquitto, Whisper, Piper, Ollama Smart home with a fully local voice assistant pipeline (STT → LLM → TTS)
monitoring/ Prometheus, Grafana, Loki, Tempo, OTel Collector, Promtail, cAdvisor, node-exporter Metrics, logs, and traces for the host and every container
registry/ Docker Registry 2 Private image registry for my own builds. The one stack not deployed by CI: Komodo pulls it from this repo on a GitHub webhook
portainer/ Portainer CE + cloudflared Control plane: management UI/API + the tunnel that exposes everything (host-managed, never CI-deployed)
komodo/ Komodo Core + Periphery + MongoDB Second control plane, under evaluation against Portainer until 2026-08-20. Host-managed, never CI-deployed. Owns the docker-registry stack

One more stack runs on the server but is deliberately not defined here: traktv-tg-bot (my Telegram bot for Trakt.tv + Postgres 17 + Aspire dashboard) generates its compose file with .NET Aspire and deploys itself from its own repo's CI via the Portainer API — the same pattern this repo uses for the infrastructure stacks. This repo only documents the seam (the monitoring stack joins its network to collect telemetry).

Highlights:

  • Local voice assistant — Home Assistant's Assist pipeline wired to Wyoming Whisper (speech-to-text), Wyoming Piper (text-to-speech) and a local Llama 3.2 model served by Ollama. No cloud round-trip.
  • Full observability — the Trakt bot ships traces/logs over OTLP to an OpenTelemetry Collector that fans out to Tempo, Loki and an Aspire dashboard; Prometheus scrapes the host, every container (cAdvisor), Home Assistant and Immich; Grafana ties it all together.
  • Self-hosted CI artifact flow — the Trakt bot's images are built by .NET Aspire's deployment pipeline in GitHub Actions and pushed to the self-hosted registry the server then pulls from.

Repo layout

├── .github/workflows/deploy.yml   change detection → image builds → stack deploys
├── config/           docker-compose.yml, Caddyfile, deploy.env
│   └── config-agent/ the one config container: repo → live sync + hourly UI-edit backup
├── immich/           docker-compose.yml, deploy.env
├── home-assistant/   docker-compose.yml, .env.example
│   ├── ha-config/    HA yaml config (automations, scripts, scenes, ...)
│   └── mosquitto/    mosquitto.conf (passwd file is generated, not committed)
├── monitoring/       docker-compose.yml
│   ├── prometheus/   Dockerfile, prometheus.yml, entrypoint (HA token via env)
│   ├── promtail/     Dockerfile, promtail.yml
│   ├── tempo/        Dockerfile, tempo.yml
│   └── otelcol/      Dockerfile, otel-collector.yml
├── registry/         docker-compose.yml (deployed by Komodo, not CI)
├── portainer/        docker-compose.yml (Portainer + cloudflared), .env.example
├── komodo/           docker-compose.yml (Core + Periphery + Mongo), .env.example
└── scripts/          bootstrap.sh, pre-commit (gitleaks)

Conventions:

  • Config baked into images, state on disk. Pure config (Prometheus/OTel/Promtail/Tempo configs) is baked into thin images (FROM upstream + COPY config) built by CI and published to GHCR, so a stack needs nothing from the host but its volumes. Config that has to live next to runtime state (HA yaml, mosquitto.conf) or hot-reload (Caddyfile) ships inside the config-agent image instead and is synced to the live dirs at deploy time. Stateful directories (photo library, HA runtime, Ollama models, databases) live under a data root (/data by default).
  • Secrets never in git. Runtime secrets are GitHub Actions secrets, injected into each stack's environment at deploy time; committed deploy.env files hold the non-secret variables. The one file-based secret (Prometheus's HA token) is materialized at container start from an env var by its entrypoint. A gitleaks pre-commit hook backstops it all.

Rebuilding from scratch

  1. Install Docker Engine + the Compose plugin; mount/create the data disk at /data.
  2. Restore the data directories from backup (Immich library + DB, HA config, etc.) — or start fresh.
  3. Create the shared network and start the control plane (Portainer + the tunnel): copy portainer/.env.example to portainer/.env, fill in the tunnel token, then docker network create internal && docker compose --project-directory portainer up -d. Point the tunnel's public hostnames — portainer.<domain>, immich.<domain>, grafana.<domain>, … — at http://caddy:80 (Portainer needs to be reachable by GitHub Actions).
  4. Set the repo's Actions secrets: PORTAINER_URL, PORTAINER_API_TOKEN (Portainer → My account → Access tokens), GRAFANA_ADMIN_PASSWORD, HA_TOKEN, DB_PASSWORD, HOMELAB_PUSH_TOKEN (fine-grained PAT, contents read/write on this repo only — lets config-agent push UI-made HA edits back).
  5. Run the Deploy workflow (workflow_dispatch) — it builds every image and (re)creates every stack.
  6. Mosquitto users are the one manual step: docker exec mosquitto mosquitto_passwd -c /mosquitto/config/passwd homeassistant

To run without Portainer/CI at all: copy each stack's .env.example to .env, fill it in, and run ./scripts/bootstrap.sh — the compose files work standalone since the images are public.

Home Assistant's HACS custom components (better_thermostat, browser_mod, extended_openai_conversation, hacs, monitor_docker, roborock_custom_map, smartrent, teamtracker, and friends) are reinstalled through HACS rather than committed — the 128 MB of vendored code doesn't belong in git.

Contributing to it (a.k.a. me, later)

Enable the secret-scanning hook once per clone:

cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

CI/CD (deploy.yml)

Every push to main runs the pipeline on a GitHub-hosted runner:

  1. Change detection — dorny/paths-filter maps the diff to the affected stacks and fans them out as a job matrix. Untouched stacks aren't redeployed.
  2. Image builds — a second paths-filter decides, per image, whether its config actually changed; only then does docker/build-push-action rebuild and push it to ghcr.io/lorainemg/homelab/* (tagged latest + commit SHA for rollbacks). A Caddyfile tweak rebuilds one image, not five.
  3. Stack deploys — cssnr/portainer-stack-deploy-action updates the stack through the Portainer API (reached via the Cloudflare Tunnel), passing the stack's committed deploy.env plus its secrets as environment variables. Stacks stay fully editable in Portainer's UI.

workflow_dispatch deploys everything unconditionally — the fresh-server / changed-secrets button.

Config that can't be baked into an app's own image flows through a single config-agent container in the config stack. CI bakes the HA yaml, mosquitto.conf and the Caddyfile into one image (ghcr.io/lorainemg/homelab/config-agent); at deploy time the agent copies the files that actually changed into the live dirs (keeping the previous version in .sync-backup/ next to each), then the running services pick them up without being recreated: Caddy runs with --watch and hot-reloads its Caddyfile by itself, and Home Assistant is reloaded — or restarted, when configuration.yaml changed — through its API. Because no config push ever recreates the caddy container, a deploy can't sever the tunnel → caddy → Portainer path its own API response travels through (the only deploy still expected to lose its response is an edit to the config stack's compose file itself, e.g. a caddy version bump — rare and deliberate). The flow is two-way: the same agent commits UI-made edits (automations, scripts, scenes, helpers) back to this repo once an hour with [skip ci], so nothing is lost between deploys. Runtime state (.storage/, databases, custom_components/, Mosquitto's passwd) is never touched — back that layer up with HA's built-in automatic backups.

About

Infrastructure-as-code for my homelab: five GitOps-managed Docker Compose stacks behind a Cloudflare Tunnel, with full OTel observability

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0