Files
second-brain/projects/homelab/guides/appctl-git-sync-and-lifecycle.md
T
kiskaadee a1152d4075 docs(brain): add document metadata frontmatter
Add YAML frontmatter to all 54 retained markdown documents.
Frontmatter schema is type-specific — no universal status field.

Type contracts applied:
- knowledge: type + status (draft|stable) + topics
- project:   type + status (planned|active|paused|completed)
- plan:      type + status + project context
- guide:     type + project context (no lifecycle status)
- journal:   type + date (no status — journals are historical by definition)
- practice:  type + status (completed|active) + topics
- inbox:     type + created date

54 documents tagged across:
  knowledge/concepts/     (3)
  knowledge/technologies/ (7, including python/ subdirectory with 4)
  knowledge/methods/      (6)
  projects/homelab/       (1 overview + 6 plans + 6 guides)
  projects/magnetflix/    (1)
  projects/nekoweb/       (1)
  records/journal/        (7)
  practice/LeetCode/      (14)
  inbox/                  (1)
2026-09-05 21:49:17 -05:00

86 lines
4.2 KiB
Markdown

---
type: guide
project: homelab
---
# 🔄 appctl Git Synchronization & Full-Stack Lifecycle Strategy
## 🎯 Motivation & Rationale
In a decentralized homelab architecture where [`~/Core`](file:///home/kiskaadee/Core) and every application stack in [`~/Sites`](file:///home/kiskaadee/Sites) are independent Git repositories:
1. **Prevent Configuration Drift**: Developers frequently push edits (compose labels, `app.yaml` metadata, Dockerfile changes) from laptops or secondary workstations. The production server needs instant visibility into repositories that are behind remote (`git pull` needed) or ahead of remote (`git push` pending).
2. **Prevent Forgotten Uncommitted State**: Dirty working trees on production need to be surfaced prominently to avoid accidental overwrites or uncommitted production hotfixes.
3. **Atomic Stack Updates (`appctl update`)**: Provide a single command that pulls Git repository changes, pulls new Docker container images, recreates the stack, and synchronizes the Homepage dashboard.
---
## 🏛️ Architecture & Display Schema
### 1. Enhanced `appctl list` Table Format
`appctl list` includes a dedicated `GIT / SYNC` column alongside runtime container health:
```text
SERVICE STATUS GIT SYNC DOMAIN DIRECTORY
------- ------ -------- ------ ---------
dashboard 🟢 Running (2) ⬆ 1 Ahead dashboard.roadtotech.me ~/Sites/homelab-dashboard
docs 🟢 Running (1) ✓ Synced docs.roadtotech.me ~/Sites/homelab-doc2site
excalidraw 🟢 Running (2) ✓ Synced excalidraw.roadtotech.me ~/Sites/homelab-excalidraw
gitea 🔴 Stopped ⬇ 1 Behind gitea.roadtotech.me ~/Sites/homelab-gitea
jellyfin 🟢 Running (1) ✓ Synced jellyfin.roadtotech.me ~/Sites/homelab-jellyfin
...
```
### 2. Status Badge Legend
* `✓ Synced`: Local branch is clean and fully in sync with upstream.
* `⬆ N Ahead`: Local branch has `N` unpushed commits.
* `⬇ N Behind`: Remote tracking branch has `N` new commits ready to pull.
* `⚡ Diverged (NA NB)`: Local and remote branches have diverged.
* `* Dirty`: Working directory has uncommitted or modified files (e.g. `✓ Synced *`, `⬆ 1 *`).
* `⚪ Untracked`: No upstream remote branch configured.
### 3. Execution Performance Model
* **Instant Local Mode (Default)**: `appctl list` executes instant local Git rev-list checks against existing tracking branches (`HEAD` vs `@{upstream}`), completing in milliseconds.
* **Live Network Mode (`--fetch` / `-f`)**: `appctl list --fetch` performs concurrent, background `git fetch` across repositories before evaluating status.
---
## 🚀 Commands & Workflows
### 1. `appctl list [--fetch] [--core]`
- `appctl list`: Lists all apps with container and local Git sync status.
- `appctl list --fetch` (or `-f`): Fetches remote refs first to report real-time upstream changes.
- `appctl list --core` (or `-c` / `--all`): Includes Core infrastructure services and the `Core` repository Git sync status.
### 2. `appctl info <service>`
Includes detailed Git repository diagnostics:
```text
Git Repository:
Branch: main
Upstream: origin/main
Sync Status: ⬆ 1 Ahead (1 unpushed commit)
Working Tree: Clean
```
### 3. Full Stack Upgrade (`appctl update <service>`)
Executes an atomic 5-step upgrade pipeline:
```mermaid
flowchart LR
A["Check Clean Worktree"] --> B["git pull --ff-only"]
B --> C["docker compose pull"]
C --> D["docker compose up -d"]
D --> E["appctl sync\n(Update Dashboard)"]
```
```bash
# Update a single application stack
appctl update docs
# Update all running application stacks
appctl update --all
```
---
## 🔒 Safety & Error Handling Rules
1. **Safety First on Pulls**: `appctl update` uses `git pull --ff-only`. If merge conflicts or diverging histories exist, execution halts immediately with a clear error prompt rather than corrupting repository state.
2. **Dirty Tree Protection**: If uncommitted local edits are present in an app repo, `appctl update` warns the user and aborts unless `--force` is explicitly provided.