docs(homelab): update Gitea sync and CI/CD architecture guide
- Document curation boundary, local hooks and push mirror topology - Add deployment guide for Gitea act_runner via Docker and NixOS
This commit is contained in:
1 parent
d0e0c05605
commit
6be60e6b29
1 file changed
+110
-77
@@ -6,109 +6,142 @@ tags:
|
||||
- brain
|
||||
- sync
|
||||
- gitops
|
||||
- cicd
|
||||
- homelab
|
||||
---
|
||||
# 🧠 Real-Time Brain Synchronization & Gitea Push Mirroring
|
||||
|
||||
# 🧠 Real-Time Brain Synchronization, CI/CD & Gitea Push Mirroring
|
||||
|
||||
## 🎯 Motivation & Objectives
|
||||
The **Brain** repository (`~/Brain`) represents an actively edited knowledge vault (notes, architectural plans, daily learnings) accessed via Obsidian on client workstations (laptop) and served live to `https://docs.roadtotech.me` via `homelab-doc2site`.
|
||||
The **Brain** repository (`~/Brain`) is an actively edited, durable personal knowledge graph. It is accessed locally (via CLI, agents, and Obsidian) and served live to `https://docs.roadtotech.me` via `homelab-doc2site`.
|
||||
|
||||
### Key Challenges & Invariants:
|
||||
1. **Zero CI/CD & Rate-Limit Overhead**: Standard GitHub Actions pipelines consume build minutes, hit quota limits, and take minutes to deploy. Note edits must appear in seconds without triggering remote CI runners.
|
||||
2. **Instant Local Reflection**: `homelab-doc2site` dynamically reads from disk on every HTTP request. As soon as changes land on the server host in `/home/kiskaadee/Brain`, they are visible on `docs.roadtotech.me` with zero container rebuilds.
|
||||
3. **Automated Cloud Backup**: Edits must be backed up offsite to GitHub automatically without manual multi-remote pushes.
|
||||
### Core Pipeline Invariants:
|
||||
1. **The Curation Boundary**: Raw thoughts and scratch captures stay in `inbox/` (uncommitted, unvalidated, zero-friction). Once moved to their semantic home (`knowledge/`, `projects/`, `records/`, `practice/`), they join the committed graph.
|
||||
2. **Local Schema Integrity Gate**: Every commit is verified locally by [`scripts/validate-brain.py`](../../../../scripts/validate-brain.py) via a `pre-commit` hook to ensure valid metadata and prevent broken relative links.
|
||||
3. **Instant Zero-Delay Auto-Push**: A resilient `post-commit` hook automatically pushes commits to the primary self-hosted Gitea forge (`gitea.roadtotech.me`), falling back gracefully if offline.
|
||||
4. **Automated Cloud Replication**: Gitea natively push-mirrors every commit to GitHub (`github.com/kiskaadee/second-brain`) immediately on receive.
|
||||
5. **Server-Side CI & Observability**: Gitea Actions validates graph health on every push asynchronously without blocking editing or live rendering.
|
||||
|
||||
---
|
||||
|
||||
## 🏛️ End-to-End GitOps Architecture
|
||||
## 🏛️ End-to-End Architecture
|
||||
|
||||
```
|
||||
┌────────────────────────┐
|
||||
│ Laptop (Author) │
|
||||
│ (Obsidian / Markdown) │
|
||||
└───────────┬────────────┘
|
||||
│ (Auto Git Push over HTTPS)
|
||||
```text
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ LOCAL WORKSTATION (~/Brain) │
|
||||
│ │
|
||||
│ [inbox/] (Uncommitted staging, raw capture) │
|
||||
│ │ │
|
||||
│ (Curate: move to knowledge/, projects/, records/) │
|
||||
│ ▼ │
|
||||
│ git commit │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ .githooks/pre-commit ────(Invalid)────► [Abort commit] │
|
||||
│ │ (Valid) │
|
||||
│ ▼ │
|
||||
│ Commit created │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ .githooks/post-commit ───► git push origin <branch> │
|
||||
└──────────────────────────────────────┬──────────────────────┘
|
||||
│ (HTTPS / SSH)
|
||||
▼
|
||||
┌────────────────────────┐
|
||||
│ Self-Hosted Gitea │
|
||||
│ (gitea.roadtotech.me) │
|
||||
└───────────┬────────────┘
|
||||
│
|
||||
┌───────────────────────┴───────────────────────┐
|
||||
│ [Push Mirror (Auto Cloud Backup)] │ [Server Host Sync Pull]
|
||||
▼ ▼
|
||||
┌───────────────────────────────┐ ┌───────────────────────────────┐
|
||||
│ GitHub Remote (Offsite) │ │ Server Systemd Service/Timer │
|
||||
│ (github.com/kiskaadee/Brain) │ │ (brain-sync.timer / pull) │
|
||||
└───────────────────────────────┘ └───────────────┬───────────────┘
|
||||
▼
|
||||
┌───────────────────────────────┐
|
||||
│ Server Host: ~/Brain │
|
||||
│ (Mounted to doc2site) │
|
||||
└───────────────┬───────────────┘
|
||||
▼
|
||||
┌───────────────────────────────┐
|
||||
│ Live docs.roadtotech.me (0s) │
|
||||
└───────────────────────────────┘
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ SELF-HOSTED GITEA (gitea.roadtotech.me) │
|
||||
│ │
|
||||
│ Primary Forge receives new HEAD │
|
||||
│ ├── 1. Push Mirror ──────────────► GitHub (Cloud Backup) │
|
||||
│ ├── 2. Gitea Actions (CI) ───────► act_runner validation │
|
||||
│ └── 3. doc2site Sync / Render ───► docs.roadtotech.me │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Validated Test Results
|
||||
## ⚙️ Component Details
|
||||
|
||||
A full end-to-end integration test was executed using a test repository (`testing-repo`):
|
||||
1. **Local Push**: Laptop pushed commits over HTTPS to `https://gitea.roadtotech.me/kiskaadee/testing-repo.git`.
|
||||
2. **Gitea Push Mirror**: Configured with GitHub Classic Personal Access Token (`ghp_...`) and `repo` scope.
|
||||
3. **SHA Parity**: Verified identical commit hashes (`38285c4`) mirrored to `https://github.com/kiskaadee/testing-repo` instantaneously.
|
||||
### 1. Local Git Hooks (`.githooks/`)
|
||||
|
||||
---
|
||||
The repository maintains version-controlled hooks in `.githooks/`:
|
||||
|
||||
## ⚙️ Implementation Guide
|
||||
* **`pre-commit`**: Validates repository structure, required root files, YAML frontmatter, and relative markdown links.
|
||||
* **`post-commit`**: Automatically runs `git push origin <current-branch>` with offline tolerance and detached-HEAD checks.
|
||||
|
||||
### 1. Configure Gitea Push Mirror (Web UI)
|
||||
1. Open Gitea repository $\rightarrow$ **Settings** $\rightarrow$ **Repository** $\rightarrow$ **Mirror Settings**.
|
||||
2. Add Push Mirror:
|
||||
- **Target Address**: `https://github.com/kiskaadee/<repo-name>.git`
|
||||
- **Authorization**: GitHub Username + Classic PAT (`ghp_...` with `repo` scope).
|
||||
- **Sync Trigger**: Enable *"Sync when commits are pushed"*.
|
||||
|
||||
### 2. Client-Side (Laptop) Automation
|
||||
On your laptop, configure automatic commit and push:
|
||||
* **Option A (Obsidian Git Plugin)**: Set auto-save / auto-commit interval to 5–10 minutes.
|
||||
* **Option B (Git Remote Configuration)**:
|
||||
#### Installation:
|
||||
Run the installer script anytime in a fresh clone:
|
||||
```bash
|
||||
cd ~/Brain
|
||||
git remote set-url origin https://gitea.roadtotech.me/kiskaadee/Brain.git
|
||||
bash scripts/install-hooks.sh
|
||||
```
|
||||
|
||||
### 3. Server-Side Automated Git Reconciliation (`brain-sync.timer`)
|
||||
A lightweight NixOS systemd timer runs periodically on the homelab host to pull upstream edits:
|
||||
---
|
||||
|
||||
### 2. Gitea Actions CI Workflow (`.gitea/workflows/validate.yaml`)
|
||||
|
||||
Runs server-side verification using standard Actions syntax
|
||||
|
||||
### 3. Setting Up Gitea Actions Runner (`act_runner`)
|
||||
|
||||
To enable CI execution on `gitea.roadtotech.me`:
|
||||
|
||||
#### Step A: Enable Actions in Gitea `app.ini`
|
||||
Ensure your Gitea configuration file (`app.ini`) includes:
|
||||
```ini
|
||||
[actions]
|
||||
ENABLED = true
|
||||
```
|
||||
Restart Gitea if this was just enabled.
|
||||
|
||||
#### Step B: Obtain Registration Token
|
||||
1. In Gitea, navigate to **Site Administration** $\rightarrow$ **Actions** $\rightarrow$ **Runners** (or Repository **Settings** $\rightarrow$ **Actions** $\rightarrow$ **Runners**).
|
||||
2. Click **Create new Runner** and copy the registration token (`<REGISTRATION_TOKEN>`).
|
||||
|
||||
#### Step C: Deploy `act_runner`
|
||||
|
||||
**Option 1: Docker Compose (Homelab Host)**
|
||||
```yaml
|
||||
version: "3.8"
|
||||
services:
|
||||
runner:
|
||||
image: gitea/act_runner:latest
|
||||
container_name: gitea-act-runner
|
||||
restart: always
|
||||
environment:
|
||||
- GITEA_INSTANCE_URL=https://gitea.roadtotech.me
|
||||
- GITEA_RUNNER_REGISTRATION_TOKEN=<REGISTRATION_TOKEN>
|
||||
- GITEA_RUNNER_NAME=homelab-docker-runner
|
||||
- GITEA_RUNNER_LABELS=ubuntu-latest:docker://node:18-bullseye,ubuntu-22.04:docker://node:18-bullseye
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- ./data:/data
|
||||
```
|
||||
|
||||
**Option 2: Declarative NixOS Module**
|
||||
```nix
|
||||
# Declarative Systemd Timer in NixOS
|
||||
systemd.services.brain-sync = {
|
||||
description = "Synchronize Brain markdown vault from Gitea";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "kiskaadee";
|
||||
WorkingDirectory = "/home/kiskaadee/Brain";
|
||||
ExecStart = "${pkgs.git}/bin/git pull --ff-only origin main";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.brain-sync = {
|
||||
description = "Trigger Brain sync every 2 minutes";
|
||||
timerConfig = {
|
||||
OnBootSec = "1min";
|
||||
OnUnitActiveSec = "2min";
|
||||
};
|
||||
wantedBy = [ "timers.target" ];
|
||||
services.gitea-actions-runner.instances."homelab-runner" = {
|
||||
enable = true;
|
||||
name = "homelab-nixos-runner";
|
||||
url = "https://gitea.roadtotech.me";
|
||||
tokenFile = "/run/secrets/gitea-runner-token";
|
||||
labels = [
|
||||
"ubuntu-latest:docker://node:18-bullseye"
|
||||
];
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4. Gitea Push Mirroring (GitHub Hot Backup)
|
||||
|
||||
Configured under repository **Settings** $\rightarrow$ **Repository** $\rightarrow$ **Push Mirrors**:
|
||||
* **Remote Address**: `https://github.com/kiskaadee/second-brain.git`
|
||||
* **Authorization**: GitHub Username + Classic Personal Access Token with `repo` scope.
|
||||
* **Sync Trigger**: *"Sync when commits are pushed"* enabled.
|
||||
|
||||
---
|
||||
|
||||
## 📄 Summary of Benefits
|
||||
* ⚡ **Instant**: Note changes render live upon page load on `docs.roadtotech.me`.
|
||||
* 🛡️ **Zero API / CI/CD Quotas**: Never consumes billable GitHub Actions minutes.
|
||||
* 📦 **Offsite Redundancy**: Gitea autonomously keeps GitHub in sync as a hot backup.
|
||||
* ⚡ **Zero-Friction Staging**: Uncommitted raw captures in `inbox/` never trigger validation failures.
|
||||
* 🛡️ **Guaranteed Knowledge Integrity**: Commits are validated before being finalized.
|
||||
* 🚀 **Zero-Delay Auto-Sync**: Commits push instantly to Gitea and mirror to GitHub.
|
||||
* 🔍 **Continuous Observability**: Server-side CI validates the entire knowledge graph on push.
|
||||
Reference in new issue
Block a user