# https://github.com/searxng/searxng-docker/blob/master/docker-compose.yaml
x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  caddy:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}caddy:${CADDY_VERSION:-2-alpine}
    network_mode: host
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy-data:/data
      - caddy-config:/config
    environment:
      - SEARXNG_HOSTNAME=${SEARXNG_HOSTNAME:-http://localhost}
      - SEARXNG_TLS=${LETSENCRYPT_EMAIL:-internal}
      - TZ=${TZ:-UTC}
    cap_drop:
      - ALL
    cap_add:
      - NET_BIND_SERVICE
    healthcheck:
      test: [CMD, wget, --spider, -q, 'http://localhost:2019/config/']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    deploy:
      resources:
        limits:
          cpus: ${SEARXNG_CADDY_CPU_LIMIT:-0.5}
          memory: ${SEARXNG_CADDY_MEMORY_LIMIT:-256M}
        reservations:
          cpus: ${SEARXNG_CADDY_CPU_RESERVATION:-0.1}
          memory: ${SEARXNG_CADDY_MEMORY_RESERVATION:-64M}

  redis:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}valkey/valkey:${VALKEY_VERSION:-8-alpine}
    command: valkey-server --save 30 1 --loglevel warning
    networks:
      - searxng
    volumes:
      - valkey-data:/data
    cap_drop:
      - ALL
    cap_add:
      - SETGID
      - SETUID
      - DAC_OVERRIDE
    healthcheck:
      test: [CMD, valkey-cli, ping]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    deploy:
      resources:
        limits:
          cpus: ${SEARXNG_REDIS_CPU_LIMIT:-0.5}
          memory: ${SEARXNG_REDIS_MEMORY_LIMIT:-256M}
        reservations:
          cpus: ${SEARXNG_REDIS_CPU_RESERVATION:-0.1}
          memory: ${SEARXNG_REDIS_MEMORY_RESERVATION:-64M}

  searxng:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}searxng/searxng:${SEARXNG_VERSION:-2025.1.20-1ce14ef99}
    networks:
      - searxng
    ports:
      - '${SEARXNG_PORT_OVERRIDE:-8080}:8080'
    volumes:
      - ./searxng:/etc/searxng:rw
    environment:
      - SEARXNG_BASE_URL=https://${SEARXNG_HOSTNAME:-localhost}/
      - UWSGI_WORKERS=${SEARXNG_UWSGI_WORKERS:-4}
      - UWSGI_THREADS=${SEARXNG_UWSGI_THREADS:-4}
      - TZ=${TZ:-UTC}
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    depends_on:
      redis:
        condition: service_healthy
    healthcheck:
      test: [CMD, wget, --spider, -q, 'http://localhost:8080/healthz']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    deploy:
      resources:
        limits:
          cpus: ${SEARXNG_CPU_LIMIT:-1.0}
          memory: ${SEARXNG_MEMORY_LIMIT:-1G}
        reservations:
          cpus: ${SEARXNG_CPU_RESERVATION:-0.1}
          memory: ${SEARXNG_MEMORY_RESERVATION:-256M}

networks:
  searxng:

volumes:
  caddy-data:
  caddy-config:
  valkey-data:
