Skip to content

w7-mgfcode/w7-base

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

W7-Base

Local-first orchestration & GitOps platform built on Docker Compose and a unified w7 CLI. PaaS-grade ergonomics without leaving the terminal β€” designed for developers and homelab operators.

Platform Stack CLI GitOps Secrets Status License CI


What is W7-Base?

W7-Base is a directory-driven monorepo that standardizes Docker Compose deployments across four isolated zones (@ops, @dev, @prod, @lab) and exposes them through a single ergonomic CLI: w7. It bundles GitOps automation, SOPS-encrypted secrets, Traefik ingress, observability, and policy enforcement β€” all running entirely on your local machine or a small VPS.

Built for:

  • Developers running multiple compose stacks who are tired of typing docker compose -f ... --env-file ....
  • Homelab operators who want PaaS-style discoverability without Kubernetes.
  • Teams that want GitOps discipline (push β†’ deploy) on a single host, with no cloud dependency.

Not built for:

  • Multi-host orchestration (use Kubernetes/Swarm).
  • Production cloud deployments.
  • Stateless ephemeral workloads (it's local-first, persistent-volume oriented).

🚦 Current Development State

Area Status Notes
Platform baseline (zones, CLI, GitOps, secrets, observability) βœ… Sealed at Slice 21 All 23 documentation slices verified
@ops services (9 stacks) βœ… Operational Gitea, Traefik, Webhook, Prometheus, Grafana, Node Exporter, W7 Exporter, Dozzle, Act-Runner
@dev/anythingllm (LLM workspace) βœ… Deployed Postgres + Qdrant + Gemini, SOPS-encrypted secrets
@lab/ll-KNOWRAG (KB/RAG sub-project) πŸ”„ Phase 7 sealed β†’ Phase 8 pivot in-flight See Β§ KNOWRAG
@prod/whoami βœ… Validation workload Pre-prod gate verified

πŸ“ Active focus: @lab/ll-KNOWRAG is mid-pivot from Supabase/PostgREST to Gitea + Qdrant as the storage backend. Phase 7 (UI/Backend parity, recursive crawling, reranking) is sealed; Phase 8 (re-architecture) is the next planned slice.


πŸš€ Quick Start

Prerequisites: bash (or zsh), docker, docker-compose-plugin, tar. Optional: age and sops for encrypted secrets.

# 1. Clone
git clone https://github.com/w7-mgfcode/w7-base.git ~/w7-base
cd ~/w7-base

# 2. Activate shell integration (adds `w7` CLI, zone aliases, `w7 go` cwd-jump)
echo 'source ~/w7-base/.shared/w7.sh' >> ~/.bashrc
source ~/.bashrc

# 3. Verify
w7 stat        # Cross-zone health matrix
w7 doctor      # Validate host dependencies, DNS, contracts

You'll see the W7-Base health matrix showing all stacks across all zones.


πŸ—οΈ Architecture

~/w7-base/
β”œβ”€β”€ @ops/             Core platform (Gitea, Traefik, Prometheus, Grafana, ...)
β”œβ”€β”€ @dev/             Active development stacks
β”œβ”€β”€ @prod/            Production-grade local stacks (gated)
β”œβ”€β”€ @lab/             Sandboxes & experiments (only zone where `prune` is allowed)
β”œβ”€β”€ .shared/          Global env bridge, policies, deploy templates
β”œβ”€β”€ .bin/             Vendored CLI: w7, sops, age
└── docs/             Platform documentation

The Strict Stack Contract

A stack is any directory exactly one level deep inside a zone that contains a .w7-meta file:

@dev/my-app/
β”œβ”€β”€ .w7-meta          YAML β€” GitOps routing, dependencies, health checks
β”œβ”€β”€ compose.yml       Standard Docker Compose definition
β”œβ”€β”€ data/             Persistent volumes (target of `w7 backup`)
β”œβ”€β”€ .env.example      Required-secret schema (committed)
β”œβ”€β”€ .env              Real secrets (NEVER committed)
└── .env.sops         SOPS+AGE encrypted secrets (safe to commit)

The CLI auto-injects COMPOSE_PROJECT_NAME="<zone>-<stack>" (e.g., dev-my-app) before invoking Docker so identical stacks across zones don't collide.

Zone Lifecycle Policy

Zone Trust GitOps prune allowed up requires --yes
@ops High Webhook + Actions ❌ ❌
@dev Med Webhook (instant) ❌ ❌
@prod Highest Actions only (approval-gated) ❌ βœ…
@lab Low Webhook (instant) βœ… ❌

πŸ› οΈ The w7 CLI

Command Description
w7 up <stack|all> Start stack(s) β€” merges .shared/global.env and stack .env; all boots @ops first
w7 down <stack|all> Stop stack(s) β€” all stops application zones first, @ops last
w7 init <@zone/stack> Scaffold a new stack with the standard contract
w7 doctor [--json] Validate dependencies, DNS, secret coverage, policy compliance
w7 stat O(1) cross-zone status matrix
w7 top / stats Live per-zone resource visibility
w7 logs <stack> Tail logs (preserves Docker ANSI colors)
w7 go <stack> cd shell to stack path (requires .shared/w7.sh sourced)
w7 net Port-mapping visibility
w7 backup <stack> Tar.gz of data/ (excludes .env to prevent secret leakage)
w7 prune <stack> Destroy containers + networks + volumes β€” @lab only
w7 secret <init|edit|decrypt> <stack> SOPS+AGE secret management

🌍 Environment Bridge

W7-Base layers env files instead of duplicating them. CLI runs:

docker compose --env-file .shared/global.env --env-file .env up -d

Precedence (highest wins):

  1. Host OS exported variables
  2. Stack-local .env
  3. Global bridge .shared/global.env (no secrets here β€” committed)

Use ${REQUIRED_KEY:?error msg} in compose.yml for fail-fast on missing vars.


πŸ” Secret Management β€” Three-File Model

File Committed? Purpose
.env.example βœ… Yes Schema (key names + placeholders)
.env ❌ Never Real values, runtime only
.env.sops βœ… Yes (encrypted) AGE-encrypted .env, GitOps-safe

Auto-decrypt: w7 up decrypts .env.sops β†’ .env automatically when the encrypted file is newer and sops is installed.

age-keygen -o ~/.config/sops/age/keys.txt    # Generate key
# Paste public key into root .sops.yaml
w7 secret init @ops/gitea                     # Encrypt existing .env
w7 secret edit @ops/gitea                     # Edit encrypted secrets

Full guide: .shared/SECRETS.md


πŸ”„ GitOps β€” Hybrid Model

Path Trigger Use For Approvals
Webhook (@ops/webhook) Instant push (HMAC-signed) @dev, @lab None β€” speed over ceremony
Runner (@ops/act-runner) Gitea Actions (push, PR, schedule, manual) @ops, @prod Branch protection + required reviews

The webhook flow: push β†’ HMAC verify β†’ git pull β†’ docker compose config validation β†’ w7 up. Failed validation rolls back the commit; the running stack stays untouched.

Full design: .shared/GITOPS_DESIGN.md

Gitea Actions workflows

The repo ships with ready-to-run workflows for the local @ops/act-runner:

File Purpose
.gitea/workflows/validate.yaml docker compose config across every stack + run all .shared/policy/*.sh checks. Triggered on push/PR.
.gitea/workflows/deploy.yaml Discovers stacks changed in the push, runs w7 up on each (skips @prod β€” that path requires manual approval).
.shared/workflows/deploy-template.yaml Reference template for stacks that want their own per-repo deploy pipeline.

GitHub Actions equivalents (.github/workflows/ci.yaml, lint.yaml) run the same compose + policy + ShellCheck/yamllint validation on PRs.


🌐 Ingress β€” Traefik

All HTTP services route through Traefik on the w7-ingress external Docker network. Default hostnames (add to /etc/hosts):

Service URL
Traefik dashboard http://localhost:8080
Gitea http://git.w7.local
Webhook listener http://webhook.w7.local
Dozzle (logs) http://logs.w7.local
Prometheus http://prom.w7.local
Grafana http://grafana.w7.local
# /etc/hosts
127.0.0.1 git.w7.local webhook.w7.local logs.w7.local prom.w7.local grafana.w7.local

πŸ“Š Observability

Built-in Prometheus + Grafana + custom W7-aware exporter:

  • @ops/prometheus β€” scrapes node-exporter + w7-exporter
  • @ops/grafana β€” dashboards (default login: admin / admin)
  • @ops/node-exporter β€” host metrics
  • @ops/w7-exporter β€” translates w7 doctor --json + w7 stat into Prometheus metrics
  • @ops/dozzle β€” real-time container log streaming

Custom metrics exposed:

  • w7_healthy β€” global system health (1/0)
  • w7_error_count, w7_warning_count β€” doctor results
  • w7_containers_up{zone} β€” per-zone container counts
  • w7_policy_violation{zone, stack, policy} β€” automated policy enforcement failures

πŸ›‘οΈ Policy Enforcement

Static checks under .shared/policy/ run during w7 doctor:

  • prod-privileged.sh β€” blocks privileged: true in @prod
  • prod-no-root-mount.sh β€” blocks host / or /etc mounts in @prod
  • zone-ingress-naming.sh β€” enforces *.w7.local naming convention

πŸ§ͺ KNOWRAG β€” Knowledge Base & RAG sub-project

@lab/ll-KNOWRAG is an in-flight local-first KB+RAG system extracted from Archon. It ingests websites/documents, chunks and embeds content, and exposes retrieval via FastAPI, FastMCP, and a React UI.

Phase 7 (sealed):

  • βœ… Recursive crawling with depth limits
  • βœ… llms.txt task expansion
  • βœ… Crawl4AI integration with httpx fallback for JS-rendered pages
  • βœ… Provider-based reranking with lexical fallback
  • βœ… UI overhaul with backend parity
  • βœ… 6 dogfood-found UI/API issues fixed

Phase 8 (planned β€” re-architecture pivot):

  • πŸ”΄ Replace Supabase/PostgREST with Gitea + Qdrant (Git as artifact source-of-truth, Qdrant for semantic search)
  • πŸ”΄ Markdown frontmatter parser (tags, status, version, owner)
  • πŸ”΄ Git-webhook-driven Qdrant ingestion pipeline
  • πŸ”΄ Tailwind-based card-grid catalog UI
  • πŸ”΄ Open WebUI + MCP integration

See @lab/ll-KNOWRAG/.omg/state/taskboard.md for the full Phase 8 task plan.


πŸ“ Repository Layout

.
β”œβ”€β”€ @ops/             Platform services (9 stacks)
β”‚   β”œβ”€β”€ gitea/        Local Git server (mirror + Actions host)
β”‚   β”œβ”€β”€ traefik/      Reverse proxy + ingress
β”‚   β”œβ”€β”€ webhook/      GitOps deploy listener (HMAC-signed)
β”‚   β”œβ”€β”€ act-runner/   Gitea Actions runner
β”‚   β”œβ”€β”€ dozzle/       Real-time container logs
β”‚   β”œβ”€β”€ prometheus/   Metrics server
β”‚   β”œβ”€β”€ grafana/      Dashboards
β”‚   β”œβ”€β”€ node-exporter/ Host metrics
β”‚   └── w7-exporter/  Custom W7 β†’ Prometheus bridge
β”œβ”€β”€ @dev/             Development stacks
β”‚   β”œβ”€β”€ anythingllm/  LLM workspace + PG + Qdrant + SOPS secrets
β”‚   β”œβ”€β”€ skill-generator/ Claude skill builder (no compose stack)
β”‚   └── test-scaffold/ Init template fixture
β”œβ”€β”€ @prod/            Production-grade stacks
β”‚   └── whoami/       Pre-prod validation workload
β”œβ”€β”€ @lab/             Sandbox / experiments
β”‚   β”œβ”€β”€ ll-KNOWRAG/   KB + RAG system (Archon-derived)
β”‚   └── test-init/    Init template fixture
β”œβ”€β”€ .bin/             w7, sops, age (vendored)
β”œβ”€β”€ .shared/          Global env, policies, workflows, contract spec
β”œβ”€β”€ .claude/          Claude Code rules + skills (project instructions)
└── docs/             Platform documentation

πŸ“š Documentation Map

Operator-facing:

Platform docs (docs/):

Internal contracts (.shared/):


πŸš‘ Troubleshooting

Symptom Cause / Fix
w7 go says "directory not found" You're running .bin/w7 directly. source ~/w7-base/.shared/w7.sh to activate the shell wrapper.
w7 up @prod/... fails By design β€” @prod is gated. Use --yes to bypass interactively, or use the Gitea Actions path.
Webhook silently doesn't deploy Check w7 logs @ops/webhook. docker compose config validation failure auto-rolls-back the commit.
w7 doctor warns about SOPS Install age + sops and configure ~/.config/sops/age/keys.txt.
*.w7.local doesn't resolve Add the hostnames to /etc/hosts (see Β§ Ingress).

πŸ€– GitOps Attack Surface (read this)

The @ops/webhook and @ops/act-runner containers mount /var/run/docker.sock to execute w7 up. If compromised, this gives root-equivalent host access. Mitigations baked in:

  • HMAC-SHA256 signature verification on webhook payloads.
  • docker compose config pre-flight validation β€” rolls back the commit on failure.
  • Hard-blocked @prod deploys via the webhook path; @prod requires the Actions path with branch protection.

Never expose the webhook port (9000) or Gitea (3000) to the public internet without zero-trust overlays (Tailscale, Cloudflare Tunnel, etc.).


πŸ—ΊοΈ Roadmap

Feature Status
w7 init scaffolding engine βœ… Implemented
w7 doctor system validation βœ… Implemented
SOPS+AGE secret management βœ… Implemented
Webhook GitOps + HMAC βœ… Implemented
Gitea Actions / runner integration βœ… Implemented
Traefik ingress + *.w7.local βœ… Implemented
Prometheus + Grafana + W7 exporter βœ… Implemented
Policy enforcement (privileged, root-mount, naming) βœ… Implemented
Backup retention + restore βœ… Implemented
Interactive @prod approvals βœ… Implemented
KNOWRAG Phase 8 β€” Gitea+Qdrant pivot πŸ”΄ Planned (next slice)
Webhook audit logging πŸ“‹ Planned

🀝 Contributing

This is a personal homelab/operator framework first, but suggestions and patches are welcome. Conventions:

  • Commits: type(scope): description β€” types: feat, fix, docs, chore, refactor, test. See historical git log.
  • Stacks: Must follow the contract in .shared/W7-CONTRACT.md.
  • Secrets: Never commit .env. Use .env.example for the schema and .env.sops for encrypted values.
  • Policy: New @prod stacks must pass .shared/policy/*.sh checks.

πŸ“œ License

Released under the MIT License.


πŸ™ Acknowledgements

About

Local-first Docker Compose orchestration & GitOps platform with @ops/@dev/@prod/@lab zones, unified w7 CLI, SOPS-encrypted secrets, Traefik ingress, and built-in observability.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors