# MinIO — 内部 app 平台对象存储（SQLite Litestream 备份桶）
#
# 决策：02-data-model + 01-prd §待定项 — 自建 MinIO docker
# 桶名：internal-apps-backups（首次启动后由 init job 自动创建）
#
# 启动：
#   bash scripts/internal-app-platform/setup-minio.sh
#   或直接：docker compose -f scripts/internal-app-platform/docker-compose.minio.yml up -d
#
# 端口：
#   9000 - S3 API（Litestream / backend 调）
#   9001 - Web UI（运维查桶 / 调试）
#
# 数据卷：minio_data（持久化到 docker named volume）

services:
  minio:
    image: minio/minio:RELEASE.2025-04-22T22-12-26Z
    container_name: ffoa-internal-apps-minio
    restart: unless-stopped
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-ffoa_internal_apps}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?Must set in .env, see .env.example}
      MINIO_BROWSER_REDIRECT_URL: ${MINIO_BROWSER_REDIRECT_URL:-http://localhost:9001}
    ports:
      - "${MINIO_API_PORT:-9000}:9000"
      - "${MINIO_CONSOLE_PORT:-9001}:9001"
    volumes:
      - minio_data:/data
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    networks:
      - ffoa-network

  # 一次性初始化 job：创建 internal-apps-backups 桶 + 设置 lifecycle policy
  minio-init:
    image: minio/mc:RELEASE.2025-04-16T18-13-26Z
    container_name: ffoa-internal-apps-minio-init
    depends_on:
      minio:
        condition: service_healthy
    networks:
      - ffoa-network
    entrypoint: >
      /bin/sh -c "
      mc alias set local http://minio:9000 ${MINIO_ROOT_USER:-ffoa_internal_apps} $${MINIO_ROOT_PASSWORD};
      mc mb -p local/internal-apps-backups || true;
      mc anonymous set none local/internal-apps-backups;
      echo 'MinIO bucket internal-apps-backups ready';
      "
    environment:
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?Must set in .env}

volumes:
  minio_data:
    name: ffoa-internal-apps-minio-data

networks:
  ffoa-network:
    external: true
    name: ${DOCKER_NETWORK:-ffoa-network}
