# Docker Compose for SRS + Caddy Live Streaming Setup
version: '3.8'

services:
  # SRS (Simple Realtime Server) for RTMP
  srs:
    image: ossrs/srs:5
    container_name: easystream_srs
    ports:
      - "1935:1935"    # RTMP port
      - "8080:8080"    # HTTP port for HLS
      - "1985:1985"    # API port
    volumes:
      - ./srs.conf:/usr/local/srs/conf/srs.conf
      - ./f_data/streams:/usr/local/srs/objs/nginx/html/live
    environment:
      - SRS_LOG_LEVEL=info
    restart: unless-stopped
    networks:
      - easystream_network

  # Caddy for HTTP/HTTPS (your existing setup)
  caddy:
    image: caddy:2-alpine
    container_name: easystream_caddy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./f_data:/var/www/html/f_data
      - caddy_data:/data
      - caddy_config:/config
    environment:
      - DOMAIN=${DOMAIN:-localhost}
    restart: unless-stopped
    networks:
      - easystream_network

  # Your PHP application
  php:
    build: .
    container_name: easystream_php
    volumes:
      - .:/var/www/html
    environment:
      - SRS_HOST=srs
      - SRS_RTMP_PORT=1935
      - SRS_HTTP_PORT=8080
      - SRS_API_PORT=1985
    networks:
      - easystream_network
    depends_on:
      - srs

  # Redis for queue system
  redis:
    image: redis:7-alpine
    container_name: easystream_redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    restart: unless-stopped
    networks:
      - easystream_network

  # MySQL database
  mysql:
    image: mysql:8.0
    container_name: easystream_mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-easystream}
      MYSQL_USER: ${MYSQL_USER:-easystream}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-password}
    volumes:
      - mysql_data:/var/lib/mysql
      - ./deploy:/docker-entrypoint-initdb.d
    ports:
      - "3306:3306"
    restart: unless-stopped
    networks:
      - easystream_network

volumes:
  caddy_data:
  caddy_config:
  redis_data:
  mysql_data:

networks:
  easystream_network:
    driver: bridge