services:
  mysql:
    image: mysql:8.4
    restart: unless-stopped
    environment:
      MYSQL_USER: jorgecuadros
      MYSQL_PASSWORD: jorgecuadros
      MYSQL_DATABASE: jorgecuadros
      MYSQL_ALLOW_EMPTY_PASSWORD: "no"
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "jorgecuadros", "-pjorgecuadros"]
      interval: 5s
      timeout: 5s
      retries: 10

  minio:
    image: minio/minio:RELEASE.2024-10-13T13-34-11Z
    restart: unless-stopped
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-jc_minio}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-jc_minio_dev}
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - minio_data:/data
    healthcheck:
      test: ["CMD-SHELL", "mc ready local || curl -f http://localhost:9000/minio/health/live || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 20s

  api:
    build:
      context: .
      dockerfile: docker/api.Dockerfile
    restart: unless-stopped
    depends_on:
      mysql:
        condition: service_healthy
      minio:
        condition: service_healthy
    environment:
      DATABASE_URL: mysql://jorgecuadros:jorgecuadros@mysql:3306/jorgecuadros
      SESSION_SECRET: ${SESSION_SECRET:?SESSION_SECRET must be set}
      WEB_ORIGIN: http://localhost:3000
      PORT: 3001
      INGEST_DIR: /data/ingest
      BACKUP_DIR: /data/backups
      MIGRATION_ENV: dev
      S3_ENDPOINT: http://minio:9000
      S3_BUCKET: jorgecuadros-documents
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-jc_minio}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-jc_minio_dev}
    volumes:
      - ingest_data:/data/ingest
      - backup_data:/data/backups
    ports:
      - "3001:3001"

  web:
    build:
      context: .
      dockerfile: docker/web.Dockerfile
    restart: unless-stopped
    depends_on:
      - api
    environment:
      NEXT_PUBLIC_API_ORIGIN: http://localhost:3001
    ports:
      - "3000:3000"

volumes:
  mysql_data:
  ingest_data:
  backup_data:
  minio_data:
