From 3b845fe85a1c9a40e6844b5651a3490a8e24c3aa Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Fri, 4 Dec 2026 08:59:51 -0600 Subject: [PATCH] Add always-on SearXNG edge service --- .../public/homelab-catalog/index.html | 8 ++ bootstrap/edge/main.tf | 18 +++- bootstrap/edge/templates/default.conf.tftpl | 68 +++++++++++- bootstrap/edge/variables.tf | 10 ++ cmd/jeannie-server/main.go | 3 +- cmd/jeannie-server/main_test.go | 6 ++ docs/app-ops.md | 14 +++ docs/jeannie.1.md | 15 +++ docs/service-catalog.md | 1 + docs/templates/app-ops.md.tmpl | 14 +++ homelab.yml | 6 ++ infra/heimdall/homepage/services.yaml | 4 + infra/heimdall/links.json | 7 ++ infra/searxng/README.md | 20 ++++ infra/searxng/docker-compose.yml | 56 ++++++++++ infra/searxng/limiter.toml | 8 ++ infra/searxng/settings.yml | 34 ++++++ jeannie | 5 + lib/jeannie/commands.sh | 7 ++ lib/jeannie/env.sh | 6 ++ lib/jeannie/pipeline.sh | 101 ++++++++++++++++++ scripts/generate-heimdall-links | 1 + scripts/generate-homepage-config | 2 + scripts/render-service-catalog | 8 ++ scripts/validate-homelab | 1 + scripts/validate-homelab-inventory | 4 + tests/jeannie/test_searxng_pipeline.py | 43 ++++++++ 27 files changed, 466 insertions(+), 4 deletions(-) create mode 100644 infra/searxng/README.md create mode 100644 infra/searxng/docker-compose.yml create mode 100644 infra/searxng/limiter.toml create mode 100644 infra/searxng/settings.yml create mode 100644 tests/jeannie/test_searxng_pipeline.py diff --git a/apps/demos-static/public/homelab-catalog/index.html b/apps/demos-static/public/homelab-catalog/index.html index 3b599cc..1ac2002 100644 --- a/apps/demos-static/public/homelab-catalog/index.html +++ b/apps/demos-static/public/homelab-catalog/index.html @@ -96,6 +96,14 @@ https://lab2025.duckdns.org/git/ infra/gitea/README.md + + SearXNG + debian (control-plane, 192.168.100.73) + Docker Compose / jeannie deploy-searxng + http://192.168.100.73:8888/ + https://search.lab2025.duckdns.org/ + infra/searxng/README.md + GitOps mirror debian (control-plane, 192.168.100.73) diff --git a/bootstrap/edge/main.tf b/bootstrap/edge/main.tf index 8eff535..08795e5 100644 --- a/bootstrap/edge/main.tf +++ b/bootstrap/edge/main.tf @@ -16,19 +16,21 @@ locals { homepage_server_name = "homepage.${var.server_name}" oidc_server_name = "auth.${var.server_name}" jellyfin_server_name = "jellyfin.${var.server_name}" + searxng_server_name = "search.${var.server_name}" heimdall_backend_host = var.heimdall_backend_host != "" ? var.heimdall_backend_host : var.gitea_backend_host homepage_backend_host = var.homepage_backend_host != "" ? var.homepage_backend_host : var.gitea_backend_host oidc_backend_host = ( var.oidc_backend_host != "" ? var.oidc_backend_host : var.gitea_backend_host ) jellyfin_backend_host = var.jellyfin_backend_host != "" ? var.jellyfin_backend_host : var.gitea_backend_host + searxng_backend_host = var.searxng_backend_host != "" ? var.searxng_backend_host : var.gitea_backend_host jeannie_api_server_name = "api.${var.server_name}" office_server_name = var.office_server_name office_onlyoffice_server_name = var.office_onlyoffice_server_name matrix_server_names = var.matrix_enabled ? [var.matrix_server_name, var.element_server_name] : [] monitoring_names = var.monitoring_backend_host != "" ? ["grafana.${var.server_name}", "prometheus.${var.server_name}", "alertmanager.${var.server_name}"] : [] - server_names = distinct(concat([var.server_name, local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name, local.jeannie_api_server_name, local.office_server_name, local.office_onlyoffice_server_name], local.matrix_server_names, var.additional_server_names)) - main_server_names = [for name in local.server_names : name if !contains([local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name, local.jeannie_api_server_name, local.office_server_name, local.office_onlyoffice_server_name], name) && !contains(local.matrix_server_names, name) && !contains(local.monitoring_names, name)] + server_names = distinct(concat([var.server_name, local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name, local.searxng_server_name, local.jeannie_api_server_name, local.office_server_name, local.office_onlyoffice_server_name], local.matrix_server_names, var.additional_server_names)) + main_server_names = [for name in local.server_names : name if !contains([local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name, local.searxng_server_name, local.jeannie_api_server_name, local.office_server_name, local.office_onlyoffice_server_name], name) && !contains(local.matrix_server_names, name) && !contains(local.monitoring_names, name)] default_conf = templatefile("${path.module}/templates/default.conf.tftpl", { server_name = var.server_name monitoring_backend_host = var.monitoring_backend_host @@ -51,6 +53,9 @@ locals { jellyfin_server_name = local.jellyfin_server_name jellyfin_backend_host = local.jellyfin_backend_host jellyfin_backend_port = tostring(var.jellyfin_backend_port) + searxng_server_name = local.searxng_server_name + searxng_backend_host = local.searxng_backend_host + searxng_backend_port = tostring(var.searxng_backend_port) jeannie_api_server_name = local.jeannie_api_server_name jeannie_api_backend_host = var.jeannie_api_backend_host jeannie_api_backend_port = tostring(var.jeannie_api_backend_port) @@ -113,6 +118,8 @@ resource "null_resource" "edge_services" { oidc_port = tostring(var.oidc_backend_port) jellyfin_host = local.jellyfin_backend_host jellyfin_port = tostring(var.jellyfin_backend_port) + searxng_host = local.searxng_backend_host + searxng_port = tostring(var.searxng_backend_port) jeannie_api_host = var.jeannie_api_backend_host jeannie_api_port = tostring(var.jeannie_api_backend_port) office_host = var.office_backend_host @@ -240,6 +247,8 @@ oidc_host="${self.triggers.oidc_host}" oidc_port="${self.triggers.oidc_port}" jellyfin_host="${self.triggers.jellyfin_host}" jellyfin_port="${self.triggers.jellyfin_port}" +searxng_host="${self.triggers.searxng_host}" +searxng_port="${self.triggers.searxng_port}" jeannie_api_host="${self.triggers.jeannie_api_host}" jeannie_api_port="${self.triggers.jeannie_api_port}" enable_letsencrypt="${self.triggers.enable_letsencrypt}" @@ -343,6 +352,11 @@ if ! curl -sS --connect-timeout 10 "http://$jellyfin_host:$jellyfin_port/" >/dev echo "Check the Debian Jellyfin container and published port before testing the public hostname." >&2 fi +if ! curl -fsS --connect-timeout 10 "http://$searxng_host:$searxng_port/healthz" >/dev/null; then + echo "Warning: cannot reach SearXNG backend http://$searxng_host:$searxng_port/healthz from the edge host." >&2 + echo "Run ./jeannie deploy-searxng on Debian before testing the public hostname." >&2 +fi + if ! curl -sS --connect-timeout 10 -o /dev/null -w '%%{http_code}' "http://$jeannie_api_host:$jeannie_api_port/v1/health" | grep -Eq '^(200|401)$'; then echo "Warning: cannot reach Jeannie API backend http://$jeannie_api_host:$jeannie_api_port/v1/health from the edge host." >&2 echo "Check the Debian Jeannie API service before testing the public hostname." >&2 diff --git a/bootstrap/edge/templates/default.conf.tftpl b/bootstrap/edge/templates/default.conf.tftpl index c8c30bd..ace82e0 100644 --- a/bootstrap/edge/templates/default.conf.tftpl +++ b/bootstrap/edge/templates/default.conf.tftpl @@ -44,6 +44,7 @@ error_log /var/log/nginx/crowdsec-error.log warn; limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s; limit_req_zone $binary_remote_addr zone=jeannie_api:10m rate=5r/s; +limit_req_zone $binary_remote_addr zone=searxng_search:10m rate=30r/m; proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=static_assets:10m max_size=100m inactive=24h; proxy_cache_path /var/cache/nginx_dynamic levels=1:2 keys_zone=dynamic_content:5m max_size=50m inactive=1h; @@ -115,7 +116,7 @@ server { server { listen 80; -server_name ${heimdall_server_name} ${homepage_server_name} ${oidc_server_name} ${jellyfin_server_name} ${jeannie_api_server_name} ${office_server_name} ${office_onlyoffice_server_name}; +server_name ${heimdall_server_name} ${homepage_server_name} ${oidc_server_name} ${jellyfin_server_name} ${searxng_server_name} ${jeannie_api_server_name} ${office_server_name} ${office_onlyoffice_server_name}; location ^~ /.well-known/acme-challenge/ { root /var/www/certbot; @@ -128,6 +129,71 @@ server_name ${heimdall_server_name} ${homepage_server_name} ${oidc_server_name} } } +server { + listen 443 ssl; + http2 on; + server_name ${searxng_server_name}; + + ssl_certificate /etc/nginx/certs/current.crt; + ssl_certificate_key /etc/nginx/certs/current.key; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + ssl_session_cache shared:homelab_ssl:10m; + ssl_session_timeout 1d; + + if ($blocked_uris) { return 403; } + + add_header X-Frame-Options SAMEORIGIN; + add_header X-Content-Type-Options nosniff; + add_header Referrer-Policy no-referrer; + add_header Permissions-Policy "geolocation=(), microphone=(), camera=()"; + + location = /edge-health { + access_log off; + return 204; + } + + location = /healthz { + proxy_pass http://${searxng_backend_host}:${searxng_backend_port}/healthz; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto https; + access_log off; + } + + location = /search { + limit_req zone=searxng_search burst=10 nodelay; + proxy_pass http://${searxng_backend_host}:${searxng_backend_port}; + proxy_http_version 1.1; + proxy_buffering off; + proxy_read_timeout 60s; + proxy_set_header Connection ""; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header CF-Connecting-IP $http_cf_connecting_ip; + add_header Cache-Control "no-store"; + } + + location / { + limit_req zone=one burst=20 nodelay; + proxy_pass http://${searxng_backend_host}:${searxng_backend_port}; + proxy_http_version 1.1; + proxy_buffering off; + proxy_read_timeout 60s; + proxy_set_header Connection ""; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header CF-Connecting-IP $http_cf_connecting_ip; + add_header Cache-Control "no-store"; + } +} + server { listen 443 ssl; http2 on; diff --git a/bootstrap/edge/variables.tf b/bootstrap/edge/variables.tf index 2bfb7c4..1b6eb1f 100644 --- a/bootstrap/edge/variables.tf +++ b/bootstrap/edge/variables.tf @@ -225,6 +225,16 @@ variable "jellyfin_backend_port" { default = 8096 } +variable "searxng_backend_host" { + type = string + default = "" +} + +variable "searxng_backend_port" { + type = number + default = 8888 +} + variable "jeannie_api_backend_host" { type = string default = "" diff --git a/cmd/jeannie-server/main.go b/cmd/jeannie-server/main.go index 34084a3..39fd01a 100644 --- a/cmd/jeannie-server/main.go +++ b/cmd/jeannie-server/main.go @@ -52,7 +52,8 @@ var allowedCommands = map[string]bool{ "apps": true, "website-translation-model": true, "website-ollama-listen": true, "ollama-setup": true, "deploy-gitea": true, "deploy-api": true, "deploy-heimdall": true, - "deploy-dex": true, "deploy-matrix": true, "deploy-ai-stack": true, + "deploy-searxng": true, + "deploy-dex": true, "deploy-matrix": true, "deploy-ai-stack": true, "deploy-office": true, "deploy-ai-tools": true, "deploy-omniroute": true, "deploy-hermes": true, "rpi-services": true, "host-bootstrap": true, "bootstrap-gitea-repo": true, "repo-sync": true, "backup-gitea": true, "hermes-connect": true, diff --git a/cmd/jeannie-server/main_test.go b/cmd/jeannie-server/main_test.go index f5faf8b..2055d95 100644 --- a/cmd/jeannie-server/main_test.go +++ b/cmd/jeannie-server/main_test.go @@ -175,6 +175,12 @@ func TestOCICommandIsRemotelyEnabled(t *testing.T) { } } +func TestSearxngDeployCommandIsRemotelyEnabled(t *testing.T) { + if !allowedCommands["deploy-searxng"] { + t.Fatal("deploy-searxng must be exposed through the remote API") + } +} + func TestPublicJeannieCommandsAreRemotelyEnabled(t *testing.T) { data, err := os.ReadFile(filepath.Join("..", "..", "jeannie")) if err != nil { diff --git a/docs/app-ops.md b/docs/app-ops.md index 73c0b77..a078a4e 100644 --- a/docs/app-ops.md +++ b/docs/app-ops.md @@ -334,6 +334,20 @@ is `/data/homelab-heimdall/data/config`, and the local HTTP port is `8082`. Dashboard links are seeded from `infra/heimdall/links.json` by a sidecar container that upserts repo-managed tiles without deleting manually added ones. +## SearXNG + +SearXNG is an independent Debian-hosted Docker Compose stack, not a Kubernetes +workload. `./jeannie deploy-searxng` installs SearXNG with a private +Valkey service at `/data/homelab-searxng`, preserves its generated secret, and +waits for the local health endpoint. `./jeannie up` includes the same +deploy in its independent host-services stage. + +The OCI edge publishes `https://search.lab2025.duckdns.org/` and reaches port +`8888` on Debian over Tailscale. Both the edge and SearXNG apply request limits; +the JSON result format remains enabled for later homelab AI-tool integration. +Run the service deploy before `./jeannie edge apply` when reconciling +the route separately. + The Debian bare repo remains the GitOps mirror: ```text diff --git a/docs/jeannie.1.md b/docs/jeannie.1.md index e1970bb..912ed25 100644 --- a/docs/jeannie.1.md +++ b/docs/jeannie.1.md @@ -263,6 +263,9 @@ needed. `deploy-heimdall` : Deploy the external Heimdall Docker Compose dashboard on the Debian host. +`deploy-searxng` +: Deploy the external SearXNG and Valkey Docker Compose stack on the Debian host. + `rpi-services` : Deploy Pi-hole, Unbound, and Uptime Kuma on the Raspberry Pi. @@ -604,6 +607,18 @@ missing. Default is to fail and ask for host bootstrap. : Allow `deploy-heimdall` to install Docker through `get.docker.com` when Docker is missing. Default is to fail and ask for host bootstrap. +`LAB_SEARXNG_DEPLOY=false` +: Skip the Debian-hosted SearXNG Compose deploy during `up`. + +`LAB_SEARXNG_INSTALL_DIR` +: Install root for SearXNG. Defaults to `/data/homelab-searxng`. + +`LAB_SEARXNG_HTTP_PORT` +: Local SearXNG HTTP port. Defaults to `8888`. + +`LAB_SEARXNG_INSTALL_DOCKER=true` +: Allow `deploy-searxng` to install Docker when it is missing. Default is to fail. + `LAB_RPI_INSTALL_DOCKER=true` : Allow `rpi-services` to install Docker through `get.docker.com` on the Raspberry Pi when Docker is missing. Default is to fail. diff --git a/docs/service-catalog.md b/docs/service-catalog.md index 357015d..4b31e48 100644 --- a/docs/service-catalog.md +++ b/docs/service-catalog.md @@ -22,6 +22,7 @@ Update `homelab.yml`, then run `scripts/render-service-catalog`. | Demo Apps | Kubernetes | Argo CD / apps/demos-static | [local](http://192.168.100.240/demo-apps/) | [public](https://demos.lab2025.duckdns.org/) | `apps/demos-static/` | | Service Catalog | Kubernetes | Generated from homelab.yml | [local](http://192.168.100.240/demo-apps/homelab-catalog/) | [public](https://demos.lab2025.duckdns.org/homelab-catalog/) | `docs/service-catalog.md` | | Gitea | debian (control-plane, 192.168.100.73) | Docker Compose / jeannie deploy-gitea | [local](http://192.168.100.73:3000/) | [public](https://lab2025.duckdns.org/git/) | `infra/gitea/README.md` | +| SearXNG | debian (control-plane, 192.168.100.73) | Docker Compose / jeannie deploy-searxng | [local](http://192.168.100.73:8888/) | [public](https://search.lab2025.duckdns.org/) | `infra/searxng/README.md` | | GitOps mirror | debian (control-plane, 192.168.100.73) | Bare Git repository | `/home/jv/git-server/my-homelab-configs.git` | [public](ssh://jv@192.168.100.73/home/jv/git-server/my-homelab-configs.git) | `README.md#gitops-and-gitea-actions` | | Container Registry | debian (control-plane, 192.168.100.73) | Argo CD / apps/container-registry | [local](http://192.168.100.73:30500/v2/_catalog) | | `apps/container-registry/` | | Traefik | Kubernetes | OpenTofu / bootstrap/platform | [local](http://192.168.100.240/) | [public](https://lab2025.duckdns.org) | `README.md#loadbalancer-services` | diff --git a/docs/templates/app-ops.md.tmpl b/docs/templates/app-ops.md.tmpl index c937b9c..590a48a 100644 --- a/docs/templates/app-ops.md.tmpl +++ b/docs/templates/app-ops.md.tmpl @@ -334,6 +334,20 @@ is `/data/homelab-heimdall/data/config`, and the local HTTP port is `8082`. Dashboard links are seeded from `infra/heimdall/links.json` by a sidecar container that upserts repo-managed tiles without deleting manually added ones. +## SearXNG + +SearXNG is an independent Debian-hosted Docker Compose stack, not a Kubernetes +workload. `./{{ main_script }} deploy-searxng` installs SearXNG with a private +Valkey service at `/data/homelab-searxng`, preserves its generated secret, and +waits for the local health endpoint. `./{{ main_script }} up` includes the same +deploy in its independent host-services stage. + +The OCI edge publishes `https://search.lab2025.duckdns.org/` and reaches port +`8888` on Debian over Tailscale. Both the edge and SearXNG apply request limits; +the JSON result format remains enabled for later homelab AI-tool integration. +Run the service deploy before `./{{ main_script }} edge apply` when reconciling +the route separately. + The Debian bare repo remains the GitOps mirror: ```text diff --git a/homelab.yml b/homelab.yml index fb7013a..7394976 100644 --- a/homelab.yml +++ b/homelab.yml @@ -30,6 +30,7 @@ domain: - suwayomi.lab2025.duckdns.org - maintainerr.lab2025.duckdns.org - api.lab2025.duckdns.org + - search.lab2025.duckdns.org network: lan_cidr: 192.168.100.0/24 @@ -190,6 +191,11 @@ services: host: debian http_port: 8787 public_url: https://api.lab2025.duckdns.org/ + searxng: + host: debian + install_dir: /data/homelab-searxng + http_port: 8888 + public_url: https://search.lab2025.duckdns.org/ gitops_mirror: host: debian path: /home/jv/git-server/my-homelab-configs.git diff --git a/infra/heimdall/homepage/services.yaml b/infra/heimdall/homepage/services.yaml index 4dc8fe1..21830ba 100644 --- a/infra/heimdall/homepage/services.yaml +++ b/infra/heimdall/homepage/services.yaml @@ -15,6 +15,10 @@ href: "https://heimdall.lab2025.duckdns.org/" description: "Homelab service dashboard" icon: "heimdall.png" + - SearXNG: + href: "https://search.lab2025.duckdns.org/" + description: "Privacy-respecting homelab metasearch" + icon: "mdi-magnify" - Service Catalog: href: "https://demos.lab2025.duckdns.org/homelab-catalog/" description: "Generated host, service, route, and runbook map from homelab.yml" diff --git a/infra/heimdall/links.json b/infra/heimdall/links.json index d2d8ec0..a062a39 100644 --- a/infra/heimdall/links.json +++ b/infra/heimdall/links.json @@ -97,6 +97,13 @@ "colour": "#334155", "class": "Api" }, + { + "title": "SearXNG", + "url": "https://search.lab2025.duckdns.org/", + "description": "Privacy-respecting homelab metasearch", + "colour": "#22a699", + "class": "SearXNG" + }, { "title": "Service Catalog", "url": "https://demos.lab2025.duckdns.org/homelab-catalog/", diff --git a/infra/searxng/README.md b/infra/searxng/README.md new file mode 100644 index 0000000..19c2718 --- /dev/null +++ b/infra/searxng/README.md @@ -0,0 +1,20 @@ +# SearXNG + +Jeannie deploys SearXNG and Valkey as an independent Docker Compose stack on +the Debian services host. It is deliberately outside Kubernetes, so cluster +maintenance does not interrupt search. The OCI edge reaches the Debian service +over Tailscale and publishes `https://search.lab2025.duckdns.org/`. + +The stack enables HTML and JSON results, SearXNG's Valkey-backed limiter, image +proxying, container resource limits, and a second request limit at the OCI edge. +The generated secret remains in `/data/homelab-searxng/.env` and is never +written to Git. + +Deploy the stack and then reconcile the edge certificate and route: + +```sh +./jeannie deploy-searxng +./jeannie edge apply +``` + +The full `./jeannie up` pipeline performs both operations in the correct order. diff --git a/infra/searxng/docker-compose.yml b/infra/searxng/docker-compose.yml new file mode 100644 index 0000000..0fedbb2 --- /dev/null +++ b/infra/searxng/docker-compose.yml @@ -0,0 +1,56 @@ +name: homelab-searxng + +services: + searxng: + image: ${SEARXNG_IMAGE:-docker.io/searxng/searxng:2026.12.3-44427d4a8} + container_name: ${SEARXNG_CONTAINER_NAME:-homelab-searxng} + restart: unless-stopped + depends_on: + valkey: + condition: service_healthy + env_file: + - .env + ports: + - "${SEARXNG_BIND_IP:-0.0.0.0}:${SEARXNG_HTTP_PORT:-8888}:8080/tcp" + volumes: + - ./config:/etc/searxng:ro + - searxng-cache:/var/cache/searxng + security_opt: + - no-new-privileges:true + mem_limit: 768m + pids_limit: 256 + healthcheck: + test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/healthz', timeout=3)"] + interval: 30s + timeout: 5s + retries: 5 + start_period: 30s + networks: + - searxng + + valkey: + image: ${VALKEY_IMAGE:-docker.io/valkey/valkey:9-alpine} + container_name: ${VALKEY_CONTAINER_NAME:-homelab-searxng-valkey} + restart: unless-stopped + command: valkey-server --save 300 1 --save 60 1000 --loglevel warning + volumes: + - searxng-valkey:/data + security_opt: + - no-new-privileges:true + mem_limit: 128m + pids_limit: 64 + healthcheck: + test: ["CMD", "valkey-cli", "ping"] + interval: 15s + timeout: 3s + retries: 5 + networks: + - searxng + +networks: + searxng: + name: homelab-searxng + +volumes: + searxng-cache: + searxng-valkey: diff --git a/infra/searxng/limiter.toml b/infra/searxng/limiter.toml new file mode 100644 index 0000000..130d92e --- /dev/null +++ b/infra/searxng/limiter.toml @@ -0,0 +1,8 @@ +[botdetection] +trusted_proxies = [ + "127.0.0.0/8", + "172.16.0.0/12", +] + +[botdetection.ip_limit] +link_token = false diff --git a/infra/searxng/settings.yml b/infra/searxng/settings.yml new file mode 100644 index 0000000..2b5b4b6 --- /dev/null +++ b/infra/searxng/settings.yml @@ -0,0 +1,34 @@ +use_default_settings: true + +general: + debug: false + instance_name: "Juvenal's Homelab Search" + +search: + safe_search: 0 + autocomplete: "" + formats: + - html + - json + +server: + limiter: true + public_instance: false + image_proxy: true + method: GET + default_http_headers: + X-Content-Type-Options: nosniff + X-Download-Options: noopen + X-Robots-Tag: noindex, nofollow + Referrer-Policy: no-referrer + +ui: + static_use_hash: true + query_in_title: false + +valkey: + url: valkey://valkey:6379/0 + +outgoing: + request_timeout: 6.0 + max_request_timeout: 15.0 diff --git a/jeannie b/jeannie index 82256a0..557630b 100755 --- a/jeannie +++ b/jeannie @@ -79,6 +79,7 @@ Build And Bootstrap deploy-gitea Deploy the Debian-hosted Gitea container. deploy-api Deploy the Temporal-backed Jeannie API on Debian. deploy-heimdall Deploy the Debian-hosted Heimdall dashboard. + deploy-searxng Deploy Debian-hosted SearXNG and Valkey. deploy-dex Deploy the Debian-hosted Dex SSO stack. monitoring {plan|migrate|apply|refresh|exporters|status|validate} Manage Debian monitoring; preserve cluster discovery and Dex. deploy-office Deploy Nextcloud + ONLYOFFICE online office. @@ -696,6 +697,10 @@ case "${1:-}" in record_change_journal "deploy-heimdall" "$@" deploy_heimdall ;; + deploy-searxng) + record_change_journal "deploy-searxng" "$@" + deploy_searxng + ;; deploy-dex) record_change_journal "deploy-dex" "$@" deploy_dex diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index 49528f6..ad9568a 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -2458,6 +2458,7 @@ status_report() { fi status_compose_stack "gitea" "/data/homelab-gitea" status_compose_stack "heimdall" "${LAB_HEIMDALL_INSTALL_DIR:-/data/homelab-heimdall}" + status_compose_stack "searxng" "${LAB_SEARXNG_INSTALL_DIR:-/data/homelab-searxng}" status_compose_stack "dex" "${LAB_DEX_INSTALL_DIR:-/data/homelab-dex}" status_compose_stack "arr-stack" "${REPO_ROOT}/infra/arr-stack" @@ -2477,6 +2478,7 @@ status_report() { status_http "website public" "${LAB_PUBLIC_URL:?LAB_PUBLIC_URL is required from homelab.yml}/" status_http "gitea public" "${LAB_GITEA_ROOT_URL:-${LAB_PUBLIC_URL:?LAB_PUBLIC_URL is required from homelab.yml}/git/}" status_http "heimdall public" "${LAB_HEIMDALL_PUBLIC_URL:-https://heimdall.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/}" + status_http "searxng public" "${LAB_SEARXNG_PUBLIC_URL:-https://search.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/}" status_http "dex public" "${LAB_DEX_PUBLIC_URL:-https://auth.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/}" status_http "gitea local" "http://127.0.0.1:${LAB_GITEA_HTTP_PORT:-3000}/" status_http "heimdall local" "http://127.0.0.1:${LAB_HEIMDALL_HTTP_PORT:-8082}/" @@ -3107,6 +3109,7 @@ doctor_homelab() { report_ui_check fail "Debian Services" "Gitea container" "./jeannie deploy-gitea" "" "" status_container_running "${GITEA_CONTAINER_NAME:-homelab-gitea}" || failures=$((failures + 1)) report_ui_check fail "Debian Services" "Gitea local HTTP" "./jeannie deploy-gitea" "" "" status_http_ok "http://127.0.0.1:${LAB_GITEA_HTTP_PORT:-3000}/" || failures=$((failures + 1)) report_ui_check fail "Debian Services" "Dex local HTTP" "./jeannie deploy-dex" "" "" status_dex_local_ok || failures=$((failures + 1)) + report_ui_check fail "Debian Services" "SearXNG local HTTP" "./jeannie deploy-searxng" "" "" status_http_ok "http://127.0.0.1:${LAB_SEARXNG_HTTP_PORT:-8888}/healthz" || failures=$((failures + 1)) report_ui_check warn "Debian Services" "Ollama API" "./jeannie ollama-setup" "" "" status_ollama_local_ok report_ui_check warn "Debian Services" "Gitea runner service" "./jeannie install-gitea-runner" "" "" check_systemd_active homelab-gitea-runner @@ -3121,6 +3124,7 @@ doctor_homelab() { report_ui_check fail "Edge/Public" "Argo CD public URL" "./jeannie platform" "" "" status_http_reachable "https://argocd.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/" || failures=$((failures + 1)) report_ui_check fail "Edge/Public" "Demos public URL" "./jeannie apps" "" "" status_http_ok "https://demos.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/" || failures=$((failures + 1)) report_ui_check fail "Edge/Public" "Dex public URL" "./jeannie deploy-dex" "" "" status_http_reachable "${LAB_DEX_PUBLIC_URL:-https://auth.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/}" || failures=$((failures + 1)) + report_ui_check fail "Edge/Public" "SearXNG public URL" "./jeannie deploy-searxng && ./jeannie edge apply" "" "" status_http_ok "${LAB_SEARXNG_PUBLIC_URL:-https://search.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/}" || failures=$((failures + 1)) report_ui_check warn "Operations" "Backup freshness" "./jeannie backup" "" "" backup_status report_ui_check warn "Operations" "Disk usage" "df -h / /data" "" "" status_disk_pressure @@ -3154,8 +3158,10 @@ doctor_homelab() { status_systemd_units docker tailscaled homelab-gitea-runner status_compose_stack "gitea" "/data/homelab-gitea" status_compose_stack "dex" "${LAB_DEX_INSTALL_DIR:-/data/homelab-dex}" + status_compose_stack "searxng" "${LAB_SEARXNG_INSTALL_DIR:-/data/homelab-searxng}" status_http "gitea local" "http://127.0.0.1:${LAB_GITEA_HTTP_PORT:-3000}/" status_http "dex local" "http://127.0.0.1:${LAB_DEX_HTTP_PORT:-5556}/healthz" + status_http "searxng local" "http://127.0.0.1:${LAB_SEARXNG_HTTP_PORT:-8888}/healthz" status_http "ollama" "${LAB_OLLAMA_URL:-http://${LAB_DEBIAN_LAN_IP:-192.168.100.73}:11434}/api/tags" status_section "Edge And Public URLs" @@ -3166,6 +3172,7 @@ doctor_homelab() { status_http "argocd public" "https://argocd.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/" status_http "demos public" "https://demos.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/" status_http "dex public" "${LAB_DEX_PUBLIC_URL:-https://auth.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/}" + status_http "searxng public" "${LAB_SEARXNG_PUBLIC_URL:-https://search.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/}" status_section "Operations" backup_status || true diff --git a/lib/jeannie/env.sh b/lib/jeannie/env.sh index d8740b5..440cd4d 100644 --- a/lib/jeannie/env.sh +++ b/lib/jeannie/env.sh @@ -67,6 +67,9 @@ mapping = { "services.jellyfin.http_port": "LAB_JELLYFIN_HTTP_PORT", "services.jellyfin.public_url": "LAB_JELLYFIN_PUBLIC_URL", "services.jeannie_api.http_port": "LAB_JEANNIE_API_BACKEND_PORT", + "services.searxng.install_dir": "LAB_SEARXNG_INSTALL_DIR", + "services.searxng.http_port": "LAB_SEARXNG_HTTP_PORT", + "services.searxng.public_url": "LAB_SEARXNG_PUBLIC_URL", "services.local_registry.endpoint": "LAB_REGISTRY_ENDPOINT", "services.ollama.url": "LAB_OLLAMA_URL", "services.ollama.bind_address": "LAB_OLLAMA_BIND_ADDRESS", @@ -231,6 +234,7 @@ for service_name, env_name in [ ("homepage", "LAB_HOMEPAGE_BACKEND_HOST"), ("dex", "LAB_DEX_BACKEND_HOST"), ("jellyfin", "LAB_JELLYFIN_BACKEND_HOST"), + ("searxng", "LAB_SEARXNG_BACKEND_HOST"), ]: service_lan = service_host_value(service_name, "lan_ip") or services_host_lan service_tailscale = service_host_value(service_name, "tailscale_ip") or services_host_tailscale @@ -340,6 +344,8 @@ export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_gitea_auth_source_name "${LAB_GITEA_DEX_SOURCE_NAME:-dex}" export_if_unset TF_VAR_jellyfin_backend_host "${LAB_JELLYFIN_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" export_if_unset TF_VAR_jellyfin_backend_port "${LAB_JELLYFIN_HTTP_PORT:-}" + export_if_unset TF_VAR_searxng_backend_host "${LAB_SEARXNG_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" + export_if_unset TF_VAR_searxng_backend_port "${LAB_SEARXNG_HTTP_PORT:-8888}" export_if_unset TF_VAR_office_server_name "${LAB_OFFICE_PUBLIC_HOST:-office.${LAB_DOMAIN:-lab2025.duckdns.org}}" export_if_unset TF_VAR_office_backend_host "${LAB_OFFICE_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-${LAB_DEBIAN_LAN_IP:-}}}" export_if_unset TF_VAR_office_backend_port "${LAB_OFFICE_HTTP_PORT:-8090}" diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 482d877..0a0ec1d 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -5453,6 +5453,99 @@ ENV_EOT echo "Homepage is reachable at http://127.0.0.1:${homepage_http_port}/ and ${homepage_public_url%/}/." } +deploy_searxng() { + local mode="${LAB_SEARXNG_DEPLOY:-true}" + local install_dir="${LAB_SEARXNG_INSTALL_DIR:-/data/homelab-searxng}" + local http_port="${LAB_SEARXNG_HTTP_PORT:-8888}" + local bind_ip="${LAB_SEARXNG_BIND_IP:-0.0.0.0}" + local public_url="${LAB_SEARXNG_PUBLIC_URL:-https://search.${LAB_DOMAIN:-lab2025.duckdns.org}/}" + local image="${SEARXNG_IMAGE:-docker.io/searxng/searxng:2026.12.3-44427d4a8}" + local valkey_image="${VALKEY_IMAGE:-docker.io/valkey/valkey:9-alpine}" + local container_name="${SEARXNG_CONTAINER_NAME:-homelab-searxng}" + local valkey_container_name="${VALKEY_CONTAINER_NAME:-homelab-searxng-valkey}" + local source_dir="${REPO_ROOT}/infra/searxng" + local install_docker="${LAB_SEARXNG_INSTALL_DOCKER:-false}" + local secret="" + local elapsed=0 + local value_name + local value + + require_debian_server "deploy-searxng" + + if disabled_value "${mode}"; then + return 0 + fi + + for value_name in install_dir http_port bind_ip public_url image valkey_image container_name valkey_container_name install_docker; do + value="${!value_name}" + if [[ "${value}" == *$'\n'* ]]; then + echo "${value_name} cannot contain a newline." >&2 + return 1 + fi + done + if ! [[ "${http_port}" =~ ^[0-9]+$ ]] || ((http_port < 1 || http_port > 65535)); then + echo "LAB_SEARXNG_HTTP_PORT must be a valid TCP port." >&2 + return 1 + fi + if [[ ! -s "${source_dir}/docker-compose.yml" || ! -s "${source_dir}/settings.yml" || ! -s "${source_dir}/limiter.toml" ]]; then + echo "Missing SearXNG source files in ${source_dir}." >&2 + return 1 + fi + + ensure_local_docker_compose "SEARXNG" "${install_docker}" + repair_local_docker_iptables + + sudo mkdir -p "${install_dir}/config" + sudo cp "${source_dir}/docker-compose.yml" "${install_dir}/docker-compose.yml" + sudo cp "${source_dir}/settings.yml" "${install_dir}/config/settings.yml" + sudo cp "${source_dir}/limiter.toml" "${install_dir}/config/limiter.toml" + sudo chmod 0644 "${install_dir}/docker-compose.yml" "${install_dir}/config/settings.yml" "${install_dir}/config/limiter.toml" + + if sudo test -s "${install_dir}/.env"; then + secret="$(sudo sed -n 's/^SEARXNG_SECRET=//p' "${install_dir}/.env" | head -n 1)" + fi + if ! [[ "${secret}" =~ ^[[:xdigit:]]{64}$ ]]; then + secret="$(openssl rand -hex 32)" + fi + + umask 077 + printf '%s\n' \ + "SEARXNG_IMAGE=${image}" \ + "VALKEY_IMAGE=${valkey_image}" \ + "SEARXNG_CONTAINER_NAME=${container_name}" \ + "VALKEY_CONTAINER_NAME=${valkey_container_name}" \ + "SEARXNG_BIND_IP=${bind_ip}" \ + "SEARXNG_HTTP_PORT=${http_port}" \ + "SEARXNG_PORT=8080" \ + "SEARXNG_BASE_URL=${public_url%/}/" \ + "SEARXNG_SECRET=${secret}" \ + "SEARXNG_LIMITER=true" \ + "SEARXNG_PUBLIC_INSTANCE=false" \ + "SEARXNG_IMAGE_PROXY=true" \ + "SEARXNG_VALKEY_URL=valkey://valkey:6379/0" | + sudo tee "${install_dir}/.env" >/dev/null + sudo chmod 0600 "${install_dir}/.env" + + ( + cd "${install_dir}" + sudo docker compose pull + sudo docker compose up -d --remove-orphans + sudo docker compose ps + ) + + until curl -fsS --connect-timeout 5 "http://127.0.0.1:${http_port}/healthz" >/dev/null; do + if ((elapsed >= 180)); then + echo "Timed out waiting for SearXNG on http://127.0.0.1:${http_port}/healthz" >&2 + (cd "${install_dir}" && sudo docker compose ps && sudo docker compose logs --tail=160) >&2 || true + return 1 + fi + sleep 5 + elapsed=$((elapsed + 5)) + done + + echo "SearXNG is healthy at http://127.0.0.1:${http_port}/ and will be published at ${public_url%/}/ by the edge stage." +} + deploy_matrix() { local mode="${LAB_MATRIX_DEPLOY:-true}" local install_dir="${LAB_MATRIX_INSTALL_DIR:-/home/jv/matrix-server}" @@ -8881,6 +8974,11 @@ spec = { "title": "Heimdall deploy", "command": [jeannie, "__up-task", "heimdall-deploy"], }, + { + "id": "searxng-deploy", + "title": "SearXNG deploy", + "command": [jeannie, "__up-task", "searxng-deploy"], + }, { "id": "dex-deploy", "title": "Dex deploy", @@ -8962,6 +9060,9 @@ up_task() { heimdall-deploy) deploy_heimdall ;; + searxng-deploy) + deploy_searxng + ;; dex-deploy) deploy_dex ;; diff --git a/scripts/generate-heimdall-links b/scripts/generate-heimdall-links index 0098e27..0541310 100755 --- a/scripts/generate-heimdall-links +++ b/scripts/generate-heimdall-links @@ -50,6 +50,7 @@ HOST_METADATA = { "suwayomi": ("Suwayomi", "Manga server and scraper engine", "#8b5cf6", "Suwayomi"), "maintainerr": ("Maintainerr", "Media list maintenance automation", "#14b8a6", "Maintainerr"), "flaresolverr": ("FlareSolverr", "Browser challenge solver service for ARR automation", "#64748b", "FlareSolverr"), + "search": ("SearXNG", "Privacy-respecting homelab metasearch", "#22a699", "SearXNG"), } diff --git a/scripts/generate-homepage-config b/scripts/generate-homepage-config index e77a768..2e662e0 100755 --- a/scripts/generate-homepage-config +++ b/scripts/generate-homepage-config @@ -20,6 +20,7 @@ SERVICE_GROUPS = { "Homepage": "Public", "Heimdall": "Public", "Service Catalog": "Public", + "SearXNG": "Public", "Gitea": "Platform", "Argo CD": "Platform", "Grafana": "Platform", @@ -63,6 +64,7 @@ ICON_MAP = { "Homepage": "homepage.png", "Heimdall": "heimdall.png", "Service Catalog": "mdi-map", + "SearXNG": "mdi-magnify", "Gitea": "gitea.png", "Argo CD": "argocd.png", "Grafana": "grafana.png", diff --git a/scripts/render-service-catalog b/scripts/render-service-catalog index d83fe6a..5fdc2cc 100755 --- a/scripts/render-service-catalog +++ b/scripts/render-service-catalog @@ -128,6 +128,14 @@ def service_rows(values: dict[str, object]) -> list[dict[str, str]]: "public": value(values, "services.gitea.root_url"), "docs": "infra/gitea/README.md", }, + { + "name": "SearXNG", + "host": value(values, "services.searxng.host", "debian"), + "managed_by": "Docker Compose / jeannie deploy-searxng", + "local": f"http://{debian_ip}:{value(values, 'services.searxng.http_port', '8888')}/", + "public": value(values, "services.searxng.public_url", f"https://search.{domain}/"), + "docs": "infra/searxng/README.md", + }, { "name": "GitOps mirror", "host": value(values, "services.gitops_mirror.host", "debian"), diff --git a/scripts/validate-homelab b/scripts/validate-homelab index 51f1f66..3c61e13 100755 --- a/scripts/validate-homelab +++ b/scripts/validate-homelab @@ -133,6 +133,7 @@ validate_unit_tests() { python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_monitoring_loki.py' python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_monitoring_debian.py' python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_monitoring_readiness.py' + python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_searxng_pipeline.py' python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_doctor_k3s_storage.py' python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_holmes_evidence.py' if [[ -x "${LAB_HOLMES_ADAPTER_PYTHON:-/home/jv/.local/share/pipx/venvs/holmesgpt/bin/python}" ]]; then diff --git a/scripts/validate-homelab-inventory b/scripts/validate-homelab-inventory index f18c267..09adbf8 100755 --- a/scripts/validate-homelab-inventory +++ b/scripts/validate-homelab-inventory @@ -70,12 +70,14 @@ else: "hosts.oci_edge.public_ip", "services.gitea.root_url", "services.heimdall.public_url", + "services.searxng.public_url", "services.local_registry.endpoint", "services.traefik.load_balancer_ip", ): require(path) require("pimox.default_worker_count", None) require("services.heimdall.http_port", None) + require("services.searxng.http_port", None) subdomains = require("domain.subdomains", list) if isinstance(subdomains, list): @@ -165,6 +167,8 @@ required_paths = %w[ services.gitea.root_url services.heimdall.http_port services.heimdall.public_url + services.searxng.http_port + services.searxng.public_url services.local_registry.endpoint services.traefik.load_balancer_ip pimox.default_worker_count diff --git a/tests/jeannie/test_searxng_pipeline.py b/tests/jeannie/test_searxng_pipeline.py new file mode 100644 index 0000000..ddd25fe --- /dev/null +++ b/tests/jeannie/test_searxng_pipeline.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +import pathlib +import unittest + + +ROOT = pathlib.Path(__file__).resolve().parents[2] + + +class SearxngPipelineTests(unittest.TestCase): + def test_compose_has_isolated_valkey_and_resource_limits(self): + compose = (ROOT / "infra/searxng/docker-compose.yml").read_text(encoding="utf-8") + self.assertIn("name: homelab-searxng", compose) + self.assertIn("valkey:", compose) + self.assertIn("mem_limit: 768m", compose) + self.assertIn("searxng:2026.12.3-44427d4a8", compose) + self.assertNotIn("valkey/valkey:latest", compose) + + def test_settings_enable_limiter_and_json(self): + settings = (ROOT / "infra/searxng/settings.yml").read_text(encoding="utf-8") + self.assertIn("limiter: true", settings) + self.assertIn("url: valkey://valkey:6379/0", settings) + self.assertIn("- json", settings) + + def test_edge_has_dedicated_route_not_generic_backend(self): + main = (ROOT / "bootstrap/edge/main.tf").read_text(encoding="utf-8") + nginx = (ROOT / "bootstrap/edge/templates/default.conf.tftpl").read_text(encoding="utf-8") + self.assertIn('searxng_server_name = "search.${var.server_name}"', main) + self.assertIn("server_name ${searxng_server_name};", nginx) + self.assertIn("zone=searxng_search", nginx) + self.assertIn("proxy_pass http://${searxng_backend_host}:${searxng_backend_port}", nginx) + + def test_pipeline_preserves_secret_and_checks_health(self): + pipeline = (ROOT / "lib/jeannie/pipeline.sh").read_text(encoding="utf-8") + self.assertIn("deploy_searxng()", pipeline) + self.assertIn('"id": "searxng-deploy"', pipeline) + self.assertIn("SEARXNG_SECRET=//p", pipeline) + self.assertIn('openssl rand -hex 32', pipeline) + self.assertIn('${http_port}/healthz', pipeline) + + +if __name__ == "__main__": + unittest.main()