diff --git a/README.md b/README.md index 43741023..615d674d 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,75 @@ roslaunch me5413_world navigation.launch ![rviz_navigation_image](src/me5413_world/media/rviz_navigation.png) +## Docker Support +This repository provides Docker support for setting up and managing a ROS Noetic environment with GPU acceleration. +The docker folder includes the following Dockerfiles to build container images: + +#### 1. `nvidia-ros-noetic.Dockerfile` +This file creates a ROS Noetic image using an NVIDIA CUDA-based Ubuntu base image, providing GPU support for ROS applications. + +To build the image, + +```bash + # From the root of the repository build the GPU accelerated ROS Noetic image + docker build -f docker/nvidia-ros-noetic.Dockerfile -t nvidia-ros-noetic . +``` + +#### 2. `dev-overlay.Dockerfile` + +This file extends the ROS Noetic base image, setting up a development container with the volume-mounted `src` folder +containing all the packages. Any new packages created in the `src` folder will automatically appear inside the running container. + +To build the development image, + +```bash + # From the root of the repository build the development image + docker build -f docker/dev-overlay.Dockerfile -t dev-overlay . +``` +### Launching the development environment +The repository includes a `docker-compose.yaml` file in the root directory to simplify launching the development environment. Use the following steps: + +1. Allow X11 access for Gazebo + +```bash + xhost + +``` + +2. Start the development environment + +```bash + docker compose up +``` + +### Accessing the development environment + +Once the container is running, you can access it using the following commands: + +- With `appuser` privilages + +```bash + docker exec -it dev-overlay bash +``` +- With `root` privilages + +```bash + docker exec -it -u 0 dev-overlay bash +``` + +### Customizing the development environment + +The development environment can be extended by adding custom commands to `docker/dev-overlay.Dockerfile` in the designated section: + +``` + # Put your code here to run additional commands + ####################################################################### + + + + + ####################################################################### +``` + ## Student Tasks ### 1. Map the environment @@ -188,4 +257,4 @@ We are following: ## License -The [ME5413_Final_Project](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project) is released under the [MIT License](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project/blob/main/LICENSE) \ No newline at end of file +The [ME5413_Final_Project](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project) is released under the [MIT License](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project/blob/main/LICENSE) diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..3dff1f98 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,30 @@ +version: "3.9" + +services: + # ROS Noetic image + nvidia-ros-noetic: + image: nvidia-ros-noetic + container_name: nvidia-ros-noetic + build: + context: . + dockerfile: docker/nvidia-ros-noetic.Dockerfile + network_mode: host + environment: + - DISPLAY=${DISPLAY} + - QT_X11_NO_MITSHM=1 + - NVIDIA_DRIVER_CAPABILITIES=all + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix:rw + - ${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority + + dev-overlay: + extends: nvidia-ros-noetic + image: dev-overlay + container_name: dev-overlay + build: + context: . + dockerfile: docker/dev-overlay.Dockerfile + network_mode: host + volumes: + - ./src:/appuser/catkin_ws/src:rw + command: sleep infinity diff --git a/docker/dev-overlay.Dockerfile b/docker/dev-overlay.Dockerfile new file mode 100644 index 00000000..ca06fc9b --- /dev/null +++ b/docker/dev-overlay.Dockerfile @@ -0,0 +1,61 @@ +FROM nvidia-ros-noetic:latest +SHELL [ "/bin/bash", "-c" ] + +# Set env variables for rosdep +ENV ROS_PYTHON_VERSION=3 +ENV ROS_DISTRO=noetic + +# Create new user with full permission to the volume mount +RUN useradd --create-home appuser + +# Copy the src folder for volume mount +USER appuser + +WORKDIR /appuser + +RUN mkdir -p catkin_ws/src + +COPY ./src catkin_ws/src + +# Run rosdep to install dependencies +USER root + +WORKDIR /appuser/catkin_ws + +RUN apt-get update --fix-missing \ + && rosdep update + +RUN rosdep install --from-paths src --ignore-src -r -y + +# Download Gazebo models +USER appuser + +WORKDIR /home/appuser + +RUN git clone https://github.com/osrf/gazebo_models.git + +RUN mkdir -p .gazebo/models \ + && cp -r gazebo_models/* .gazebo/models \ + && cp -r /appuser/catkin_ws/src/me5413_world/models/* .gazebo/models + + +# Put your code here to run additional commands +####################################################################### + + + + +####################################################################### + + +# Build the entire package +USER appuser + +WORKDIR /appuser/catkin_ws + +RUN source /opt/ros/noetic/setup.bash \ + && catkin config --install \ + && catkin build + +RUN echo "source /appuser/catkin_ws/devel/setup.bash" >> ~/.bashrc + diff --git a/docker/nvidia-ros-noetic.Dockerfile b/docker/nvidia-ros-noetic.Dockerfile new file mode 100644 index 00000000..e81a3df0 --- /dev/null +++ b/docker/nvidia-ros-noetic.Dockerfile @@ -0,0 +1,47 @@ +# Ubuntu 20.04 base image with NVIDIA CUDA and ROS Noetic +FROM nvidia/cudagl:11.2.1-base-ubuntu20.04 +SHELL ["/bin/bash", "-c"] + +# Install apt packages +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y \ + locales \ + lsb-release + +RUN dpkg-reconfigure locales + +RUN apt-get update && apt-get install -y \ + git \ + g++ \ + cmake \ + gnupg \ + gnupg1 \ + gnupg2 \ + wget + +# Install ROS Noetic +RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' + +RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends ros-noetic-desktop-full + +RUN apt-get install -y --no-install-recommends python3-rosdep + +RUN rosdep init \ + && rosdep fix-permissions \ + && rosdep update + +RUN echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc + +# Install python3 dependencies +RUN apt-get install -y \ + python3-pip \ + python3-catkin-tools \ + python3-opencv + +COPY ./docker/ros_entrypoint.sh / +ENTRYPOINT [ "/ros_entrypoint.sh" ] + diff --git a/docker/ros_entrypoint.sh b/docker/ros_entrypoint.sh new file mode 100755 index 00000000..6385ae1b --- /dev/null +++ b/docker/ros_entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +source /opt/ros/noetic/setup.bash + +exec "$@"