Compare commits
22
Commits
27fd03df59
...
5fc5ad8656
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fc5ad8656 | ||
|
|
619209fe4f | ||
|
|
246b5879d8 | ||
|
|
642ab32364 | ||
|
|
03b36b1b3a | ||
|
|
db1825832f | ||
|
|
2c8c7d969f | ||
|
|
22d3a649ea | ||
|
|
e0422a3795 | ||
|
|
c0cb71be2b | ||
|
|
2856c75092 | ||
|
|
f5e7c0b233 | ||
|
|
942bb1cc6d | ||
|
|
dd931a7c01 | ||
|
|
de7dcfc715 | ||
|
|
5f12e9e2a3 | ||
|
|
dc028934bd | ||
|
|
693733a324 | ||
|
|
90eed848e8 | ||
|
|
041d6d3434 | ||
|
|
d43848cf3b | ||
|
|
d119ca1ccd |
No files matched your search
@@ -1,13 +0,0 @@
|
||||
# DOMAIN AND DNS CONFIGURATION
|
||||
DOMAIN=yourdomain.com
|
||||
ACME_EMAIL=your-email@provider.com
|
||||
DYNU_API_KEY=your_dynu_api_key
|
||||
|
||||
# DOCKER CONFIGURATION
|
||||
DOCKER_API_VERSION=1.40
|
||||
|
||||
# AUTHELIA SECURITY SECRETS
|
||||
# Generate these using: openssl rand -hex 64
|
||||
AUTHELIA_SESSION_SECRET=session_secret_hex
|
||||
AUTHELIA_STORAGE_ENCRYPTION_KEY=storage_encryption_key_hex
|
||||
AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET=jwt_secret_hex
|
||||
@@ -0,0 +1 @@
|
||||
use flake
|
||||
@@ -9,12 +9,18 @@ on:
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: nixery.dev/shell/coreutils/git/nix/nodejs:latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Nix
|
||||
uses: DeterminateSystems/nix-installer-action@main
|
||||
- name: Configure Git Safe Directory & Nix Flakes
|
||||
run: |
|
||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||
mkdir -p ~/.config/nix
|
||||
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
|
||||
echo "build-users-group =" >> ~/.config/nix/nix.conf
|
||||
|
||||
- name: Run Architecture & Security Invariant Checks
|
||||
run: |
|
||||
|
||||
+2
-1
@@ -3,6 +3,8 @@
|
||||
.env.*
|
||||
secrets.txt
|
||||
backup.zip
|
||||
.envrc
|
||||
.direnv
|
||||
|
||||
# SSL / ACME Certificates & Keys
|
||||
config/letsencrypt/*
|
||||
@@ -47,4 +49,3 @@ __pycache__/
|
||||
# Local Bootstrap & Operational Scripts
|
||||
scripts/bootstrap_lldap_users.py
|
||||
scripts/bootstrap_*.py
|
||||
|
||||
@@ -18,7 +18,7 @@ The homelab ecosystem separates **ownership**, **runtime architecture**, and **c
|
||||
The system operates across four runtime layers:
|
||||
1. **Host Foundation**: Headless NixOS Linux, disk configuration, Docker daemon, systemd daemons, firewall rules, and in-memory secret files under `/run/secrets/`.
|
||||
2. **Edge Gateway**: Traefik (v3.6) reverse proxy terminating wildcard TLS (`*.roadtotech.me`) via Dynu DNS-01 Let's Encrypt validation.
|
||||
3. **Core Platform Services**: Central services in `docker-compose.yml` (Authelia SSO, LLDAP directory, Stalwart mail, SnappyMail, Homepage dashboard, Portainer, Dozzle, Watchtower, Diun, and socket-proxy).
|
||||
3. **Core Platform Services**: Central services in `docker-compose.yml` (Authelia SSO, LLDAP directory, Stalwart mail, SnappyMail, Homepage dashboard, Dozzle, Watchtower, Diun, and socket-proxy).
|
||||
4. **Workload Plane**: Independent application stacks in `~/Sites` connected to the platform over the `proxy-net` Docker network.
|
||||
|
||||
### 3. Cross-Cutting Orchestration
|
||||
@@ -49,7 +49,7 @@ The system operates across four runtime layers:
|
||||
│ Docker proxy-net │
|
||||
├───────────────────────────────┤
|
||||
│ • Core Services (Homepage, │
|
||||
│ Portainer, Dozzle, etc.) │
|
||||
│ Dozzle, etc.) │
|
||||
│ • Workload Apps (~/Sites/*) │
|
||||
└───────────────────────────────┘
|
||||
│
|
||||
@@ -74,7 +74,6 @@ The system operates across four runtime layers:
|
||||
| **`stalwart`** | `mail.roadtotech.me` | Mail Server (SMTP/IMAP/JMAP/Sieve) | Native / LLDAP |
|
||||
| **`snappymail`** | `webmail.roadtotech.me` | Webmail client connected to Stalwart | Native / Stalwart |
|
||||
| **`homepage`** | `dashboard.roadtotech.me` | Service portal & system dashboard | Authelia Guard |
|
||||
| **`portainer`** | `portainer.roadtotech.me` | Container management GUI (via socket-proxy) | Authelia Guard |
|
||||
| **`dozzle`** | `logs.roadtotech.me` | Container log viewer (via socket-proxy) | Authelia Guard |
|
||||
| **`watchtower`** | Internal | Automated container image updater | Internal Only |
|
||||
| **`diun`** | Internal | Container image update notifier | Internal Only |
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ This document outlines the security controls, container isolation rules, and ope
|
||||
* Direct container mounts of `/var/run/docker.sock` are restricted.
|
||||
* Only the dedicated `socket-proxy` container mounts `/var/run/docker.sock:ro`.
|
||||
* State-modifying and execution API endpoints are disabled in HAProxy (`POST=0`, `DELETE=0`, `BUILD=0`, `EXEC=0`, `COMMIT=0`, `CONFIGS=0`, `DISTRIBUTION=0`, `NODES=0`, `PLUGINS=0`, `SECRETS=0`, `SWARM=0`, `SYSTEM=0`).
|
||||
* Traefik, Portainer, and Dozzle query Docker metrics and metadata via `tcp://socket-proxy:2375` rather than direct socket mounts.
|
||||
* Traefik and Dozzle query Docker metrics and metadata via `tcp://socket-proxy:2375` rather than direct socket mounts.
|
||||
|
||||
### B. Identity & Access Management (`lldap` & `authelia`)
|
||||
* **Directory Service**: User accounts and group memberships are stored in LLDAP (`users.roadtotech.me`).
|
||||
|
||||
+23
-29
@@ -161,31 +161,6 @@ services:
|
||||
- "traefik.http.routers.authelia-red.entrypoints=web"
|
||||
- "traefik.http.routers.authelia-red.middlewares=https-redirect@docker"
|
||||
|
||||
portainer:
|
||||
image: portainer/portainer-ce:latest
|
||||
container_name: portainer
|
||||
restart: always
|
||||
command: -H tcp://socket-proxy:2375
|
||||
volumes:
|
||||
- portainer_data:/data
|
||||
networks:
|
||||
- socket-net
|
||||
- proxy-net
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
# Public (HTTPS)
|
||||
- "traefik.http.routers.portainer.rule=Host(`portainer.${DOMAIN}`)"
|
||||
- "traefik.http.routers.portainer.entrypoints=websecure"
|
||||
- "traefik.http.routers.portainer.tls=true"
|
||||
- "traefik.http.routers.portainer.tls.certresolver=myresolver"
|
||||
- "traefik.http.routers.portainer.middlewares=authelia-auth@docker"
|
||||
- "traefik.http.routers.portainer.service=portainer-svc"
|
||||
# Public (Redirect)
|
||||
- "traefik.http.routers.portainer-red.rule=Host(`portainer.${DOMAIN}`)"
|
||||
- "traefik.http.routers.portainer-red.entrypoints=web"
|
||||
- "traefik.http.routers.portainer-red.middlewares=https-redirect@docker"
|
||||
- "traefik.http.services.portainer-svc.loadbalancer.server.port=9000"
|
||||
|
||||
dozzle:
|
||||
image: amir20/dozzle:latest
|
||||
container_name: dozzle
|
||||
@@ -193,6 +168,10 @@ services:
|
||||
environment:
|
||||
- DOCKER_HOST=tcp://socket-proxy:2375
|
||||
- DOCKER_API_VERSION=${DOCKER_API_VERSION:-1.40}
|
||||
- DOZZLE_AUTH_PROVIDER=forward-proxy
|
||||
- DOZZLE_AUTH_LOGOUT_URL=https://auth.${DOMAIN}/logout
|
||||
volumes:
|
||||
- dozzle_data:/data
|
||||
networks:
|
||||
- proxy-net
|
||||
- socket-net
|
||||
@@ -227,19 +206,33 @@ services:
|
||||
container_name: diun
|
||||
restart: always
|
||||
command: serve
|
||||
depends_on:
|
||||
- socket-proxy
|
||||
- stalwart
|
||||
environment:
|
||||
- TZ=UTC
|
||||
- LOG_LEVEL=info
|
||||
- LOG_JSON=false
|
||||
- DIUN_WATCH_WORKERS=20
|
||||
- DIUN_WATCH_WORKERS=6
|
||||
- DIUN_WATCH_JITTER=30s
|
||||
- DIUN_WATCH_SCHEDULE=0 */6 * * *
|
||||
- DIUN_PROVIDERS_DOCKER=true
|
||||
- DIUN_PROVIDERS_DOCKER_ENDPOINT=tcp://socket-proxy:2375
|
||||
- DOCKER_API_VERSION=${DOCKER_API_VERSION:-1.40}
|
||||
- DIUN_PROVIDERS_DOCKER_WATCHBYDEFAULT=true
|
||||
- DIUN_PROVIDERS_DOCKER_APIVERSION=${DOCKER_API_VERSION:-1.40}
|
||||
- DIUN_NOTIF_MAIL_HOST=stalwart
|
||||
- DIUN_NOTIF_MAIL_PORT=465
|
||||
- DIUN_NOTIF_MAIL_USERNAME=notifier@${DOMAIN:-roadtotech.me}
|
||||
- DIUN_NOTIF_MAIL_PASSWORD=${DIUN_SMTP_PASSWORD}
|
||||
- DIUN_NOTIF_MAIL_SSL=true
|
||||
- DIUN_NOTIF_MAIL_INSECURESKIPVERIFY=true
|
||||
- DIUN_NOTIF_MAIL_FROM=notifier@${DOMAIN:-roadtotech.me}
|
||||
- DIUN_NOTIF_MAIL_TO=kiskaadee@${DOMAIN:-roadtotech.me}
|
||||
volumes:
|
||||
- ./config/diun:/data
|
||||
networks:
|
||||
- socket-net
|
||||
- proxy-net
|
||||
|
||||
stalwart:
|
||||
image: stalwartlabs/stalwart:v0.16.22
|
||||
@@ -284,7 +277,7 @@ services:
|
||||
depends_on:
|
||||
- stalwart
|
||||
volumes:
|
||||
- ./config/snappymail/data:/snappymail/data
|
||||
- ./config/snappymail/data:/var/lib/snappymail/_data_
|
||||
networks:
|
||||
- proxy-net
|
||||
labels:
|
||||
@@ -335,4 +328,5 @@ networks:
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
portainer_data:
|
||||
dozzle_data:
|
||||
|
||||
+1
-1
@@ -206,7 +206,7 @@ When `appctl` executes commands against a workload, environment variables are re
|
||||
|
||||
When `appctl sync` runs:
|
||||
1. `appctl_engine.py` reads all `~/Sites/*/app.yaml` files.
|
||||
2. Core services (`traefik`, `authelia`, `lldap`, `stalwart`, `snappymail`, `portainer`, `dozzle`) are assigned to `Core Infrastructure`.
|
||||
2. Core services (`traefik`, `authelia`, `lldap`, `stalwart`, `snappymail`, `dozzle`) are assigned to `Core Infrastructure`.
|
||||
3. Workload applications with `visible: true` are grouped by their `homepage.group` (ordered: `Core Infrastructure`, `Knowledge & Notes`, `Media & Productivity`, `Development & AI`, `Applications`).
|
||||
4. Custom icons matching files in `config/homepage/icons/` (SVG or PNG) are mapped to `/icons/<name>`.
|
||||
5. The compiled configuration is written to `config/homepage/services.yaml`.
|
||||
@@ -25,7 +25,7 @@ The runtime environment consists of four functional layers:
|
||||
┌────────────────────────────────────────────────────────────────────────┐
|
||||
│ 2. CONTROL & PLATFORM SERVICES (Core Compose Stack) │
|
||||
│ Authelia SSO · LLDAP Directory · Stalwart Mail · SnappyMail │
|
||||
│ Homepage Dashboard · Portainer · Dozzle · Watchtower · Diun │
|
||||
│ Homepage Dashboard · Dozzle · Watchtower · Diun │
|
||||
│ socket-proxy (Read-Only Docker API Barrier) │
|
||||
└───────────────────────────────────┬────────────────────────────────────┘
|
||||
│
|
||||
@@ -81,9 +81,8 @@ Orchestration coordinates operations across the runtime layers without being a r
|
||||
- Outbound mail relay configured to route through an external smart host (Brevo SMTP relay via SOPS secrets).
|
||||
* **`snappymail`**: Webmail client accessible at `webmail.roadtotech.me` routing to Stalwart.
|
||||
|
||||
### E. Portal & Observability (`homepage`, `portainer`, `dozzle`)
|
||||
### E. Portal & Observability (`homepage`, `dozzle`)
|
||||
* **`homepage`**: Service dashboard at `dashboard.roadtotech.me`. Synchronized from `app.yaml` manifests in `~/Sites` by `appctl sync`.
|
||||
* **`portainer`**: Container management interface at `portainer.roadtotech.me`, connecting to Docker through `socket-proxy`.
|
||||
* **`dozzle`**: Log viewing interface at `logs.roadtotech.me`, connecting through `socket-proxy`.
|
||||
|
||||
### F. Host Foundation & Daemons
|
||||
@@ -108,7 +107,7 @@ Homelab Core configures two bridge networks:
|
||||
│ │ • traefik (router) • authelia (sso) │ │
|
||||
│ │ • lldap (directory) • stalwart (mail) │ │
|
||||
│ │ • snappymail (webmail) • homepage (dashboard) │ │
|
||||
│ │ • portainer (management) • dozzle (logs) │ │
|
||||
│ │ • dozzle (logs) │ │
|
||||
│ │ • All User Workloads (~/Sites/*) │ │
|
||||
│ └──────────────────────────────┬───────────────────────────────┘ │
|
||||
│ │ │
|
||||
@@ -116,9 +115,8 @@ Homelab Core configures two bridge networks:
|
||||
│ │ socket-net (Bridge) │ │
|
||||
│ │ │ │
|
||||
│ │ • socket-proxy (HAProxy :2375) • traefik │ │
|
||||
│ │ • portainer • dozzle │ │
|
||||
│ │ • watchtower • diun │ │
|
||||
│ │ • homepage │ │
|
||||
│ │ • dozzle • watchtower │ │
|
||||
│ │ • diun • homepage │ │
|
||||
│ └──────────────────────────────┬───────────────────────────────┘ │
|
||||
│ │ (ro mount) │
|
||||
│ ▼ │
|
||||
|
||||
@@ -152,3 +152,24 @@ cat ~/.local/state/homelab/gitops/homelab-docs.status.json
|
||||
# Trigger a local manual deployment run
|
||||
python3 ~/Core/scripts/gitops_dispatcher.py --repo docs --branch main
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Pre-Merge CI Gating vs. Post-Merge CD Dispatcher
|
||||
|
||||
The continuous deployment engine operates strictly **downstream** of CI verification:
|
||||
|
||||
```
|
||||
[Developer / PR] ──► [Gitea Actions CI] ──► [Merge to main] ──► [Gitea Webhook] ──► [homelab-gitops] ──► [Deploy]
|
||||
(Ephemeral Container) (Host Daemon)
|
||||
```
|
||||
|
||||
1. **Pre-Merge CI Invariant (`.gitea/workflows/ci.yaml`)**:
|
||||
- Executes inside containerized `act_runner` environments using **pre-baked toolchain images** (`container: nixery.dev/shell/coreutils/git/nix/nodejs:latest`).
|
||||
- Runs hermetic validation (`nix flake check`, `pytest`, `ruff`) with Git safe directory enforcement.
|
||||
- Prevents broken code, misconfigured flakes, or regression bugs from entering `main`.
|
||||
2. **Post-Merge CD Execution (`homelab-gitops.service`)**:
|
||||
- Triggers only after commits are admitted into `main`.
|
||||
- Executes non-shell allowlisted actions (`git_pull`, `compose_up`) on the server host.
|
||||
- Operates fully decoupled from the CI runner runtime.
|
||||
|
||||
+2
-2
@@ -51,7 +51,7 @@ docker system prune -a --volumes --filter "until=168h"
|
||||
Homelab Core runs several platform services managed by systemd:
|
||||
|
||||
### `homeserver-core.service` (Core Compose Stack)
|
||||
Manages the lifecycle of Traefik, Authelia, LLDAP, Stalwart, SnappyMail, Homepage, Portainer, Dozzle, Watchtower, and Diun.
|
||||
Manages the lifecycle of Traefik, Authelia, LLDAP, Stalwart, SnappyMail, Homepage, Dozzle, Watchtower, and Diun.
|
||||
|
||||
```bash
|
||||
# Check service status
|
||||
@@ -211,7 +211,7 @@ User accounts and group memberships are managed dynamically in **LLDAP** rather
|
||||
```
|
||||
|
||||
### C. Docker Socket Communication Errors
|
||||
* **Symptom**: Traefik fails to discover routers, or Dozzle/Portainer shows "Cannot connect to Docker daemon".
|
||||
* **Symptom**: Traefik fails to discover routers, or Dozzle shows "Cannot connect to Docker daemon".
|
||||
* **Diagnosis**:
|
||||
```bash
|
||||
# Verify socket-proxy is running and healthy
|
||||
|
||||
@@ -115,6 +115,6 @@ Homelab Core separates **user identity** from **static platform secrets**:
|
||||
| **Auth Database** | `~/Core/config/authelia/db.sqlite3` | ❌ No | Authelia session database |
|
||||
| **Mail Data & Keys** | `~/Core/config/stalwart/` | ❌ No | Stalwart mail storage, DKIM keys, mailboxes |
|
||||
| **Webmail Storage** | `~/Core/config/snappymail/data/` | ❌ No | SnappyMail configuration and sessions |
|
||||
| **Container Volumes** | Docker volume `portainer_data` | ❌ No | Portainer internal metadata |
|
||||
| **Container Volumes** | Docker volume `dozzle_data` | ❌ No | Dozzle UI preferences and state |
|
||||
| **DDNS History** | `/var/lib/dynu/ip_history.jsonl` | ❌ No | Historical WAN IP transitions log |
|
||||
| **GitOps State** | `~/.local/state/homelab/gitops/` | ❌ No | Deployment locks, pending JSONs, status logs |
|
||||
Generated
+7
-7
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1789006805,
|
||||
"narHash": "sha256-q+GdZ3yq4Y2LXHRK0vKTM32Hwy7RCgUgy+hjwZLI5pY=",
|
||||
"rev": "8ce4ef6cb6f871616146b9fe26d2a5ae594e94fe",
|
||||
"lastModified": 1790046670,
|
||||
"narHash": "sha256-OJe62m8gZx4xEAQnMcqH1u31/uu4Xf0q2ykAEHZfgrg=",
|
||||
"rev": "6774f7bc253789b113a4f39285dc0fa100abeacc",
|
||||
"type": "tarball",
|
||||
"url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1070770.8ce4ef6cb6f8/nixexprs.tar.zst"
|
||||
"url": "https://releases.nixos.org/nixos/unstable/nixos-26.11pre1077996.6774f7bc2537/nixexprs.tar.zst"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
@@ -26,11 +26,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1788914643,
|
||||
"narHash": "sha256-4GuMPW90JSxXWDPUB9M+1m7fYbe3H0apOd86/zBQ2Kw=",
|
||||
"lastModified": 1789890976,
|
||||
"narHash": "sha256-GKwH3zpy7tartuJMG0Rv/xUsdetG1QLmTVv8UKgJLmA=",
|
||||
"owner": "Mic92",
|
||||
"repo": "sops-nix",
|
||||
"rev": "13616fff713a9f94055c66f15687ebdc17a335df",
|
||||
"rev": "7214124c20c1542c90deb54af50e2f53ae02711f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -27,9 +27,12 @@
|
||||
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
python3
|
||||
python3Packages.pytest
|
||||
python3Packages.pyyaml
|
||||
(python3.withPackages (ps: with ps; [
|
||||
pyyaml
|
||||
types-pyyaml
|
||||
pytest
|
||||
]))
|
||||
pyright
|
||||
ruff
|
||||
];
|
||||
shellHook = ''
|
||||
|
||||
@@ -66,7 +66,12 @@
|
||||
};
|
||||
|
||||
# ── Virtualisation ───────────────────────────────────────────────────────────
|
||||
virtualisation.docker.enable = true;
|
||||
virtualisation.docker = {
|
||||
enable = true;
|
||||
daemon.settings = {
|
||||
dns = [ "1.1.1.1" "1.0.0.1" ];
|
||||
};
|
||||
};
|
||||
|
||||
# ── Dynamic binary support ───────────────────────────────────────────────────
|
||||
programs.nix-ld = {
|
||||
@@ -115,7 +120,9 @@
|
||||
sops
|
||||
age
|
||||
# Python runtime (hard requirement for appctl and gitops_dispatcher.py)
|
||||
python3
|
||||
python3.withPackages(ps: with ps; [
|
||||
pyyaml
|
||||
])
|
||||
# Modern shell utilities
|
||||
eza # ls replacement
|
||||
ripgrep # rg — fast grep
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"gitops/webhook_secret"
|
||||
"brevo/smtp_login"
|
||||
"brevo/smtp_key"
|
||||
"diun/smtp_password"
|
||||
] (name: { owner = "kiskaadee"; });
|
||||
|
||||
# Generate the unified environment file at runtime in /run/secrets/homeserver.env
|
||||
@@ -38,6 +39,7 @@
|
||||
SMTP_PORT = "587";
|
||||
SMTP_LOGIN = config.sops.placeholder."brevo/smtp_login";
|
||||
SMTP_KEY = config.sops.placeholder."brevo/smtp_key";
|
||||
DIUN_SMTP_PASSWORD = config.sops.placeholder."diun/smtp_password";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -79,7 +81,7 @@
|
||||
id = "deploy";
|
||||
execute-command = "/home/kiskaadee/Core/scripts/gitops_dispatcher.py";
|
||||
pass-arguments-to-command = [
|
||||
{ source = "entire-payload"; }
|
||||
{ source = "raw-request-body"; }
|
||||
{ source = "header"; name = "X-Gitea-Signature"; }
|
||||
{ source = "header"; name = "X-Gitea-Event"; }
|
||||
];
|
||||
|
||||
+4
-2
@@ -2,6 +2,8 @@ authelia:
|
||||
session_secret: ENC[AES256_GCM,data:TmujJ9I51cQrzRMcvFkhFnG1CICebOM332NUTwXSj33niFdrV3xfHWR3h83/WcNk+M/i0AjcFtZ7fRYNW5VV2766p2BAfsaihSN8yQPrsQRNPyQKvSgij2xWL/B5I1a7NQGRh7xX6yiQYqaPzrwKnlcv8kmKp8aFPlkdmWYOCPc=,iv:Pcj6yu1MvZBJ0VPfuEO4RiTiE5SOULI/jGAz8dy/X4g=,tag:firz8cjG9HP8HEgKM4c53Q==,type:str]
|
||||
storage_encryption_key: ENC[AES256_GCM,data:ycsfhh9cAsIbSEVaPvCH8ky0t+zayLtI6NVLcb+v2HIJMYSqD8eXu7JCvp5E0u1PkGTyaAoatXtcdChb2ABEiUNeqlOPXciF4ED+4yFAXftfMKy/M4AAYgp9jBA1v8JsE5mfBEOfmnBWV5SwGSaHBcQgUoJubKqcODPfHOmkKwg=,iv:1bgvgcClI+2VG6wXa5el5jfOrkCx+bj33VYiFdA1gas=,tag:0n7nJaZomtllFzSH2+Z8yw==,type:str]
|
||||
jwt_secret: ENC[AES256_GCM,data:C1FnoRi49PSaIZNp+SAS6Q5+odYwai75OR4UfvGx1Jk8wb4nVDUASpaOgm7ZFJysTX4WjuQi99PYyG5GshlHoJ5dVbLSFpEq7MSSiY8tZA2PqnHmIODNYARfFw6lB7udPjz8ANyU2UcrnwRKXnDD+T2Pa1uL9joW5rg7vWZlRks=,iv:IDZ2/wbmCPoR14b1imZrTJR5LuQp6V91tcZ/Z5Znl0w=,tag:d0UQ49QcEqgD+PCIBoOJ7Q==,type:str]
|
||||
diun:
|
||||
smtp_password: ENC[AES256_GCM,data:ED3NoQWxpuucfpGAiw==,iv:fWmHEnNr9r1OpgteTJwT8Z2iKn1WKPf8WudWWvBnvjA=,tag:MjVAN7IITEm+Og+3k/SGVg==,type:str]
|
||||
traefik:
|
||||
acme_email: ENC[AES256_GCM,data:U2IPYioGlfgSpfZy5E+2+VM0iXQ=,iv:zQ5Txq9H7mF7GcaZfyPPjSQFKa0736/DI7Y4XARMFqM=,tag:7Q4YN9OPA1rRVpXuapewQQ==,type:str]
|
||||
dynu:
|
||||
@@ -55,7 +57,7 @@ sops:
|
||||
yvBksdjSVYITIR6E6sZJx4ujk8Gmu64UsHwxtASMZRQ60sUjLCo8+A==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
recipient: age1pln9sxy5j93lklqklfwp3qepx7x4cs4y2w63n9y3ykt68qgra5ysqleesg
|
||||
lastmodified: "2026-09-15T19:45:16Z"
|
||||
mac: ENC[AES256_GCM,data:356RqShyhqaBM3Z1/Nz/ignvR6OYlUhASrCEBQ4aAR6Fkd4SMQVVEnvUuwn7mT1J5LJkB21NHnlKO/PHcqRdvB1HjFgwqIL31ZzT5ugWyVvz5PRg97wcYzwOqszNKQYWPVRRuMedgU2tFLMK9v1WAvUJnPf6upMHcliljldgFIg=,iv:Cl1TT61MegkA9Imo8WWKOTyUrYGrElc2D7WbAIvwHgs=,tag:e81/PgkCTTkKrN0jsRKn4Q==,type:str]
|
||||
lastmodified: "2026-09-25T00:49:38Z"
|
||||
mac: ENC[AES256_GCM,data:EyJ9V0aYo7isyqnW6HWBz4hD2X6xa+VRNg3TaK88gkX6YCG/H0htBfMf/VYl/hOA/eEZW+uMVys8Ocula9zpY1Pd1gUbWt5FrXQvooYNhtCFCFUAJdsrmif8Ru7AXazFbyhhaeBSBjSQURM0qi69XqllVvfmiSz32WlX/QIOZ/c=,iv:znmm8JuFKSFl2IGGhRG77SE9kqy3uFWUK8VjocJ18n4=,tag:tG000kt5a6W1fa0IEfvLLQ==,type:str]
|
||||
unencrypted_suffix: _unencrypted
|
||||
version: 3.13.3
|
||||
@@ -0,0 +1,2 @@
|
||||
[tool.pyright]
|
||||
extraPaths = ["scripts"]
|
||||
@@ -328,7 +328,6 @@ def get_core_services():
|
||||
{"name": "lldap", "domain": "users.roadtotech.me", "container": "lldap", "desc": "Lightweight LDAP User & Group Directory"},
|
||||
{"name": "stalwart", "domain": "mail.roadtotech.me", "container": "stalwart", "desc": "All-in-one Mail Server & JMAP/IMAP/SMTP"},
|
||||
{"name": "snappymail", "domain": "webmail.roadtotech.me", "container": "snappymail", "desc": "Modern Lightweight Webmail Client"},
|
||||
{"name": "portainer", "domain": "portainer.roadtotech.me", "container": "portainer", "desc": "Container Management GUI"},
|
||||
{"name": "dozzle", "domain": "logs.roadtotech.me", "container": "dozzle", "desc": "Real-time Log Viewer"},
|
||||
{"name": "socket-proxy", "domain": "internal", "container": "socket-proxy", "desc": "Docker Socket Security Proxy"},
|
||||
{"name": "homepage", "domain": "dashboard.roadtotech.me", "container": "homepage", "desc": "Application Dashboard & System Portal"},
|
||||
@@ -759,7 +758,6 @@ def cmd_sync_homepage(args):
|
||||
"lldap": {"title": "LLDAP Directory", "icon": "lldap.png", "weight": 25},
|
||||
"stalwart": {"title": "Stalwart Mail", "icon": "email.png", "weight": 26},
|
||||
"snappymail": {"title": "Webmail", "icon": "email.png", "weight": 27},
|
||||
"portainer": {"title": "Portainer", "icon": "portainer.png", "weight": 30},
|
||||
"dozzle": {"title": "Dozzle", "icon": "dozzle.png", "weight": 40},
|
||||
}
|
||||
for svc in get_core_services():
|
||||
|
||||
@@ -0,0 +1,353 @@
|
||||
import os
|
||||
import sys
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
# Dynamic Environment Paths
|
||||
CORE_DIR = os.environ.get(
|
||||
"CORE_DIR", os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
|
||||
)
|
||||
|
||||
SITES_DIR = os.environ.get(
|
||||
"SITES_DIR",
|
||||
os.path.join(os.path.dirname(CORE_DIR), "Sites")
|
||||
if os.path.isdir(os.path.join(os.path.dirname(CORE_DIR), "Sites"))
|
||||
else os.path.expanduser("~/Sites"),
|
||||
)
|
||||
|
||||
|
||||
HOMELAB_DOMAIN = os.environ.get("HOMELAB_DOMAIN") or os.environ.get("DOMAIN", "")
|
||||
|
||||
|
||||
def validate_environment() -> None:
|
||||
"""Ensure mandatory environment configuration is valid before CLI execution."""
|
||||
errors: list[str] = []
|
||||
|
||||
if not HOMELAB_DOMAIN:
|
||||
errors.append(
|
||||
"• Missing 'HOMELAB_DOMAIN' (or 'DOMAIN') environment variable.\n"
|
||||
" Please export it (e.g. export HOMELAB_DOMAIN='roadtotech.me') or set it in your environment file."
|
||||
)
|
||||
|
||||
if not os.path.isdir(CORE_DIR):
|
||||
errors.append(f"• Core directory not found at: {CORE_DIR}")
|
||||
|
||||
if errors:
|
||||
print("❌ Environment Validation Failed:\n", file=sys.stderr)
|
||||
for err in errors:
|
||||
print(f" {err}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
class ManifestError(Exception):
|
||||
pass
|
||||
|
||||
@dataclass
|
||||
class HomepageConfig:
|
||||
title: str
|
||||
group: str = "Applications"
|
||||
icon: str = "default.png"
|
||||
container: str = ""
|
||||
weight: int = 50
|
||||
|
||||
@dataclass
|
||||
class App:
|
||||
name: str # Canonical identified (e.g., "traefik", "jellyfin")
|
||||
description: str # Human-readable summary for dashboards and CLI info
|
||||
domain: str # Routing FQDN (e.g., "auth.roadtotech.me") or "internal".
|
||||
dir_path: str # Filesystem directory (CORE_DIR for Core, or ~/Sites/<app> for Sites).
|
||||
|
||||
@property
|
||||
def is_internal(self) -> bool:
|
||||
"""Returns True if the service does not expose a public TLS endpoint."""
|
||||
return not self.domain or self.domain == "internal" or self.domain.endswith(".local") or ":" in self.domain
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
"""Serialize for JSON consumption by scripts/appctl"""
|
||||
data = asdict(self)
|
||||
data["type"] = getattr(self, "app_type", "app")
|
||||
return data
|
||||
|
||||
@dataclass
|
||||
class CoreService(App):
|
||||
container: str = "" # Target container name inside Core's root docker-compose.yml (e.g., "authelia", "stalwart")
|
||||
weight: int = 50 # Homepage ordering weight (optional, for dashboard synchronization)
|
||||
icon: str = "default.png" # Dashboard icon filename
|
||||
app_type: str = "core_service"
|
||||
dir_path: str = CORE_DIR
|
||||
|
||||
@dataclass
|
||||
class SitesApp(App):
|
||||
dir_name: str = "" # directory name in ~/Sites (e.g., "homelab-vaultwarden")
|
||||
aliases: list[str] = field(default_factory=list) # CLI resolution aliases (e.g., "vw", "vaultwarden")
|
||||
visible: bool = True # Defines whether the icon is visible in the Homepage Dashboard
|
||||
auth: bool = True # Authelia protection guard indicator; Defaulting to True is safer
|
||||
has_compose: bool = False # Whether a docker-compose.yaml exists at ~/Sites/dir_name.
|
||||
networks: list[str] = field(default_factory=lambda: ["proxy-net"]) # Docker network attachments (def ["proxy-net"])
|
||||
env: dict[str, Any] = field(default_factory=dict) # Dynamic environment variable overrides
|
||||
homepage: HomepageConfig | None = None # Dashboard Card Configuration
|
||||
manifest_error: str | None = None # Captured syntax/loading errors if app.yaml was malformed/absent
|
||||
app_type: str = "app"
|
||||
|
||||
|
||||
|
||||
def load_manifest(manifest_path: str) -> dict[str, Any]:
|
||||
"""Load and parese the app manifest file
|
||||
|
||||
Raises:
|
||||
FileNotFoundError: if the manifest file does not exist.
|
||||
ValueError: if YAML object is malformed.
|
||||
TypeError: If root is not a directory
|
||||
"""
|
||||
if not os.path.isfile(manifest_path):
|
||||
raise FileNotFoundError(f"Manifest file not found at {manifest_path}")
|
||||
|
||||
try:
|
||||
with open(manifest_path, "r", encoding="utf-8") as file:
|
||||
manifest_data = yaml.safe_load(file) or {}
|
||||
except (yaml.YAMLError, OSError) as err:
|
||||
raise ManifestError(f"YAML parsing failed: {err}") from err
|
||||
|
||||
if not isinstance(manifest_data, dict):
|
||||
raise ManifestError(f"Invalid manifest root: expected `dict`, got `{type(manifest_data).__name__}`")
|
||||
|
||||
return manifest_data
|
||||
|
||||
|
||||
|
||||
def sites_app_from_manifest(
|
||||
|
||||
app_dir: str,
|
||||
manifest: dict[str, Any],
|
||||
manifest_error: str | None = None
|
||||
) -> SitesApp:
|
||||
"""Construct and normalize a SitesApp domain model from raw manifest data."""
|
||||
raw_dir_name = os.path.basename(app_dir)
|
||||
canonical_name = str(manifest.get("name") or raw_dir_name.replace("homelab-", ""))
|
||||
|
||||
# Normalize aliases into list[str]
|
||||
raw_aliases = manifest.get("aliases") or []
|
||||
if isinstance(raw_aliases, str):
|
||||
aliases = [raw_aliases]
|
||||
elif isinstance(raw_aliases, list):
|
||||
aliases = [str(alias) for alias in raw_aliases]
|
||||
else:
|
||||
aliases = []
|
||||
|
||||
# Homepage card normalization
|
||||
homepage_config: HomepageConfig | None = None
|
||||
raw_hp = manifest.get("homepage")
|
||||
if isinstance(raw_hp, dict):
|
||||
homepage_config = HomepageConfig(
|
||||
title=str(raw_hp.get("title") or canonical_name),
|
||||
group=str(raw_hp.get("group") or "Applications"),
|
||||
icon=str(raw_hp.get("icon") or "default.png"),
|
||||
container=str(raw_hp.get("container") or canonical_name),
|
||||
weight=int(raw_hp.get("weight", 50))
|
||||
)
|
||||
has_compose = (
|
||||
os.path.isfile(os.path.join(app_dir, "docker-compose.yaml")) or
|
||||
os.path.isfile(os.path.join(app_dir, "docker-compose.yml"))
|
||||
)
|
||||
|
||||
# Manifest Data parsing
|
||||
raw_desc = manifest.get("description")
|
||||
app_desc: str = str(raw_desc) if raw_desc is not None else ""
|
||||
|
||||
raw_dom = manifest.get("domain")
|
||||
app_dom = str(raw_dom) if raw_dom is not None else f"{canonical_name}.{HOMELAB_DOMAIN}"
|
||||
|
||||
app_net = manifest.get("networks")
|
||||
if not isinstance(app_net, list):
|
||||
app_net = ["proxy-net"]
|
||||
|
||||
app_env = manifest.get("env")
|
||||
if not isinstance(app_env, dict):
|
||||
app_env = {}
|
||||
|
||||
def _as_bool(value: Any, default: bool) -> bool:
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
return default
|
||||
|
||||
app_vis = _as_bool(manifest.get("visible"), True)
|
||||
app_auth = _as_bool(manifest.get("auth"), True)
|
||||
|
||||
return SitesApp(
|
||||
name=canonical_name,
|
||||
dir_name=raw_dir_name,
|
||||
description=app_desc,
|
||||
domain=app_dom,
|
||||
dir_path=app_dir,
|
||||
has_compose=has_compose,
|
||||
aliases=aliases,
|
||||
visible=app_vis,
|
||||
auth=app_auth,
|
||||
networks=app_net,
|
||||
env=app_env,
|
||||
homepage= homepage_config,
|
||||
manifest_error=manifest_error,
|
||||
)
|
||||
|
||||
|
||||
|
||||
def get_sites_apps(sites_dir: str | None = None) -> list[SitesApp]:
|
||||
"""
|
||||
Scan the given sites directory (defaulting to SITES_DIR) for application.
|
||||
"""
|
||||
target_dir = sites_dir or SITES_DIR
|
||||
apps: list[SitesApp] = []
|
||||
if not os.path.isdir(target_dir):
|
||||
return apps
|
||||
|
||||
for entry in sorted(os.listdir(target_dir)):
|
||||
app_dir = os.path.join(target_dir, entry)
|
||||
# skip hidden or null directories
|
||||
if entry.startswith(".") or not os.path.isdir(app_dir):
|
||||
continue
|
||||
manifest_path = os.path.join(app_dir, "app.yaml")
|
||||
manifest: dict[str, Any] = {}
|
||||
manifest_error: str | None = None
|
||||
|
||||
if os.path.isfile(manifest_path):
|
||||
try:
|
||||
manifest = load_manifest(manifest_path=manifest_path)
|
||||
except ManifestError as err:
|
||||
manifest_error = str(err)
|
||||
apps.append(sites_app_from_manifest(app_dir, manifest, manifest_error))
|
||||
|
||||
return apps
|
||||
|
||||
def resolve_app(
|
||||
query: str,
|
||||
apps: list[SitesApp] | None = None,
|
||||
sites_dir: str | None = None
|
||||
) -> SitesApp | None:
|
||||
|
||||
if apps is None:
|
||||
apps = get_sites_apps(sites_dir= sites_dir if sites_dir is not None else SITES_DIR)
|
||||
|
||||
query_clean = query.strip().lower()
|
||||
|
||||
# 1. Extract match on canonical name
|
||||
for app in apps:
|
||||
if app.name.lower() == query_clean:
|
||||
return app
|
||||
|
||||
# 2. Match on alias
|
||||
for app in apps:
|
||||
if any(alias.lower() == query_clean for alias in app.aliases):
|
||||
return app
|
||||
|
||||
# 3. Match directory name
|
||||
for app in apps:
|
||||
if app.dir_name.lower() == query_clean:
|
||||
return app
|
||||
# 4. Match stripped 'homelab-' prefix
|
||||
for app in apps:
|
||||
if app.dir_name.lower() == f"homelab-{query_clean}":
|
||||
return app
|
||||
|
||||
return None
|
||||
|
||||
def get_core_services(core_dir: str | None = None) -> list[CoreService]:
|
||||
"""Return the strongly-typed registry of Core platform services."""
|
||||
return [
|
||||
CoreService(
|
||||
name="traefik",
|
||||
domain=f"traefik.{HOMELAB_DOMAIN}",
|
||||
container="traefik",
|
||||
description="Edge Reverse Proxy & ACME TLS",
|
||||
icon="traefik.png",
|
||||
weight=10,
|
||||
),
|
||||
CoreService(
|
||||
name="authelia",
|
||||
domain=f"auth.{HOMELAB_DOMAIN}",
|
||||
container="authelia",
|
||||
description="Identity & SSO Access Control",
|
||||
icon="authelia.png",
|
||||
weight=20,
|
||||
),
|
||||
CoreService(
|
||||
name="lldap",
|
||||
domain=f"users.{HOMELAB_DOMAIN}",
|
||||
container="lldap",
|
||||
description="Lightweight LDAP User Directory",
|
||||
icon="lldap.png",
|
||||
weight=25,
|
||||
),
|
||||
CoreService(
|
||||
name="stalwart",
|
||||
domain=f"mail.{HOMELAB_DOMAIN}",
|
||||
container="stalwart",
|
||||
description="All-in-one Mail Server",
|
||||
icon="email.png",
|
||||
weight=26,
|
||||
),
|
||||
CoreService(
|
||||
name="snappymail",
|
||||
domain=f"webmail.{HOMELAB_DOMAIN}",
|
||||
container="snappymail",
|
||||
description="Modern Lightweight Webmail Client",
|
||||
icon="email.png",
|
||||
weight=27,
|
||||
),
|
||||
CoreService(
|
||||
name="portainer",
|
||||
domain=f"portainer.{HOMELAB_DOMAIN}",
|
||||
container="portainer",
|
||||
description="Container Management GUI",
|
||||
icon="portainer.png",
|
||||
weight=30,
|
||||
),
|
||||
CoreService(
|
||||
name="dozzle",
|
||||
domain=f"logs.{HOMELAB_DOMAIN}",
|
||||
container="dozzle",
|
||||
description="Real-time Log Viewer",
|
||||
icon="dozzle.png",
|
||||
weight=40,
|
||||
),
|
||||
CoreService(
|
||||
name="socket-proxy",
|
||||
domain="internal",
|
||||
container="socket-proxy",
|
||||
description="Docker Socket Security Proxy",
|
||||
),
|
||||
CoreService(
|
||||
name="homepage",
|
||||
domain=f"dashboard.{HOMELAB_DOMAIN}",
|
||||
container="homepage",
|
||||
description="Application Dashboard & System Portal",
|
||||
icon="homepage.png",
|
||||
weight=5,
|
||||
),
|
||||
CoreService(
|
||||
name="diun",
|
||||
domain="internal",
|
||||
container="diun",
|
||||
description="Docker Image Update Notifier",
|
||||
),
|
||||
CoreService(
|
||||
name="watchtower",
|
||||
domain="internal",
|
||||
container="watchtower",
|
||||
description="Automated Container Updates",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def get_docker_status(
|
||||
dir_path: str | Path,
|
||||
container_name: str | None = None
|
||||
) -> str:
|
||||
path: Path = Path(dir_path)
|
||||
def _do_something(path: Path = path):
|
||||
return ""
|
||||
return _do_something()
|
||||
|
||||
def cmd_sync_homepage(args) -> None:
|
||||
pass
|
||||
@@ -64,3 +64,16 @@ def test_no_shell_true_in_core_scripts():
|
||||
for py_file in scripts_dir.glob("*.py"):
|
||||
content = py_file.read_text(encoding="utf-8")
|
||||
assert "shell=True" not in content, f"shell=True detected in {py_file.name}!"
|
||||
|
||||
|
||||
def test_portainer_is_deprecated_and_absent():
|
||||
"""Ensure portainer service and volume are completely absent from core docker-compose."""
|
||||
compose_path = CORE_ROOT / "docker-compose.yml"
|
||||
with open(compose_path, encoding="utf-8") as f:
|
||||
compose = yaml.safe_load(f)
|
||||
|
||||
services = compose.get("services", {})
|
||||
assert "portainer" not in services, "Deprecated service 'portainer' must not exist in docker-compose.yml"
|
||||
|
||||
volumes = compose.get("volumes", {}) or {}
|
||||
assert "portainer_data" not in volumes, "Deprecated volume 'portainer_data' must not exist in docker-compose.yml"
|
||||
@@ -0,0 +1,190 @@
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
# Import appctl engine v2
|
||||
CORE_ROOT = Path(__file__).resolve().parent.parent.parent
|
||||
sys.path.insert(0, str(CORE_ROOT / "scripts"))
|
||||
|
||||
import appctl_engine_v2 as engine
|
||||
|
||||
|
||||
@dataclass
|
||||
class AppFactory:
|
||||
"""Helper class to generate mock app directories and configurations"""
|
||||
sites_dir: Path
|
||||
|
||||
def create(
|
||||
self,
|
||||
dir_name: str,
|
||||
manifest_yaml: str = "",
|
||||
has_compose: bool = True,
|
||||
) -> Path:
|
||||
app_dir: Path = self.sites_dir / dir_name
|
||||
app_dir.mkdir(parents=True, exist_ok=True)
|
||||
if manifest_yaml:
|
||||
(app_dir / "app.yaml").write_text(manifest_yaml, encoding="utf-8")
|
||||
if has_compose:
|
||||
(app_dir / "docker-compose.yml").write_text("services: {}\n", encoding="utf-8")
|
||||
return app_dir
|
||||
|
||||
@pytest.fixture
|
||||
def mock_sites_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
||||
"""Fixture that creates an isolated Sites directory and points engine.SITES_DIR to it"""
|
||||
sites = tmp_path / "Sites"
|
||||
monkeypatch.setattr(engine, "SITES_DIR", str(sites))
|
||||
monkeypatch.setattr(engine, "HOMELAB_DOMAIN", "mydomain.test")
|
||||
return sites
|
||||
|
||||
@pytest.fixture
|
||||
def app_factory(mock_sites_dir: Path) -> AppFactory:
|
||||
"""Fixture that provides the AppFactory instance to test"""
|
||||
return AppFactory(mock_sites_dir)
|
||||
|
||||
@pytest.fixture
|
||||
def mock_core_dir(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch
|
||||
) -> Path:
|
||||
"""Fixture that creates an isolated Core directory and points engine.CORE_DIR to it"""
|
||||
core = tmp_path / "CORE"
|
||||
core.mkdir(parents=True, exist_ok=True)
|
||||
return core
|
||||
|
||||
## GREEN TEST: Existing implementation should not break
|
||||
|
||||
def test_resolve_app_hierarchy(app_factory: AppFactory):
|
||||
"""Ensure resolution follows: Canonical Name > Alias > Dir Name > Prefix"""
|
||||
app_factory.create(
|
||||
dir_name="homelab-jellyfin",
|
||||
manifest_yaml="""
|
||||
name: media-server
|
||||
aliases:
|
||||
- movies
|
||||
""",
|
||||
)
|
||||
apps = engine.get_sites_apps()
|
||||
|
||||
assert engine.resolve_app("media-server", apps) is not None
|
||||
assert engine.resolve_app("movies", apps) is not None
|
||||
assert engine.resolve_app("homelab-jellyfin", apps) is not None
|
||||
assert engine.resolve_app("unknown", apps) is None
|
||||
|
||||
def test_manifest_data_overrides_default_values(app_factory: AppFactory):
|
||||
"""Ensure app.yaml values successfully override the system defaults"""
|
||||
app_factory.create(
|
||||
dir_name="homelab-custom",
|
||||
manifest_yaml="""
|
||||
name: custom-app
|
||||
domain: custom.roadtotech.local
|
||||
auth: false
|
||||
visible: false
|
||||
networks:
|
||||
- custom-net
|
||||
"""
|
||||
)
|
||||
|
||||
apps = engine.get_sites_apps()
|
||||
app = engine.resolve_app("custom-app", apps)
|
||||
|
||||
assert app is not None
|
||||
assert app.domain == "custom.roadtotech.local"
|
||||
assert app.auth is False
|
||||
assert app.networks == ["custom-net"]
|
||||
|
||||
def test_sites_app_normalization(app_factory: AppFactory):
|
||||
"""Ensure missing or badly typed manifest fields are safely normalized"""
|
||||
app_factory.create(
|
||||
dir_name="homelab-custom",
|
||||
manifest_yaml="""
|
||||
name: testapp
|
||||
# Missing domain - should fallback to <name>.roadtotech.me
|
||||
aliases: single-string-alias # should become a list[str]
|
||||
auth: "False" # should evaluate based on boolean casting
|
||||
homepage:
|
||||
weight: "99" # this should be casted as an int
|
||||
"""
|
||||
)
|
||||
apps = engine.get_sites_apps()
|
||||
app = engine.resolve_app("testapp", apps)
|
||||
|
||||
assert app is not None
|
||||
assert app.name == "testapp"
|
||||
assert app.domain == "testapp.mydomain.test"
|
||||
assert app.aliases == ["single-string-alias"]
|
||||
assert app.auth is True
|
||||
assert app.homepage is not None
|
||||
assert app.homepage.weight == 99
|
||||
|
||||
|
||||
## RED TESTS: TDD Goals for next implementation
|
||||
|
||||
@pytest.mark.xfail(reason="TDD in progress: get_docker_status not yet implemented")
|
||||
def test_docker_status_parser_running(monkeypatch):
|
||||
"""
|
||||
TDD Goal: Port `get_docker_status` to V2
|
||||
It must shell out to `docker-compse ps` and `docker inspect`
|
||||
then return the correct UI badge
|
||||
"""
|
||||
def mock_run(args, **kwargs):
|
||||
"""Mocking a running"""
|
||||
mock = MagicMock()
|
||||
if "ps" in args:
|
||||
mock.stdout = "container123\n"
|
||||
if "inspect" in args:
|
||||
mock.stdout = "true\n"
|
||||
return mock
|
||||
|
||||
monkeypatch.setattr("subprocess.run", mock_run)
|
||||
|
||||
status = engine.get_docker_status("/fake/dir")
|
||||
assert status == "🟢 Running (1)"
|
||||
|
||||
@pytest.mark.xfail(reason="TDD in progress: cmd_sync_homepage not yet implemented")
|
||||
def test_homepage_sync_groups_and_sorts_correctly(
|
||||
mock_core_dir: Path,
|
||||
app_factory: AppFactory,
|
||||
monkeypatch):
|
||||
"""
|
||||
TDD Goal: Port `cmd_sync_homepage` to V2 using the new Dataclass structure.
|
||||
It must group by `homepage.group` and sort by `homepage.weight`.
|
||||
"""
|
||||
hp_config_dir = mock_core_dir / "config" / "homepage"
|
||||
hp_config_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
app_factory.create(
|
||||
dir_name="homelab-app1",
|
||||
manifest_yaml="""
|
||||
name: App1
|
||||
domain: app1.local.test
|
||||
homepage:
|
||||
title: App1
|
||||
group: Group B
|
||||
weight: 20
|
||||
"""
|
||||
)
|
||||
|
||||
app_factory.create(
|
||||
dir_name="homelab-app2",
|
||||
manifest_yaml="""
|
||||
name: App2
|
||||
domain: app2.local.test
|
||||
homepage:
|
||||
title: App2
|
||||
group: Group A
|
||||
weight: 10
|
||||
"""
|
||||
)
|
||||
|
||||
monkeypatch.setattr(engine, "get_core_services", list)
|
||||
engine.cmd_sync_homepage(["--homepage-dir=" + str(hp_config_dir)])
|
||||
|
||||
output_file = hp_config_dir / "services.yaml"
|
||||
assert output_file.exists(), "The services.yaml file must be generated"
|
||||
|
||||
content = output_file.read_text()
|
||||
assert content.find("- Group A") < content.find("- Group B") # Group A should appear before Group B
|
||||
assert "App2" in content # App 2 is in the file
|
||||
Reference in new issue
Block a user