Files
RDC_Simulation/docker-compose.yml
2026-01-11 00:37:32 +00:00

182 lines
5.9 KiB
YAML

# =============================================================================
# RDC Simulation - Docker Compose (GPU-enabled, Wayland, Multi-Service)
# =============================================================================
# Runs the complete simulation stack with 3 services:
# 1. gazebo - Gazebo Harmonic simulation
# 2. sitl - ArduPilot SITL (ArduCopter)
# 3. controller - Python flight controller
#
# Usage:
# # Start all services
# docker compose up
#
# # Or start individually
# docker compose up gazebo
# docker compose up sitl
# docker compose up controller
#
# # Interactive shell
# docker compose run --rm simulation bash
#
# # Stop everything
# docker compose down
# =============================================================================
# Common configuration anchor
x-common: &common
image: rdc-simulation:latest
build:
context: .
dockerfile: Dockerfile
# GPU support (NVIDIA)
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [ gpu ]
# Environment variables - Wayland with GPU
environment:
# Wayland display
&common-env
- WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-wayland-0}
- XDG_RUNTIME_DIR=/run/user/1000
# X11 fallback
- DISPLAY=${DISPLAY:-:0}
# GPU
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all
# Qt platform - Wayland first, then X11
- QT_QPA_PLATFORM=wayland
- QT_WAYLAND_DISABLE_WINDOWDECORATION=1
# OpenGL settings
- __GLX_VENDOR_LIBRARY_NAME=nvidia
- __NV_PRIME_RENDER_OFFLOAD=1
# Gazebo paths
- GZ_SIM_SYSTEM_PLUGIN_PATH=/home/pilot/ardupilot_gazebo/build
- GZ_SIM_RESOURCE_PATH=/home/pilot/ardupilot_gazebo/models:/home/pilot/ardupilot_gazebo/worlds:/home/pilot/RDC_Simulation/gazebo/models
# Mount Wayland and X11 sockets
volumes:
# Wayland socket
- ${XDG_RUNTIME_DIR:-/run/user/1000}/${WAYLAND_DISPLAY:-wayland-0}:/run/user/1000/wayland-0:rw
# X11 socket (for XWayland fallback)
- /tmp/.X11-unix:/tmp/.X11-unix:rw
# GPU device
- /dev/dri:/dev/dri:rw
# Network mode for SITL communication (all services share host network)
network_mode: host
# Run as user with access to Wayland socket
user: "1000:1000"
stdin_open: true
tty: true
working_dir: /home/pilot/RDC_Simulation
services:
# =========================================================================
# Interactive Shell (for manual control)
# =========================================================================
simulation:
<<: *common
container_name: rdc-sim
entrypoint: [ "/home/pilot/docker-entrypoint.sh" ]
command: [ "bash" ]
# =========================================================================
# Service 1: Gazebo Simulation
# =========================================================================
gazebo:
<<: *common
container_name: rdc-gazebo
entrypoint: [ "/bin/bash", "-c" ]
command:
- |
source /opt/ros/jazzy/setup.bash
source ~/.bashrc
echo "Starting Gazebo Harmonic..."
echo "Waiting 5 seconds for initialization..."
sleep 5
cd /home/pilot/RDC_Simulation
./scripts/run_ardupilot_sim.sh runway
# =========================================================================
# Service 2: ArduPilot SITL
# =========================================================================
sitl:
<<: *common
container_name: rdc-sitl
depends_on:
gazebo:
condition: service_started
entrypoint: [ "/bin/bash", "-c" ]
command:
- |
source /opt/ros/jazzy/setup.bash
source ~/.bashrc
echo "Waiting 15 seconds for Gazebo to start..."
sleep 15
echo "Starting ArduPilot SITL..."
cd /home/pilot/ardupilot
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --console --no-mavproxy
# =========================================================================
# Service 3: Flight Controller
# =========================================================================
controller:
<<: *common
container_name: rdc-controller
depends_on:
sitl:
condition: service_started
entrypoint: [ "/bin/bash", "-c" ]
command:
- |
source /opt/ros/jazzy/setup.bash
source ~/.bashrc
source /home/pilot/RDC_Simulation/venv/bin/activate
echo "Waiting 30 seconds for SITL to initialize..."
sleep 30
echo "Starting flight controller..."
cd /home/pilot/RDC_Simulation
python scripts/run_ardupilot.py --pattern square
# =========================================================================
# Headless Mode (CI/Server - no display)
# =========================================================================
simulation-headless:
<<: *common
container_name: rdc-sim-headless
user: "1000:1000"
environment:
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=compute,utility
- HEADLESS=1
- LIBGL_ALWAYS_SOFTWARE=1
- GZ_SIM_SYSTEM_PLUGIN_PATH=/home/pilot/ardupilot_gazebo/build
- GZ_SIM_RESOURCE_PATH=/home/pilot/ardupilot_gazebo/models:/home/pilot/ardupilot_gazebo/worlds:/home/pilot/RDC_Simulation/gazebo/models
volumes: [] # No display mounts needed
entrypoint: [ "/home/pilot/docker-entrypoint.sh" ]
command: [ "bash" ]
# =========================================================================
# All-in-One (runs everything in one container)
# =========================================================================
all-in-one:
<<: *common
container_name: rdc-all
entrypoint: [ "/bin/bash", "-c" ]
command:
- |
source /opt/ros/jazzy/setup.bash
source ~/.bashrc
source /home/pilot/RDC_Simulation/venv/bin/activate
cd /home/pilot/RDC_Simulation
echo "Starting all-in-one simulation..."
./scripts/run_ardupilot_controller.sh