version: '3'  # Specifies the Docker Compose file version.

services:  # Defines the services to be run.
  
  # Stream Capture Container
  stream_capture:  # Service name for the Stream Capture Container.
    build:  # Specifies the build configuration.
      context: .  # Sets the build context to the current directory.
      dockerfile: docker/Dockerfile  # Specifies the Dockerfile to use for building the image.     
    # image: stream-capture:latest  # Docker image name and tag
    # container_name: StreamCaptureContainer  # Container name  
    environment:    
      - M3U_FILE_URL=${M3U_FILE_URL}
      - PROJECT_NAME=${PROJECT_NAME}
      - SEGMENT_DURATION=${SEGMENT_DURATION}
      - MAX_CAPTURE_RETRIES=${MAX_CAPTURE_RETRIES}
      - EXIT_ON_FAILURE=${EXIT_ON_FAILURE}
      - CAPTURE_RETRY_INTERVAL=${CAPTURE_RETRY_INTERVAL}
      - MAX_TS_FILE_NUMBER=${MAX_TS_FILE_NUMBER}
    volumes:  # Specifies volume mounts for the service. 
      - ./data:/app/data # Mount the host machine's ./data directory to /app/data in the container.
      - /var/www/html/El_Hiwar_Ettounsi_HLS/:/var/www/html/El_Hiwar_Ettounsi_HLS/
    command: ["sh", "/app/stream_capture.sh"]  # Defines the command to run in the container.

  # Stream Listener Container
  stream_listener:  # Service name for the Stream Listener Container.
    build:  # Specifies the build configuration.
      context: .  # Sets the build context to the current directory.
      dockerfile: docker/Dockerfile  # Specifies the Dockerfile to use for building the image.   
    # container_name: StreamListenerContainer  # Container name 
    environment:     
      - PROJECT_NAME=${PROJECT_NAME}
      - SEGMENT_DURATION=${SEGMENT_DURATION} 
      - MAX_TS_FILE_NUMBER=${MAX_TS_FILE_NUMBER}
    volumes:  # Specifies volume mounts for the service. 
      - ./data:/app/data  # Mount the host machine's ./data directory to /app/data in the container.
    command: ["sh", "/app/stream_listener.sh"]  # Defines the command to run in the container.
    depends_on:
      - stream_capture  # Ensure StreamCaptureContainer is started first

  # Ads Marker Container
  stream_ads_marker:  # Service name for the Stream Ads Marker Container.
    build:  # Specifies the build configuration.
      context: .  # Sets the build context to the current directory.
      dockerfile: docker/Dockerfile  # Specifies the Dockerfile to use for building the image.      
    # container_name: StreamAdsMarkerContainer  # Container name 
    environment:     
      - PROJECT_NAME=${PROJECT_NAME}
      - FEED_QUALITY=${FEED_QUALITY}
      - ADS_MARKER_AT=${ADS_MARKER_AT} 
      - ADS_DURATION=${ADS_DURATION}
      - ADS_FREQUENCY=${ADS_FREQUENCY}
      - TOTAL_ADS_DURATION=${TOTAL_ADS_DURATION}
    volumes:  # Specifies volume mounts for the service. 
      - ./data:/app/data # Mount the host machine's ./data directory to /app/data in the container.
    command: ["sh", "/app/stream_ads_marker.sh"]  # Defines the command to run in the container.
    depends_on:
      - stream_capture  # Ensure StreamCaptureContainer is started first
      - stream_listener  # Ensure StreamListenerContainer is started first