# EN: Development Docker Compose - Shared network and volumes
# VI: Development Docker Compose - Network và volumes dùng chung

version: '3.8'

networks:
  microservices-network:
    driver: bridge

volumes:
  postgres_data:
  redis_data:
  minio_data:

services:
  # EN: Traefik Reverse Proxy
  # VI: Traefik Reverse Proxy
  traefik:
    image: traefik:v3.0
    container_name: traefik
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.file.directory=/etc/traefik/dynamic"
      - "--providers.file.watch=true"
      - "--entrypoints.web.address=:80"
      - "--log.level=INFO"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ../traefik/dynamic:/etc/traefik/dynamic:ro
    networks:
      - microservices-network

  # EN: Redis Cache
  # VI: Redis Cache
  redis:
    image: redis:7-alpine
    container_name: redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - microservices-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3

  # EN: MinIO Object Storage
  # VI: MinIO Object Storage
  minio:
    image: minio/minio:latest
    container_name: minio
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
    volumes:
      - minio_data:/data
    command: server /data --console-address ":9001"
    networks:
      - microservices-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 10s
      retries: 3

  # EN: IAM Service
  # VI: IAM Service
  iam-service-net:
    build:
      context: ../../services/iam-service-net
      dockerfile: Dockerfile
    container_name: iam-service-net
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    networks:
      - microservices-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

  # EN: Storage Service
  # VI: Storage Service
  storage-service-net:
    build:
      context: ../../services/storage-service-net
      dockerfile: Dockerfile
    container_name: storage-service-net
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    networks:
      - microservices-network
    depends_on:
      - minio
      - redis
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

  # EN: Membership Service
  # VI: Membership Service
  membership-service-net:
    build:
      context: ../../services/membership-service-net
      dockerfile: Dockerfile
    container_name: membership-service-net
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    networks:
      - microservices-network
    depends_on:
      - redis
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

  # EN: Merchant Service
  # VI: Merchant Service
  merchant-service-net:
    build:
      context: ../../services/merchant-service-net
      dockerfile: Dockerfile
    container_name: merchant-service-net
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    networks:
      - microservices-network
    depends_on:
      - redis
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
