version: '3.8'

services:
  medical-imaging:
    image: swarmcare/medical-imaging:1.0.0
    container_name: medical-imaging
    build:
      context: ..
      dockerfile: deliverables/Dockerfile
    ports:
      - "8080:8080"
      - "9090:9090"
    environment:
      # Application
      - APP_ENV=production
      - APP_PORT=8080
      - LOG_LEVEL=INFO

      # HIPAA Compliance
      - HIPAA_MODE=enabled
      - PHI_DETECTION=enabled
      - ANONYMIZATION=enabled

      # Medical Imaging
      - MAX_IMAGE_SIZE_MB=100
      - SUPPORTED_FORMATS=dcm,png,jpg,jpeg,tiff
      - PROCESSING_TIMEOUT_SEC=30

      # Performance
      - MAX_CONCURRENT_ANALYSIS=10
      - CACHE_ENABLED=true
      - CACHE_TTL_SECONDS=3600

      # Storage
      - IMAGE_STORAGE_PATH=/data/medical-images
      - RESULTS_STORAGE_PATH=/data/results

      # Monitoring
      - METRICS_ENABLED=true
      - METRICS_PORT=9090
      - HEALTH_CHECK_ENABLED=true

    volumes:
      - medical-images:/data/medical-images
      - analysis-results:/data/results
      - ./logs:/var/log/medical-imaging

    networks:
      - medical-imaging-network

    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

    restart: unless-stopped

    deploy:
      resources:
        limits:
          cpus: '4.0'
          memory: 4G
        reservations:
          cpus: '2.0'
          memory: 2G

    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "10"

  # Redis cache (optional)
  redis:
    image: redis:7-alpine
    container_name: medical-imaging-cache
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    networks:
      - medical-imaging-network
    command: redis-server --appendonly yes --requirepass changeme
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 512M

  # PostgreSQL database (optional)
  postgres:
    image: postgres:15-alpine
    container_name: medical-imaging-db
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=medical_imaging
      - POSTGRES_USER=medical_user
      - POSTGRES_PASSWORD=changeme
    volumes:
      - postgres-data:/var/lib/postgresql/data
    networks:
      - medical-imaging-network
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 2G

  # Prometheus monitoring (optional)
  prometheus:
    image: prom/prometheus:latest
    container_name: medical-imaging-prometheus
    ports:
      - "9091:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus-data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
    networks:
      - medical-imaging-network
    restart: unless-stopped

  # Grafana dashboards (optional)
  grafana:
    image: grafana/grafana:latest
    container_name: medical-imaging-grafana
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=changeme
    volumes:
      - grafana-data:/var/lib/grafana
    networks:
      - medical-imaging-network
    restart: unless-stopped
    depends_on:
      - prometheus

  # Nginx reverse proxy (optional)
  nginx:
    image: nginx:alpine
    container_name: medical-imaging-nginx
    ports:
      - "443:443"
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./ssl:/etc/nginx/ssl
    networks:
      - medical-imaging-network
    restart: unless-stopped
    depends_on:
      - medical-imaging

networks:
  medical-imaging-network:
    driver: bridge

volumes:
  medical-images:
    driver: local
  analysis-results:
    driver: local
  redis-data:
    driver: local
  postgres-data:
    driver: local
  prometheus-data:
    driver: local
  grafana-data:
    driver: local
