x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  stable-diffusion-webui:
    <<: *defaults
    image: ${GHCR_IO_REGISTRY:-ghcr.io}/absolutelyludicrous/sdnext:${SD_WEBUI_VERSION:-latest}
    ports:
      - '${SD_WEBUI_PORT_OVERRIDE:-7860}:7860'
    environment:
      TZ: ${TZ:-UTC}
      CLI_ARGS: ${CLI_ARGS:---listen --api --skip-version-check}
      NVIDIA_VISIBLE_DEVICES: ${NVIDIA_VISIBLE_DEVICES:-all}
      NVIDIA_DRIVER_CAPABILITIES: ${NVIDIA_DRIVER_CAPABILITIES:-compute,utility}
    volumes:
      - sd_webui_data:/data
      - sd_webui_output:/output
    deploy:
      resources:
        limits:
          cpus: ${SD_WEBUI_CPU_LIMIT:-4.0}
          memory: ${SD_WEBUI_MEMORY_LIMIT:-16G}
        reservations:
          cpus: ${SD_WEBUI_CPU_RESERVATION:-0.1}
          memory: ${SD_WEBUI_MEMORY_RESERVATION:-8G}
          devices:
            - driver: nvidia
              count: ${GPU_COUNT:-1}
              capabilities: [gpu]
    healthcheck:
      test: [CMD, wget, --no-verbose, --tries=1, --spider, 'http://localhost:7860/']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 120s

volumes:
  sd_webui_data:
  sd_webui_output:
