services:
  codexmanager:
    container_name: codexmanager
    image: registry.cn-hangzhou.aliyuncs.com/kilimiao/codex-manager:latest
    pull_policy: always
    restart: unless-stopped
    labels:
      com.centurylinklabs.watchtower.enable: "true"
    init: true
    # NAS Docker panels often create bind-mounted folders with host-only ownership
    # and do not expose chown/chmod controls. Run as root so /data stays writable.
    user: "0:0"
    environment:
      CODEXMANAGER_SERVICE_ADDR: 0.0.0.0:48760
      CODEXMANAGER_WEB_ADDR: 0.0.0.0:48761
      CODEXMANAGER_WEB_NO_OPEN: "1"
      TZ: ${TZ:-Asia/Shanghai}
      CODEXMANAGER_DB_PATH: /data/codexmanager.db
      CODEXMANAGER_RPC_TOKEN_FILE: /data/codexmanager.rpc-token
      CODEXMANAGER_GATEWAY_TRACE_STDOUT: "1"
      CODEXMANAGER_GATEWAY_ERROR_STDOUT: "1"
      # Optional mitigation for same key/path/model head-of-line gate waits:
      # CODEXMANAGER_REQUEST_GATE_WAIT_TIMEOUT_MS: "5000"
      # If the host machine provides an HTTP proxy, use:
      # CODEXMANAGER_UPSTREAM_PROXY_URL: http://host.docker.internal:7890
    volumes:
      # For normal Linux servers you can also run as UID/GID 10001 and chown this
      # folder, but NAS environments such as ZSpace are usually easier with root.
      - ./data:/data
    ports:
      - "48761:48761"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    stop_grace_period: 20s

  codexmanager-ota:
    image: containrrr/watchtower:1.7.1
    profiles:
      - ota
    restart: unless-stopped
    command:
      - --label-enable
      - --interval
      - "${CODEXMANAGER_OTA_INTERVAL:-300}"
      - --monitor-only
      - --cleanup
      - --rolling-restart
      - --stop-timeout
      - 20s
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

  codexmanager-ota-auto:
    image: containrrr/watchtower:1.7.1
    profiles:
      - ota-auto
    restart: unless-stopped
    command:
      - --label-enable
      - --interval
      - "${CODEXMANAGER_OTA_INTERVAL:-300}"
      - --cleanup
      - --rolling-restart
      - --stop-timeout
      - 20s
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro