services:
  minio:
    image: minio/minio:latest
    container_name: freedge-minio
    ports:
      - "9000:9000"   # API S3
      - "9001:9001"   # Console web
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-freedge}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-freedge123}
    volumes:
      - minio-data:/data
    command: server /data --console-address ":9001"
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 5s
      timeout: 5s
      retries: 5

  # Crée le bucket automatiquement au démarrage
  minio-init:
    image: minio/mc:latest
    container_name: freedge-minio-init
    depends_on:
      minio:
        condition: service_healthy
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-freedge}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-freedge123}
      MINIO_BUCKET: ${MINIO_BUCKET:-freedge}
    entrypoint: >
      /bin/sh -c "
      set -e;
      mc alias set local http://minio:9000 $$MINIO_ROOT_USER $$MINIO_ROOT_PASSWORD;
      mc mb --ignore-existing local/$$MINIO_BUCKET;
      mc anonymous set download local/$$MINIO_BUCKET;
      echo 'Bucket '$$MINIO_BUCKET' prêt et lisible publiquement';
      "

volumes:
  minio-data:
    driver: local
