From 8a02c4e8368fe091d6148b14dbae3e7f89a7088e Mon Sep 17 00:00:00 2001 From: default Date: Sun, 11 Jan 2026 00:23:45 +0000 Subject: [PATCH] docker compose update --- docker-compose.yml | 234 ++++++++++++++++++++++++++++++++------------- 1 file changed, 167 insertions(+), 67 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 06946d5..fcfa9e7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,82 +1,182 @@ # ============================================================================= -# RDC Simulation - Docker Compose (GPU-enabled) +# RDC Simulation - Docker Compose (GPU-enabled, Wayland, Multi-Service) # ============================================================================= -# Runs the simulation with GPU acceleration and X11 display forwarding. +# Runs the complete simulation stack with 3 services: +# 1. gazebo - Gazebo Harmonic simulation +# 2. sitl - ArduPilot SITL (ArduCopter) +# 3. controller - Python flight controller # # Usage: -# # Build the container -# docker compose build +# # Start all services +# docker compose up # -# # Run interactive shell -# docker compose run --rm simulation +# # Or start individually +# docker compose up gazebo +# docker compose up sitl +# docker compose up controller # -# # Run specific command -# docker compose run --rm simulation ./scripts/run_ardupilot_sim.sh runway +# # Interactive shell +# docker compose run --rm simulation bash +# +# # Stop everything +# docker compose down # ============================================================================= -services: - simulation: - build: - context: . - dockerfile: Dockerfile - image: rdc-simulation:latest - container_name: rdc-sim - - # GPU support (NVIDIA) - deploy: - resources: - reservations: - devices: - - driver: nvidia - count: all - capabilities: [gpu] - - # Display forwarding for Gazebo GUI - environment: - - DISPLAY=${DISPLAY:-:0} - - NVIDIA_VISIBLE_DEVICES=all - - NVIDIA_DRIVER_CAPABILITIES=all - - QT_X11_NO_MITSHM=1 - - # Mount X11 socket for display - volumes: - - /tmp/.X11-unix:/tmp/.X11-unix:rw - - ~/.Xauthority:/home/pilot/.Xauthority:ro - - # Network mode for SITL communication - network_mode: host - - # Keep stdin open for interactive use - stdin_open: true - tty: true - - # Run as current user (optional - for file permission compatibility) - # user: "${UID:-1000}:${GID:-1000}" - - working_dir: /home/pilot/RDC_Simulation +# Common configuration anchor +x-common: &common + image: rdc-simulation:latest + build: + context: . + dockerfile: Dockerfile - # Alternative: Run headless (no display, for CI/testing) + # GPU support (NVIDIA) + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: [ gpu ] + + # Environment variables for Wayland + GPU + environment: + # Wayland display + &common-env + - WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-wayland-0} + - XDG_RUNTIME_DIR=/run/user/1000 + # Fallback X11 (XWayland) + - DISPLAY=${DISPLAY:-:0} + # GPU + - NVIDIA_VISIBLE_DEVICES=all + - NVIDIA_DRIVER_CAPABILITIES=all + # Qt platform - prefer Wayland, fallback to XCB + - QT_QPA_PLATFORM=wayland;xcb + - QT_WAYLAND_DISABLE_WINDOWDECORATION=1 + - QT_X11_NO_MITSHM=1 + # OpenGL + - __GLX_VENDOR_LIBRARY_NAME=nvidia + - GDK_BACKEND=wayland,x11 + # 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: - build: - context: . - dockerfile: Dockerfile - image: rdc-simulation:latest + <<: *common container_name: rdc-sim-headless - - deploy: - resources: - reservations: - devices: - - driver: nvidia - count: all - capabilities: [gpu] - + user: "1000:1000" environment: - NVIDIA_VISIBLE_DEVICES=all - NVIDIA_DRIVER_CAPABILITIES=compute,utility - HEADLESS=1 - - network_mode: host - stdin_open: true - tty: true - working_dir: /home/pilot/RDC_Simulation + - 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