refactor(core): consolidate control plane into a single compose stack

This massive refactor transitions the project from a custom-scripted
multi-stack deployment into a unified, standard Docker Compose
architecture. This heavily simplifies GitOps workflows and native
NixOS systemd integration.

- Merge all infrastructure and portal compose files into a root docker-compose.yml
- Consolidate all service configurations and databases into a single ./config/ directory
- Remove brittle up.sh and down.sh orchestration scripts
- Fix Authelia templating by enabling X_AUTHELIA_CONFIG_FILTERS=template
- Replace all hardcoded domain names with dynamic ${DOMAIN} variables
- Archive legacy HTML documentation and architecture notes to docs/legacy/
- Introduce setup_guide.md as the single source of truth for SOPS secrets and NixOS deployment
This commit is contained in:
kiskaadee committed 2026-06-28 15:55:06 -05:00
1 parent d75e4aa2cb
commit e832c83882
38 files changed
+426 -452

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# 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
+10 -11
View File
@@ -1,28 +1,27 @@
# Environments & Secrets # Environments & Secrets
.env .env
.env.* .env.*
**/.env secrets.txt
**/config/*.env backup.zip
**/config/users.yml
# SSL / ACME Certificates & Keys # SSL / ACME Certificates & Keys
**/letsencrypt/acme.json config/letsencrypt/acme.json
**/*.key **/*.key
**/*.crt **/*.crt
**/*.pem **/*.pem
# Authelia Databases & Mail Logs # Authelia Databases & Mail Logs
infra/authelia/config/db.sqlite3 config/authelia/db.sqlite3
infra/authelia/config/emails.txt config/authelia/emails.txt
# Infrastructure Persistent Volumes & Logs # Diun Databases
**/portainer_data/ config/diun/diun.db
infra/diun/data/
homepage/config/logs/ # Homepage Logs
config/homepage/logs/
# OS & Editor Metadata # OS & Editor Metadata
.DS_Store .DS_Store
Thumbs.db Thumbs.db
.vscode/ .vscode/
.idea/ .idea/
backup.zip
+29 -82
View File
@@ -1,105 +1,52 @@
# Traefik Homelab # Traefik Homelab Core
This repository contains the core Control Plane for a modular, secure, and self-documenting homeserver architecture based on the **Hardened Hub** model. This repository contains the core Control Plane for a modular, secure, and self-documenting homeserver architecture based on the **Hardened Hub** model.
It consolidates all routing, authentication, and core panel management into a single, unified Docker Compose stack, optimized for secure credentials management via `sops-nix`.
---
## 🏗️ Architectural Overview ## 🏗️ Architectural Overview
The system is split into two distinct planes to ensure stability, security, and a clean separation of concerns: The system is split into two distinct planes to ensure stability, security, and a clean separation of concerns:
### 1. Control Plane (`infra/` & `homepage/`) ### 1. Control Plane (This Repository)
The "nervous system" of the server. These services handle security, edge routing, identity, maintenance, and portal visualization. The "nervous system" of the server. These services handle security, edge routing, identity, maintenance, and portal visualization. All services are defined in a single, root-level `docker-compose.yml` and state configurations are stored in `./config/`:
- **Core (`infra/core`):** * **`traefik` (v3.6):** The edge gateway. Handles wildcard HTTPS (Let's Encrypt DNS-01 challenges via Dynu), reverse routing, and load balancing.
- **Traefik (v3.6):** The entry gateway. Handles HTTPS (Let's Encrypt DNS-01 challenges), routing, and load balancing. * **`socket-proxy`:** Security boundary. Decouples containers from the host's `/var/run/docker.sock`.
- **Socket-Proxy:** The security boundary. Decouples core containers from the host's `/var/run/docker.sock`. * **`authelia`:** Provides Single Sign-On (SSO) and 2FA protection for administrative tools and exposed applications.
- **Identity (`infra/authelia`):** Provides Single Sign-On (SSO) and 2FA protection for administrative tools and exposed applications. * **`portainer`:** Visual container and stack management.
- **Management (`infra/portainer`):** Visual container and stack management. * **`dozzle`:** Real-time log streaming for core containers (SSO Protected).
- **Monitoring (`infra/dozzle`):** Real-time log streaming for core containers (SSO Protected). * **`watchtower` & `diun`:** Automated image updates and registry monitoring.
- **Maintenance (`infra/watchtower`, `infra/diun`):** Automated image updates and registry monitoring. * **`homepage`:** Central landing dashboard at the root domain (`arch-services.mywire.org`) serving as the entry portal.
- **Portal (`homepage/`):** Central landing dashboard at `arch-services.mywire.org` serving as the single entry point.
### 2. Data Plane (Decoupled User Applications) ### 2. Data Plane (Decoupled User Applications)
User applications (such as Gitea, Jellyfin, or Kanban boards) are kept fully decoupled in separate directories outside this repository. They integrate with the Control Plane dynamically via the shared external Docker network (`proxy-net`) and Traefik routing labels. User applications (such as Gitea, Jellyfin, or Kanban boards) live in separate directories outside this repository (e.g. `/home/kiskaadee/Deployments/traefik-deployments`). They integrate with the Control Plane dynamically via the shared external Docker network (`proxy-net`) and Traefik routing labels.
--- ---
## 🚀 Getting Started ## 🚀 Getting Started
### 1. Secrets Management All instructions on deployment, structure, and secrets management have been updated for this release:
Secrets are kept out of the configuration files and stored in `.env` files (git-ignored).
- **Core Infrastructure:** Create `infra/core/.env` based on `.env-example`: 👉 **See the [Setup & Secrets Management Guide](docs/setup_guide.md)**
```env
DYNU_API_KEY=your_key
ACME_EMAIL=your_email
```
- **Identity (Authelia):** Create `infra/authelia/.env` with the following:
```env
AUTHELIA_SESSION_SECRET=long_random_string
AUTHELIA_STORAGE_ENCRYPTION_KEY=long_random_string
AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET=long_random_string
```
### 2. Deployment
Use the `up.sh` script to launch the core stack. The script handles network creation, Let's Encrypt certificate file initialization, and starts all infrastructure services plus the Homepage portal.
### Quick Start (NixOS systemd Service)
If you are deploying on NixOS with the matching configuration, the service is managed declaratively. To check status or read logs:
```bash ```bash
# Start the entire Core Infrastructure + Homepage systemctl status homeserver-core
./up.sh journalctl -u homeserver-core -f
``` ```
### 3. Verification ### Manual Verification
Once deployed, verify your services are reachable: If running manually (or troubleshooting config edits):
- **Homepage Dashboard:** `https://arch-services.mywire.org` ```bash
- **Auth Portal:** `https://auth.arch-services.mywire.org` docker compose --env-file /run/secrets/homeserver.env up -d --remove-orphans
- **Traefik Dashboard:** `https://traefik.arch-services.mywire.org` (Redirects to Auth) ```
- **Logs:** `https://logs.arch-services.mywire.org` (Redirects to Auth)
--- ---
## 📊 Observability & Monitoring ## 📚 Documentation
* **[Setup & Secrets Guide](docs/setup_guide.md)**: Detailed configuration, systemd service, and SOPS secret integration.
The system includes built-in tools for real-time monitoring and management: * **[Legacy Documentation](docs/legacy/)**: Archive of old setup files and html pages.
- **Traefik Dashboard**: `https://traefik.arch-services.mywire.org` — View routing, entrypoints, and certificate status (SSO Protected).
- **Dozzle**: `https://logs.arch-services.mywire.org` — Real-time log streaming for all containers (SSO Protected).
- **Portainer**: `https://portainer.arch-services.mywire.org` — Advanced container, volume, and stack management (SSO Protected).
- **Homepage**: `https://arch-services.mywire.org` — The central portal displaying status indicators for all services.
### Maintenance Scripts
For rapid diagnostics and common fixes, use the included automation scripts:
- **`./scripts/check-ssl.sh`**: Instantly audits the SSL/TLS status across all configured public subdomains.
- **`./scripts/purge-dynu.sh`**: Clears stale ACME challenge records from Dynu to resolve "503 Quota" deadlocks.
---
## 📜 Log Policy
To prevent the host system from running out of disk space, a **Log Rotation** policy is enforced:
- **Driver**: `json-file`
- **Max Size**: `10m` (10 Megabytes per file)
- **Max Files**: `3` (Keeps the last 3 files)
This policy is currently enabled on core infrastructure and is recommended for all high-traffic application containers.
---
## 🛡️ Security Features
- **Socket Isolation:** No container has access to the host's raw Docker socket. All management tools communicate via the read/write-controlled `socket-proxy`.
- **SSO Integration:** Critical management tools (Portainer, Dozzle) and sensitive user applications are behind Authelia Forward Auth.
- **Automatic TLS:** Traefik automatically manages wildcard Let's Encrypt certificates via DNS-01 challenges with Dynu.
- **Network Segmentation:** System traffic is isolated on `proxy-net` and `socket-net` networks.
- **Decoupled Architecture:** Application stacks are isolated from the core repository config, preventing Git history contamination and permitting independent CI/CD pipelines.
---
## 📚 Detailed Documentation
For more in-depth information, please refer to the following guides:
- **[Server Architecture](https://kiskaadee.github.io/traefik-homelab/architecture.html)**: Deep dive into the layered model, networking, and security posture.
- **[Usability & Operations](https://kiskaadee.github.io/traefik-homelab/usability.html)**: How to use the hub, expose new decoupled apps, and manage updates.
- **[Troubleshooting](https://kiskaadee.github.io/traefik-homelab/troubleshooting.html)**: Solutions for common connectivity, SSL, and authentication issues.
- **[Project Roadmap](https://kiskaadee.github.io/traefik-homelab/roadmap.html)**: Current status and future planned features.
- **[Dynu IP Protocol](https://kiskaadee.github.io/traefik-homelab/dynu-ip-update-protocol.html)**: Technical details on the DDNS synchronization mechanism.
@@ -14,29 +14,29 @@ authentication_backend:
access_control: access_control:
default_policy: deny default_policy: deny
rules: rules:
- domain: "auth.{{ env \"DOMAIN\" }}" - domain: 'auth.{{ env "DOMAIN" }}'
policy: bypass policy: bypass
- domain: "*.{{ env \"DOMAIN\" }}" - domain: '*.{{ env "DOMAIN" }}'
policy: one_factor policy: one_factor
session: session:
name: authelia_session name: authelia_session
secret: "{{ env \"AUTHELIA_SESSION_SECRET\" }}" secret: '{{ env "AUTHELIA_SESSION_SECRET" }}'
expiration: 3600 expiration: 3600
inactivity: 300 inactivity: 300
remember_me: 1M remember_me: 1M
cookies: cookies:
- domain: "{{ env \"DOMAIN\" }}" - domain: '{{ env "DOMAIN" }}'
authelia_url: "https://auth.{{ env \"DOMAIN\" }}" authelia_url: 'https://auth.{{ env "DOMAIN" }}'
identity_validation: identity_validation:
reset_password: reset_password:
jwt_secret: "{{ env \"AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET\" }}" jwt_secret: '{{ env "AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET" }}'
storage: storage:
local: local:
path: /config/db.sqlite3 path: /config/db.sqlite3
encryption_key: "{{ env \"AUTHELIA_STORAGE_ENCRYPTION_KEY\" }}" encryption_key: '{{ env "AUTHELIA_STORAGE_ENCRYPTION_KEY" }}'
notifier: notifier:
filesystem: filesystem:
+9
View File
@@ -0,0 +1,9 @@
users:
admin:
displayname: "Admin"
# Password is 'password' (hashed with Authelia's default)
password: '$pbkdf2-sha512$310000$6AM/6rKEZJm9nNeMRl.Zfw$BpLugzfKmNdcX5kpf3/RQwIkO.dCUj7ZOYhKatY2H4iyDmMZP2KJ2Zj9u0rr7sBPHoTBS7C.1hWw7qjjUKAkCw'
email: admin@arch-services.mywire.org
groups:
- admins
- dev
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+237
View File
@@ -0,0 +1,237 @@
services:
socket-proxy:
image: tecnativa/docker-socket-proxy
container_name: socket-proxy
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
- CONTAINERS=1
- NETWORKS=1
- SERVICES=1
- TASKS=1
- IMAGES=1
- VOLUMES=1
- POST=1
- DELETE=1
- DOCKER_API_VERSION=${DOCKER_API_VERSION:-1.40}
- VERSION=1
- INFO=1
- EVENTS=1
- PING=1
- BUILD=0
- COMMIT=0
- CONFIGS=0
- DISTRIBUTION=0
- EXEC=0
- NODES=0
- PLUGINS=0
- SECRETS=0
- SWARM=0
- SYSTEM=0
networks:
- socket-net
traefik:
image: traefik:v3.6
container_name: traefik
restart: always
depends_on:
- socket-proxy
ports:
- "80:80"
- "443:443"
environment:
- DYNU_API_KEY=${DYNU_API_KEY}
- DOCKER_API_VERSION=${DOCKER_API_VERSION:-1.40}
command:
- "--log.level=INFO"
- "--api.dashboard=true"
- "--providers.docker=true"
- "--providers.docker.endpoint=tcp://socket-proxy:2375"
- "--providers.docker.exposedByDefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
# Global TLS defaults for websecure
- "--entrypoints.websecure.http.tls.certResolver=myresolver"
- "--entrypoints.websecure.http.tls.domains[0].main=${DOMAIN}"
- "--entrypoints.websecure.http.tls.domains[0].sans=*.${DOMAIN}"
# SSL Setup
- "--certificatesresolvers.myresolver.acme.dnschallenge=true"
- "--certificatesresolvers.myresolver.acme.dnschallenge.provider=dynu"
- "--certificatesresolvers.myresolver.acme.email=${ACME_EMAIL}"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
volumes:
- ./config/letsencrypt:/letsencrypt
networks:
- socket-net
- proxy-net
labels:
- "traefik.enable=true"
# Middleware: Redirect to HTTPS
- "traefik.http.middlewares.https-redirect.redirectscheme.scheme=https"
- "traefik.http.middlewares.https-redirect.redirectscheme.permanent=true"
# Middleware: Authelia Guard
- "traefik.http.middlewares.authelia-auth.forwardauth.address=http://authelia:9091/api/verify?rd=https://auth.${DOMAIN}/"
- "traefik.http.middlewares.authelia-auth.forwardauth.trustForwardHeader=true"
- "traefik.http.middlewares.authelia-auth.forwardauth.authResponseHeaders=Remote-User,Remote-Groups,Remote-Email,Remote-Name"
# Dashboard - Public (HTTPS)
- "traefik.http.routers.traefik-dash.rule=Host(`traefik.${DOMAIN}`)"
- "traefik.http.routers.traefik-dash.entrypoints=websecure"
- "traefik.http.routers.traefik-dash.tls=true"
- "traefik.http.routers.traefik-dash.service=api@internal"
- "traefik.http.routers.traefik-dash.middlewares=authelia-auth@docker"
# Dashboard - Public (Redirect)
- "traefik.http.routers.traefik-dash-red.rule=Host(`traefik.${DOMAIN}`)"
- "traefik.http.routers.traefik-dash-red.entrypoints=web"
- "traefik.http.routers.traefik-dash-red.middlewares=https-redirect@docker"
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
authelia:
image: authelia/authelia:latest
container_name: authelia
restart: always
volumes:
- ./config/authelia:/config
environment:
- DOMAIN=${DOMAIN}
- AUTHELIA_SESSION_SECRET=${AUTHELIA_SESSION_SECRET}
- AUTHELIA_STORAGE_ENCRYPTION_KEY=${AUTHELIA_STORAGE_ENCRYPTION_KEY}
- AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET=${AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET}
- X_AUTHELIA_CONFIG_FILTERS=template
networks:
- proxy-net
labels:
- "traefik.enable=true"
# Public (HTTPS)
- "traefik.http.routers.authelia.rule=Host(`auth.${DOMAIN}`)"
- "traefik.http.routers.authelia.entrypoints=websecure"
- "traefik.http.routers.authelia.tls=true"
# Public (Redirect)
- "traefik.http.routers.authelia-red.rule=Host(`auth.${DOMAIN}`)"
- "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.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
restart: always
environment:
- DOCKER_HOST=tcp://socket-proxy:2375
- DOCKER_API_VERSION=${DOCKER_API_VERSION:-1.40}
networks:
- proxy-net
- socket-net
labels:
- "traefik.enable=true"
# Public (HTTPS)
- "traefik.http.routers.logs.rule=Host(`logs.${DOMAIN}`)"
- "traefik.http.routers.logs.entrypoints=websecure"
- "traefik.http.routers.logs.tls=true"
- "traefik.http.routers.logs.middlewares=authelia-auth@docker"
- "traefik.http.routers.logs.service=logs-svc"
# Public (Redirect)
- "traefik.http.routers.logs-red.rule=Host(`logs.${DOMAIN}`)"
- "traefik.http.routers.logs-red.entrypoints=web"
- "traefik.http.routers.logs-red.middlewares=https-redirect@docker"
- "traefik.http.services.logs-svc.loadbalancer.server.port=8080"
watchtower:
image: containrrr/watchtower
container_name: watchtower
restart: always
environment:
- DOCKER_HOST=tcp://socket-proxy:2375
- DOCKER_API_VERSION=${DOCKER_API_VERSION:-1.40}
- WATCHTOWER_CLEANUP=true
- WATCHTOWER_LABEL_ENABLE=true
networks:
- socket-net
diun:
image: crazymax/diun:latest
container_name: diun
restart: always
command: serve
environment:
- TZ=UTC
- LOG_LEVEL=info
- LOG_JSON=false
- DIUN_WATCH_WORKERS=20
- 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}
volumes:
- ./config/diun:/data
networks:
- socket-net
homepage:
image: ghcr.io/gethomepage/homepage:latest
container_name: homepage
restart: always
volumes:
- ./config/homepage:/app/config
- /home:/home:ro
environment:
- HOMEPAGE_ALLOWED_HOSTS=${DOMAIN}
networks:
- proxy-net
- socket-net
labels:
- "traefik.enable=true"
# Public (HTTPS)
- "traefik.http.routers.homepage.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.homepage.entrypoints=websecure"
- "traefik.http.routers.homepage.tls=true"
- "traefik.http.routers.homepage.service=homepage-svc"
# Public (Redirect)
- "traefik.http.routers.homepage-red.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.homepage-red.entrypoints=web"
- "traefik.http.routers.homepage-red.middlewares=https-redirect@docker"
- "traefik.http.services.homepage-svc.loadbalancer.server.port=3000"
networks:
proxy-net:
name: proxy-net
driver: bridge
socket-net:
name: socket-net
driver: bridge
internal: true
volumes:
portainer_data:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+119
View File
@@ -0,0 +1,119 @@
# Setup & Secrets Management Guide (Traefik Homelab)
This document provides a guide for deploying, managing, and securing the consolidated homeserver core stack.
---
## 🏗️ Architectural Overview
The core infrastructure is organized as a single, unified Docker Compose stack:
* **/docker-compose.yml**: Root orchestrator defining all core services (`traefik`, `authelia`, `portainer`, `dozzle`, `watchtower`, `diun`, `homepage`, `socket-proxy`).
* **/config/**: Holds the configuration directories and sqlite databases for all services:
* `config/letsencrypt/`: Contains SSL certificate state (`acme.json`).
* `config/authelia/`: Contains single sign-on configs (`configuration.yml`, `users.yml`) and database (`db.sqlite3`).
* `config/homepage/`: Contains dashboard layout files (`services.yaml`, `bookmarks.yaml`, etc.).
* `config/diun/`: Diun registry monitoring database (`diun.db`).
---
## 🔒 Credentials & Secrets Management
Secrets are managed declaratively using **`sops-nix`** (Mozilla SOPS + age keys) inside your system configuration repository (`~/Config`). This keeps all private credentials completely out of Git in an encrypted format.
### How Secrets Flow:
```
[~/Config/hosts/desktop/secrets.yaml] (Encrypted)
│
▼ (Decrypted at boot by sops-nix using SSH host key)
[/run/secrets/homeserver.env] (Runtime Environment File)
│
▼ (Fed via --env-file flag into Docker Compose)
[Docker Containers] (Active environment variables)
```
---
## 🔑 Adding/Editing Secrets
To add or modify credentials (e.g. changing your Dynu API key or regenerating Authelia secrets):
1. Navigate to your system configuration repository:
```bash
cd ~/Config
```
2. Decrypt and open the secrets file in your editor using SOPS:
```bash
nix-shell -p sops --run "sops hosts/desktop/secrets.yaml"
```
3. Append or edit the required keys under the root block:
```yaml
dynu_api_key: "your_dynu_api_key"
acme_email: "your_email@provider.com"
authelia_session_secret: "secure_64_character_hex_string"
authelia_storage_encryption_key: "secure_64_character_hex_string"
authelia_identity_validation_reset_password_jwt_secret: "secure_64_character_hex_string"
```
4. Save and close the editor. SOPS will automatically encrypt the file and write it back to disk.
---
## ⚙️ NixOS Integration
The stack is managed as a declarative systemd service inside `/home/kiskaadee/Config/hosts/desktop/homeserver.nix`:
### 1. Secret Environment Template
The module defines a SOPS template to gather all secrets and structure them as key-value pairs at `/run/secrets/homeserver.env`:
```nix
sops.templates."homeserver.env" = {
owner = "kiskaadee";
content = lib.generators.toKeyValue {} {
DOMAIN = "arch-services.mywire.org";
DOCKER_API_VERSION = "1.40";
DYNU_API_KEY = config.sops.placeholder.dynu_api_key;
ACME_EMAIL = config.sops.placeholder.acme_email;
AUTHELIA_SESSION_SECRET = config.sops.placeholder.authelia_session_secret;
AUTHELIA_STORAGE_ENCRYPTION_KEY = config.sops.placeholder.authelia_storage_encryption_key;
AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET = config.sops.placeholder.authelia_identity_validation_reset_password_jwt_secret;
};
};
```
### 2. systemd Lifecycle Daemon
The service starts and stops the compose stack automatically:
```nix
systemd.services.homeserver-core = {
description = "Homeserver Core Stack";
after = [ "network-online.target" "docker.service" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
WorkingDirectory = "/home/kiskaadee/Deployments/homeserver";
ExecStart = "${pkgs.docker-compose}/bin/docker-compose --env-file ${config.sops.templates."homeserver.env".path} up -d --remove-orphans";
ExecStop = "${pkgs.docker-compose}/bin/docker-compose down";
};
};
```
---
## 🚀 Running and Managing the Stack
Because the systemd service manages the containers, standard `systemctl` commands can be used:
* **Start the stack**: `sudo systemctl start homeserver-core`
* **Stop the stack**: `sudo systemctl stop homeserver-core`
* **Check service status**: `systemctl status homeserver-core`
* **Check logs**: `journalctl -u homeserver-core`
### Dynamic Configuration Tweaks (Non-Nix Workflow)
If you modify `docker-compose.yml` (e.g. adding a new Traefik routing label), you do **not** need to rebuild NixOS! You can apply it instantly:
```bash
cd /home/kiskaadee/Deployments/homeserver
docker compose --env-file /run/secrets/homeserver.env up -d --remove-orphans
```
This preserves the extreme agility of Docker Compose while keeping your system configuration and secrets declaratively managed.
-29
View File
@@ -1,29 +0,0 @@
#!/bin/bash
stop_stack() {
local stack_path=$1
shift
local env_flags=()
for env_file in "$@"; do
if [ -f "$env_file" ]; then
env_flags+=("--env-file" "$env_file")
fi
done
if [ -f "$stack_path/docker-compose.yml" ]; then
echo "Stopping stack: $stack_path..."
docker compose -f "$stack_path/docker-compose.yml" "${env_flags[@]}" down
fi
}
echo "=== Stopping Portal Layer ==="
stop_stack "homepage" "infra/core/.env"
echo "=== Stopping Infrastructure Layer ==="
stop_stack "infra/dozzle"
stop_stack "infra/diun"
stop_stack "infra/watchtower"
stop_stack "infra/portainer"
stop_stack "infra/authelia" "infra/core/.env" "infra/authelia/.env"
stop_stack "infra/core" "infra/core/.env"
echo "All services stopped."
-36
View File
@@ -1,36 +0,0 @@
services:
homepage:
image: ghcr.io/gethomepage/homepage:latest
container_name: homepage
restart: always
volumes:
- ./config:/app/config
- /home:/home:ro
environment:
- HOMEPAGE_ALLOWED_HOSTS=${DOMAIN}
networks:
- proxy-net
- socket-net
labels:
- "traefik.enable=true"
# Public (HTTPS)
- "traefik.http.routers.homepage.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.homepage.entrypoints=websecure"
- "traefik.http.routers.homepage.tls=true"
- "traefik.http.routers.homepage.service=homepage-svc"
# Public (Redirect)
- "traefik.http.routers.homepage-red.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.homepage-red.entrypoints=web"
- "traefik.http.routers.homepage-red.middlewares=https-redirect@docker"
- "traefik.http.services.homepage-svc.loadbalancer.server.port=3000"
networks:
proxy-net:
external: true
socket-net:
external: true
-6
View File
@@ -1,6 +0,0 @@
# Authelia Configuration Environment Variables
# Generate secure random secrets (e.g., openssl rand -hex 32) for these fields
AUTHELIA_SESSION_SECRET=
AUTHELIA_STORAGE_ENCRYPTION_KEY=
AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET=
-26
View File
@@ -1,26 +0,0 @@
services:
authelia:
image: authelia/authelia:latest
container_name: authelia
restart: always
volumes:
- ./config:/config
environment:
- DOMAIN=${DOMAIN}
networks:
- proxy-net
labels:
- "traefik.enable=true"
# Public (HTTPS)
- "traefik.http.routers.authelia.rule=Host(`auth.${DOMAIN}`)"
- "traefik.http.routers.authelia.entrypoints=websecure"
- "traefik.http.routers.authelia.tls=true"
# Public (Redirect)
- "traefik.http.routers.authelia-red.rule=Host(`auth.${DOMAIN}`)"
- "traefik.http.routers.authelia-red.entrypoints=web"
- "traefik.http.routers.authelia-red.middlewares=https-redirect@docker"
networks:
proxy-net:
external: true
-3
View File
@@ -1,3 +0,0 @@
DYNU_API_KEY=your_secret_api_key_here
ACME_EMAIL=your-email@example.com
DOMAIN=somewhere.domain.com
-103
View File
@@ -1,103 +0,0 @@
services:
socket-proxy:
image: tecnativa/docker-socket-proxy
container_name: socket-proxy
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro # Only place the real socket is mounted
environment:
- CONTAINERS=1 # Traefik needs to see containers
- NETWORKS=1 # Traefik needs to see networks
- SERVICES=1
- TASKS=1
- IMAGES=1 # Needed for Watchtower/Portainer
- VOLUMES=1 # Needed for Portainer
- POST=1 # Needed for Portainer/Watchtower to start/stop/create containers
- DELETE=1 # Needed for Portainer/Watchtower to remove containers/images
- DOCKER_API_VERSION=1.40
- VERSION=1 # Allow Traefik to query version
- INFO=1 # Allow Traefik to query info
- EVENTS=1 # Allow Traefik to monitor container changes
- PING=1 # Allow Traefik to check Docker health
- BUILD=0
- COMMIT=0
- CONFIGS=0
- DISTRIBUTION=0
- EXEC=0
- NODES=0
- PLUGINS=0
- SECRETS=0
- SWARM=0
- SYSTEM=0
networks:
- socket-net
traefik:
image: traefik:v3.6
container_name: traefik
restart: always
depends_on:
- socket-proxy
ports:
- "80:80"
- "443:443"
environment:
- DYNU_API_KEY=${DYNU_API_KEY}
- DOCKER_API_VERSION=1.40
command:
- "--log.level=INFO"
- "--api.dashboard=true"
- "--providers.docker=true"
- "--providers.docker.endpoint=tcp://socket-proxy:2375"
- "--providers.docker.exposedByDefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
# Global TLS defaults for websecure
- "--entrypoints.websecure.http.tls.certResolver=myresolver"
- "--entrypoints.websecure.http.tls.domains[0].main=${DOMAIN}"
- "--entrypoints.websecure.http.tls.domains[0].sans=*.${DOMAIN}"
# SSL Setup
- "--certificatesresolvers.myresolver.acme.dnschallenge=true"
- "--certificatesresolvers.myresolver.acme.dnschallenge.provider=dynu"
- "--certificatesresolvers.myresolver.acme.email=${ACME_EMAIL}"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
volumes:
- ./letsencrypt:/letsencrypt
networks:
- socket-net
- proxy-net
labels:
- "traefik.enable=true"
# Middleware: Redirect to HTTPS
- "traefik.http.middlewares.https-redirect.redirectscheme.scheme=https"
- "traefik.http.middlewares.https-redirect.redirectscheme.permanent=true"
# Middleware: Authelia Guard
- "traefik.http.middlewares.authelia-auth.forwardauth.address=http://authelia:9091/api/verify?rd=https://auth.${DOMAIN}/"
- "traefik.http.middlewares.authelia-auth.forwardauth.trustForwardHeader=true"
- "traefik.http.middlewares.authelia-auth.forwardauth.authResponseHeaders=Remote-User,Remote-Groups,Remote-Name,Remote-Email"
# Dashboard - Public (HTTPS)
- "traefik.http.routers.traefik-dash.rule=Host(`traefik.${DOMAIN}`)"
- "traefik.http.routers.traefik-dash.entrypoints=websecure"
- "traefik.http.routers.traefik-dash.tls=true"
- "traefik.http.routers.traefik-dash.service=api@internal"
- "traefik.http.routers.traefik-dash.middlewares=authelia-auth@docker"
# Dashboard - Public (Redirect)
- "traefik.http.routers.traefik-dash-red.rule=Host(`traefik.${DOMAIN}`)"
- "traefik.http.routers.traefik-dash-red.entrypoints=web"
- "traefik.http.routers.traefik-dash-red.middlewares=https-redirect@docker"
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
networks:
socket-net:
external: true
proxy-net:
external: true
View File
Whitespace-only changes.
-23
View File
@@ -1,23 +0,0 @@
services:
diun:
image: crazymax/diun:latest
container_name: diun
restart: always
command: serve
environment:
- TZ=UTC
- LOG_LEVEL=info
- LOG_JSON=false
- DIUN_WATCH_WORKERS=20
- DIUN_WATCH_SCHEDULE=0 */6 * * *
- DIUN_PROVIDERS_DOCKER=true
- DIUN_PROVIDERS_DOCKER_ENDPOINT=tcp://socket-proxy:2375
- DOCKER_API_VERSION=1.40
volumes:
- "./data:/data"
networks:
- socket-net
networks:
socket-net:
external: true
-29
View File
@@ -1,29 +0,0 @@
services:
dozzle:
image: amir20/dozzle:latest
container_name: dozzle
environment:
- DOCKER_HOST=tcp://socket-proxy:2375
- DOCKER_API_VERSION=1.40
networks:
- proxy-net
- socket-net
labels:
- "traefik.enable=true"
- "traefik.http.routers.logs.rule=Host(`logs.arch-services.mywire.org`)"
- "traefik.http.routers.logs.entrypoints=websecure"
- "traefik.http.routers.logs.tls=true"
- "traefik.http.routers.logs.middlewares=authelia-auth@docker"
- "traefik.http.routers.logs.service=logs-svc"
- "traefik.http.routers.logs-red.rule=Host(`logs.arch-services.mywire.org`)"
- "traefik.http.routers.logs-red.entrypoints=web"
- "traefik.http.routers.logs-red.middlewares=https-redirect@docker"
- "traefik.http.services.logs-svc.loadbalancer.server.port=8080"
networks:
proxy-net:
external: true
socket-net:
external: true
-32
View File
@@ -1,32 +0,0 @@
services:
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"
- "traefik.http.routers.portainer.rule=Host(`portainer.arch-services.mywire.org`)"
- "traefik.http.routers.portainer.entrypoints=websecure"
- "traefik.http.routers.portainer.tls=true"
- "traefik.http.routers.portainer.service=portainer-svc"
- "traefik.http.routers.portainer-red.rule=Host(`portainer.arch-services.mywire.org`)"
- "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"
networks:
socket-net:
external: true
proxy-net:
external: true
volumes:
portainer_data:
-16
View File
@@ -1,16 +0,0 @@
services:
watchtower:
image: containrrr/watchtower
container_name: watchtower
restart: always
environment:
- DOCKER_HOST=tcp://socket-proxy:2375
- DOCKER_API_VERSION=1.40
- WATCHTOWER_CLEANUP=true
- WATCHTOWER_LABEL_ENABLE=true
networks:
- socket-net
networks:
socket-net:
external: true
+2 -2
View File
@@ -2,7 +2,7 @@
# Path to your configuration # Path to your configuration
# Changed to project relative path # Changed to project relative path
ENV_FILE="infra/core/.env" ENV_FILE="${ENV_FILE:-.env}"
# 1. Load Environment Variables # 1. Load Environment Variables
if [ -f "$ENV_FILE" ]; then if [ -f "$ENV_FILE" ]; then
@@ -44,6 +44,6 @@ fi
# 4. Restart Traefik to trigger new challenge # 4. Restart Traefik to trigger new challenge
echo "Restarting Traefik..." echo "Restarting Traefik..."
cd infra/core/ && docker compose restart traefik docker compose restart traefik
echo "Process complete. Monitor logs with: docker logs traefik 2>&1 | grep -iE 'acme|dynu'" echo "Process complete. Monitor logs with: docker logs traefik 2>&1 | grep -iE 'acme|dynu'"
-47
View File
@@ -1,47 +0,0 @@
#!/bin/bash
# --- 1. NETWORK & PERMISSIONS ---
docker network inspect proxy-net >/dev/null 2>&1 || docker network create proxy-net
docker network inspect socket-net >/dev/null 2>&1 || docker network create socket-net
# SSL Permissions (Moved to infra/core)
if [ ! -f infra/core/letsencrypt/acme.json ]; then
echo "Initializing letsencrypt/acme.json..."
sudo mkdir -p infra/core/letsencrypt
sudo touch infra/core/letsencrypt/acme.json
sudo chmod 600 infra/core/letsencrypt/acme.json
sudo chown root:root infra/core/letsencrypt/acme.json
fi
# --- 2. HELPER FUNCTIONS ---
start_stack() {
local stack_path=$1
shift
local env_flags=()
for env_file in "$@"; do
if [ -f "$env_file" ]; then
env_flags+=("--env-file" "$env_file")
fi
done
if [ -f "$stack_path/docker-compose.yml" ]; then
echo "Starting stack: $stack_path..."
docker compose -f "$stack_path/docker-compose.yml" "${env_flags[@]}" up -d
else
echo "Warning: No docker-compose.yml found in $stack_path"
fi
}
# --- 3. DEPLOY CONTROL PLANE & PORTAL ---
echo "=== Deploying Control Plane ==="
start_stack "infra/core" "infra/core/.env"
start_stack "infra/authelia" "infra/core/.env" "infra/authelia/.env"
start_stack "infra/portainer"
start_stack "infra/watchtower"
start_stack "infra/diun"
start_stack "infra/dozzle"
echo "=== Deploying Homepage Portal ==="
start_stack "homepage" "infra/core/.env"
echo ""
echo "Hardened Private Cloud Deployment Complete."