name: rubis-dev

services:
  postgres:
    image: postgres:16-alpine
    container_name: rubis-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: rubis
      POSTGRES_PASSWORD: rubis
      POSTGRES_DB: rubis_dev
    ports:
      - '5433:5432'
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U rubis -d rubis_dev']
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: rubis-redis
    restart: unless-stopped
    ports:
      - '6380:6379'
    volumes:
      - redis_data:/data
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 5s
      retries: 5

  minio:
    image: minio/minio:latest
    container_name: rubis-minio
    restart: unless-stopped
    command: server /data --console-address ':9001'
    environment:
      MINIO_ROOT_USER: rubis
      MINIO_ROOT_PASSWORD: rubis-dev-secret
    ports:
      - '9100:9000' # API S3
      - '9101:9001' # Console web
    volumes:
      - minio_data:/data
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:9000/minio/health/live']
      interval: 10s
      timeout: 5s
      retries: 5

  # Crée le bucket invoices au démarrage puis sort
  minio-bootstrap:
    image: minio/mc:latest
    container_name: rubis-minio-bootstrap
    depends_on:
      minio:
        condition: service_healthy
    entrypoint: >
      /bin/sh -c "
      mc alias set local http://minio:9000 rubis rubis-dev-secret;
      mc mb --ignore-existing local/rubis-invoices;
      mc anonymous set none local/rubis-invoices;
      exit 0;
      "

  # Mailpit = successeur multi-arch et activement maintenu de Mailhog,
  # protocole et UI compatibles (SMTP 1025, web UI 8025).
  mailpit:
    image: axllent/mailpit:latest
    container_name: rubis-mailpit
    restart: unless-stopped
    ports:
      - '1025:1025' # SMTP
      - '8025:8025' # Web UI
    healthcheck:
      test: ['CMD', 'wget', '--quiet', '--spider', 'http://localhost:8025/livez']
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  postgres_data:
  redis_data:
  minio_data:
