services:
  minio:
    image: minio/minio
    expose:
      - "9000"
      - "9001"
    volumes:
      - minio_storage:/data
    networks:
      - dokploy-network
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
    command: server --console-address ":9001" /data
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://minio:9000/minio/health/live" ]
      interval: 10s
      timeout: 10s
      retries: 5

  tiles:
    image: eqalpha/keydb:latest
    volumes:
      - tiles-data:/data
    networks:
      - dokploy-network
    expose:
      - "6379"
    command: keydb-server /etc/keydb/keydb.conf --maxmemory 100mb --maxmemory-policy volatile-lru --maxmemory-samples 5
    healthcheck:
      test: ["CMD", "keydb-cli", "-h", "localhost", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: "0.5"
  
  keydb:
    image: eqalpha/keydb:latest
    volumes:
      - keydb-data:/data
    networks:
      - dokploy-network
    expose:
      - "6379"
    healthcheck:
      test: ["CMD", "keydb-cli", "-h", "localhost", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: "0.5"

  backend:
    build:
      context: .
      dockerfile: Dockerfile
    networks:
      - dokploy-network
    expose:
      - 1323
    restart: unless-stopped
    volumes:
      - images_volume:/app/images
      - storage_volume:/app/storage
    environment:
      STORAGE_STRATEGY: "minio"
      MINIO_URL: minio:9000
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
      PGHOST: db
      PGPORT: "5432"
      IMAGEOPTION: "true"
      CONCURRENT_IMAGES: ${CONCURRENT_IMAGES}
    depends_on:
      minio:
        condition: service_healthy

volumes:
  minio_storage:
  images_volume:
  storage_volume:
  tiles-data:
  keydb-data:


networks:
  dokploy-network:
    external: true
