version: '3.8'

services:
  # ========================================================================
  # ROS 2 + SkyLink Bridge 容器
  # ========================================================================
  
  ros2-bridge:
    image: ros:humble-ros-core
    container_name: skylink_ros2_bridge
    
    # 网络配置
    network_mode: host  # 使用主机网络以支持 UDP 广播
    
    # 环境变量
    environment:
      - ROS_DOMAIN_ID=0
      - ROS_DISTRO=humble
    
    # 卷挂载
    volumes:
      - ./skylink_ros2:/workspace
      - /dev:/dev  # 相机访问
    
    # 设备挂载
    devices:
      - /dev/video0:/dev/video0  # USB 摄像头
      - /dev/video1:/dev/video1  # (可选) 第二个摄像头
    
    # 启动命令
    command: >
      bash -c "
      source /opt/ros/humble/setup.bash &&
      cd /workspace &&
      colcon build &&
      source install/setup.bash &&
      ros2 launch skylink_bridge bridge.launch.py
      "
    
    # 资源限制
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 2G
        reservations:
          cpus: '1'
          memory: 1G
    
    # 重启策略
    restart: unless-stopped

networks:
  default:
    driver: bridge
