services:
  # ==================== 反代 ====================
  caddy:
    build:
      context: ./caddy
    image: juwan-center/caddy:wt
    container_name: juwan-caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy-data:/data
      - caddy-config:/config
    depends_on:
      - gitea
      - zot
      - garage

  # ==================== 容器仓库 ====================
  zot:
    image: ghcr.io/project-zot/zot:v2.1.16
    container_name: juwan-zot
    restart: unless-stopped
    command: ["serve", "/etc/zot/config.json"]
    volumes:
      - ./zot/config.json:/etc/zot/config.json:ro
      - ./zot/htpasswd:/etc/zot/htpasswd:ro
      - zot-data:/var/lib/registry
    expose:
      - "5000"

  # ==================== S3 对象存储 ====================
  garage:
    image: dxflrs/garage:v2.3.0
    container_name: juwan-garage
    restart: unless-stopped
    command: ["/garage", "server"]
    volumes:
      - ./garage/garage.toml:/etc/garage.toml:ro
      - garage-meta:/var/lib/garage/meta
      - garage-data:/var/lib/garage/data
    expose:
      - "3900"
      - "3901"
      - "3902"
      - "3903"

  # ==================== Git 服务 ====================
  gitea:
    image: docker.gitea.com/gitea:1.26.1
    container_name: juwan-gitea
    restart: unless-stopped
    environment:
      USER_UID: "1000"
      USER_GID: "1000"
      GITEA__database__DB_TYPE: sqlite3
      GITEA__server__DOMAIN: ${GITEA_DOMAIN}
      GITEA__server__ROOT_URL: https://${GITEA_DOMAIN}/
      GITEA__server__PROTOCOL: http
      GITEA__server__HTTP_PORT: "3000"
      GITEA__server__DISABLE_SSH: "true"
      GITEA__service__DISABLE_REGISTRATION: "true"
      GITEA__security__INSTALL_LOCK: "true"
      GITEA__actions__ENABLED: "true"
    volumes:
      - gitea-data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    expose:
      - "3000"
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/api/healthz >/dev/null || exit 1"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 30s

  # ==================== CI/CD 执行器 ====================
  runner:
    image: gitea/act_runner:0.6.1
    container_name: juwan-runner
    restart: unless-stopped
    environment:
      GITEA_INSTANCE_URL: http://gitea:3000
      GITEA_RUNNER_REGISTRATION_TOKEN: ${RUNNER_TOKEN}
      GITEA_RUNNER_NAME: juwan-center
      GITEA_RUNNER_LABELS: ubuntu-latest:docker://docker.gitea.com/runner-images:ubuntu-latest-slim
      CONFIG_FILE: /data/config.yaml
    volumes:
      - runner-data:/data
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      gitea:
        condition: service_healthy

volumes:
  caddy-data:
    name: juwan-caddy-data
  caddy-config:
    name: juwan-caddy-config
  zot-data:
    name: juwan-zot-data
  garage-meta:
    name: juwan-garage-meta
  garage-data:
    name: juwan-garage-data
  gitea-data:
    name: juwan-gitea-data
  runner-data:
    name: juwan-runner-data
