name: sabnzbd-bench
services:
  sabnzbd:
    container_name: sabnzbd
    deploy:
      resources:
        limits:
          memory: "1073741824"
    entrypoint:
      - /bin/sh
      - -c
      - |
        CONF=/config/sabnzbd.ini
        if [ ! -f "$$CONF" ]; then
          mkdir -p /config
          {
            printf '%s\n' '[misc]'
            printf '%s\n' 'host = 0.0.0.0'
            printf '%s\n' 'port = 8080'
            printf '%s\n' 'username = admin'
            printf 'password = %s\n' "$$SAB_ADMIN_PASSWORD"
            printf 'api_key = %s\n' "$$SAB_API_KEY"
            printf '%s\n' 'inet_exposure = 5'
            printf 'host_whitelist = %s, sabnzbd, localhost, 127.0.0.1\n' "$$SAB_PUBLIC_HOST"
            printf '%s\n' 'download_dir = /incomplete-downloads'
            printf '%s\n' 'complete_dir = /downloads'
            printf '%s\n' 'check_new_rel = 0'
            printf '%s\n' 'auto_browser = 0'
          } > "$$CONF"
          chmod 600 "$$CONF"
        fi
        exec /init
    environment:
      PGID: "1000"
      PUID: "1000"
      SAB_ADMIN_PASSWORD: 85tZ4avOYyifUzc8NxqXHxZ3
      SAB_API_KEY: 5d3aa684c50b0f13893eebf2e470fb4d
      SAB_PUBLIC_HOST: usenet.bench.local
      TZ: Europe/Budapest
      UMASK: "022"
    healthcheck:
      test:
        - CMD-SHELL
        - curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8080/ | grep -qE '^(200|401)$$'
      timeout: 5s
      interval: 30s
      retries: 3
      start_period: 1m0s
    image: lscr.io/linuxserver/sabnzbd:version-5.1.3
    labels:
      traefik.enable: "true"
      traefik.http.routers.sabnzbd.entrypoints: websecure
      traefik.http.routers.sabnzbd.rule: Host(`usenet.bench.local`)
      traefik.http.routers.sabnzbd.tls: "true"
      traefik.http.routers.sabnzbd.tls.certresolver: letsencrypt
      traefik.http.services.sabnzbd.loadbalancer.server.port: "8080"
    networks:
      traefik-public: null
    restart: unless-stopped
    volumes:
      - type: volume
        source: sabnzbd_config
        target: /config
        volume: {}
      - type: bind
        source: /opt/sabnzbd-bench/userdata/media/usenet/complete
        target: /downloads
        bind:
          create_host_path: true
      - type: bind
        source: /opt/sabnzbd-bench/userdata/media/usenet/incomplete
        target: /incomplete-downloads
        bind:
          create_host_path: true
networks:
  traefik-public:
    name: traefik-public
    external: true
volumes:
  sabnzbd_config:
    name: sabnzbd-bench_sabnzbd_config
