7.3 KiB
type, project, tags
| type | project | tags | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| guide | homelab |
|
🧠 Brain GitOps & Auto-Sync Deployment Pipeline
🎯 Overview & Objectives
The Brain repository is the canonical data vault and knowledge graph for the homelab ecosystem. To achieve frictionless authoring with absolute data integrity and instantaneous live publishing, Brain employs a zero-delay GitOps synchronization pipeline.
Any change committed locally flows through a multi-stage pipeline:
- Local Pre-commit Gate: 9-phase integrity check (
validate-brain.py). - Local Post-commit Trigger: Automatic push over custom SSH port
2223. - Gitea CI & Hot Mirroring: Server-side Actions validation (
act_runner) and GitHub backup sync. - Webhook Event Dispatch: Internal HTTP POST to
homelab-gitopson port9000. - Host-Level GitOps Dispatcher: Zero-delay fast-forward Git pull into the server's
~/Braininstance. - Live Consumer API & Presentation: Instantaneous rendering via
homelab-doc2siteathttps://docs.roadtotech.me.
🏛️ End-to-End Pipeline Architecture
flowchart TD
subgraph LocalWorkstation["1. Local Author Workstation (~/Brain)"]
AuthorEdit["Author writes note / code"]
GitCommit["git commit -m '...'"]
PreHook["pre-commit hook\n(validate-brain.py: 9 checks)"]
PostHook["post-commit hook\n(auto-push to origin)"]
AuthorEdit --> GitCommit --> PreHook --> PostHook
end
subgraph GiteaForge["2. Gitea Forge (gitea.roadtotech.me:2223)"]
GiteaSSH["SSH Port 2223 (git user)"]
ActionsCI["Gitea Actions\n(act_runner: validate.yaml)"]
PushMirror["Push Mirror\n(GitHub Hot Backup)"]
WebhookTrigger["Webhook Event\n(POST -> :9000/hooks/deploy)"]
GiteaSSH --> ActionsCI
GiteaSSH --> PushMirror
GiteaSSH --> WebhookTrigger
end
subgraph ServerHost["3. Homeserver Host (192.168.1.36)"]
WebhookDaemon["systemd: homelab-gitops\n(webhook daemon :9000)"]
Dispatcher["gitops_dispatcher.py\n(payload resolver)"]
BrainVault["~/Brain\n(git pull --ff-only)"]
WebhookTrigger --> WebhookDaemon --> Dispatcher --> BrainVault
end
subgraph Presentation["4. Consumer & Presentation Layer"]
Doc2Site["homelab-doc2site\n(FastAPI / reactive watcher)"]
PublicDocs["https://docs.roadtotech.me\n(Traefik + Authelia / Public)"]
BrainVault --> Doc2Site --> PublicDocs
end
PostHook -->|git push| GiteaSSH
🔍 Detailed Pipeline Stages
1. Local Workstation Hooks (.githooks/)
The repository uses native Git hooks located in .githooks/ (configured via git config core.hooksPath .githooks):
-
pre-commit: Executesscripts/validate-brain.pybefore finalizing any commit. It enforces:- No deprecated directories (
notes/,scratch/, etc.). - Required root files (
README.md,AGENTS.md,flake.nix, etc.). - Frontmatter schema (
type,status,topics,tags,project). - Relative link validation (all markdown links resolve to real files).
- Markdown code fence balance.
- Mermaid diagram validation (syntax balance, node label quoting).
- Ruff code linting (Python solutions & scripts).
- Pyright static type checking (strict typing standards).
- Inbox Curation Exemption (
inbox/*is intentionally skipped to preserve zero-friction drafting).
- No deprecated directories (
-
post-commit: Synchronously pushes the current branch toorigin:CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) git push origin "$CURRENT_BRANCH"It includes offline detection and detached HEAD guards so commits never fail if network connectivity is temporarily unavailable.
2. Gitea Actions CI (act_runner)
When commits reach Gitea, Gitea Actions triggers .gitea/workflows/validate.yaml:
name: Brain Structural Validation
on:
push:
branches: ["**"]
pull_request:
jobs:
validate:
name: Validate Markdown Structure & Links
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Run Brain Validator
run: python3 scripts/validate-brain.py
- Execution Engine: Handled by the
homelab-runnercontainer runninggitea/act_runner:latestwith theubuntu-latest:docker://node:18-bullseyelabel. - Fail-Safe: If a broken link or syntax defect ever bypassed local checks, the CI status immediately flags the commit in Gitea.
3. Gitea Webhook & Host Dispatcher
Upon push completion, Gitea delivers an HTTP POST event to the server's internal webhook daemon:
- Endpoint:
http://192.168.1.36:9000/hooks/deploy - Payload: Gitea JSON push payload detailing repository name (
second-brain), branch (refs/heads/main), and commit SHAs.
The server's systemd unit (homelab-gitops) pipes this payload directly into homelab-core/scripts/gitops_dispatcher.py:
gitops_dispatcher.pyidentifiessecond-brainas a core data vault.- It resolves the vault target directory to
~/Brain. - It runs
git pull --ff-only origin mainin the background. - Total execution time from local
git committo server synchronization is typically under 1.5 seconds.
4. Consumer API & Live Presentation (doc2site)
- The documentation rendering service (
homelab-doc2site) runs in Docker and mounts~/Braindirectly into its container filesystem. - Because
git pulldirectly updates the underlying markdown files on the server host,doc2siteserves the updated knowledge graph immediately upon HTTP request without needing a container rebuild, restart, or cache purge. - The web portal is accessible at
https://docs.roadtotech.me.
5. GitHub Hot Mirroring
Gitea maintains an automated push mirror to GitHub (github.com/kiskaadee/second-brain):
- Trigger: Every push event on Gitea immediately triggers an upstream mirror sync.
- Purpose: Provides an off-site, immutable disaster-recovery backup while keeping self-hosted Gitea as the primary source of truth.
🛠️ Verification & Diagnostic Runbook
| Step | Action | Expected Output |
|---|---|---|
| 1. Local Commit | git commit -m "docs: test update" |
Pre-commit passes 9 checks, post-commit auto-pushes to port 2223 |
| 2. Gitea Webhook | Repository \rightarrow Settings \rightarrow Webhooks \rightarrow Test Delivery |
HTTP 200 Deployment payload dispatched successfully. |
| 3. Server Pull | ssh server-remote "cd ~/Brain && git status" |
Your branch is up to date with 'origin/main'. |
| 4. Live Web View | Open https://docs.roadtotech.me |
Edited content appears immediately |
| 5. CI Status | Repository \rightarrow Actions tab in Gitea |
Pipeline Brain Structural Validation green (✓) |
🏛️ Related References & Incident Post-Mortems
- GitOps Dispatcher Webhook Signature Mismatch: Epistemic Root Cause Analysis — Detailed investigation into
adnanh/webhookpayload serialization divergence and HMAC signature verification.