fix(searxng): Env-Substitution über Python statt !env-YAML-Tag
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m15s

SearXNG v2026 kennt keinen !env-YAML-Constructor — Container crasht
mit „could not determine a constructor for the tag '!env'". Fix: wir
mounten settings.yml read-only auf /config-src, und ein Entrypoint-Hook
schreibt beim Start eine expandierte Fassung nach /etc/searxng/settings.yml
(mit os.path.expandvars — Python ist im Image, envsubst fehlt).

- settings.yml: api_key nutzt jetzt ${BRAVE_API_KEY} statt !env.
- docker-compose.prod.yml: searxng-Container bekommt entrypoint-
  Override, reicht BRAVE_API_KEY + SEARXNG_SECRET als Env durch und
  expandiert das YAML vor exec.

Leerer Key ist weiterhin ok — Brave antwortet dann mit 401, andere
Engines bleiben unberührt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-18 13:56:18 +02:00
parent 553bf4f924
commit 49d4e60a1c
2 changed files with 23 additions and 3 deletions

View File

@@ -33,14 +33,31 @@ services:
searxng:
# Absichtlich nur intern erreichbar — keine Traefik-Labels, kein externer Port.
image: searxng/searxng:latest
# settings.yml wird read-only gemountet und beim Start in eine beschreib-
# bare /etc/searxng-Kopie expandiert (${…}-Platzhalter → ENV-Werte),
# damit der Brave-API-Key aus .env eingesetzt werden kann, ohne ihn im
# Repo zu pflegen. SearXNG selbst hat kein !env-Tag, daher machen wir
# es per Python im Entrypoint-Hook. Das SearXNG-Image hat Python bereits
# installiert; envsubst fehlt im Alpine-Base.
volumes:
- ./searxng:/etc/searxng
- ./searxng:/config-src:ro
environment:
- BASE_URL=http://searxng:8080/
- INSTANCE_NAME=kochwas-search
# Brave Search API-Key aus .env (auf dem Pi gepflegt, nicht im Repo).
# Leer oder fehlend → brave-Engine ist im settings.yml disabled/default.
# Leer oder fehlend → brave-Engine antwortet mit 401, andere Engines
# laufen normal weiter.
- BRAVE_API_KEY=${BRAVE_API_KEY:-}
- SEARXNG_SECRET=${SEARXNG_SECRET:-dev-secret-change-in-prod}
entrypoint:
- /bin/sh
- -c
- |
set -e
mkdir -p /etc/searxng
python3 -c "import os,sys; sys.stdout.write(os.path.expandvars(open('/config-src/settings.yml').read()))" > /etc/searxng/settings.yml
exec /usr/local/searxng/dockerfiles/docker-entrypoint.sh "$@"
- --
restart: unless-stopped
networks:
- internal