From d5052cc425ac041e0ec72e4515002081b2f33e3b Mon Sep 17 00:00:00 2001 From: Aryans006 Date: Thu, 22 Aug 2024 21:20:07 +0530 Subject: [PATCH 1/4] added files for docker and made changes in the gitignore --- .gitignore | 53 +++++++++++++++++++ Dockerfile | 41 +++++++++++++++ build_files/.catkin_workspace | 1 + build_files/src/CMakeLists.txt | 1 + build_image.sh | 89 ++++++++++++++++++++++++++++++++ mr_robot_description/package.xml | 2 +- run_image.sh | 31 +++++++++++ 7 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 build_files/.catkin_workspace create mode 120000 build_files/src/CMakeLists.txt create mode 100755 build_image.sh create mode 100755 run_image.sh diff --git a/.gitignore b/.gitignore index a3062be..67289b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,54 @@ .vscode/* +.build_files/* + +devel/ +logs/ +build/ +bin/ +lib/ +msg_gen/ +srv_gen/ +msg/*Action.msg +msg/*ActionFeedback.msg +msg/*ActionGoal.msg +msg/*ActionResult.msg +msg/*Feedback.msg +msg/*Goal.msg +msg/*Result.msg +msg/_*.py +build_isolated/ +devel_isolated/ + +# Generated by dynamic reconfigure +*.cfgc +/cfg/cpp/ +/cfg/*.py + +# Ignore generated docs +*.dox +*.wikidoc + +# eclipse stuff +.project +.cproject + +# qcreator stuff +CMakeLists.txt.user + +srv/_*.py +*.pcd +*.pyc +qtcreator-* +*.user + +/planning/cfg +/planning/docs +/planning/src + +*~ + +# Emacs +.#* + +# Catkin custom files +CATKIN_IGNORE \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0c33603 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM osrf/ros:noetic-desktop-full + +SHELL ["/bin/bash","-c"] + +RUN echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc +RUN echo "source /workspaces/mr_robo_ws/devel/setup.bash" >> ~/.bashrc +RUN echo "source /usr/share/gazebo-11/setup.sh" >> ~/.bashrc +RUN echo "export LIBGL_ALWAYS_SOFTWARE=1" >> ~/.bashrc + + +RUN apt-get update + +RUN apt-get install --no-install-recommends -yqqq \ + python3-pip + +RUN pip3 install ultralytics +RUN apt-get install --no-install-recommends -yqqq \ + tmux \ + libfreenect-dev + + +RUN apt-get install --no-install-recommends -yqqq \ + ros-noetic-turtlebot3-gazebo\ + ros-noetic-turtlebot3-description\ + ros-noetic-turtlebot3-navigation\ + ros-noetic-ros-control \ + ros-noetic-gazebo-ros-pkgs \ + libopencv-dev \ + python3-opencv \ + ros-noetic-map-server \ + ros-noetic-move-base \ + ros-noetic-amcl \ + libgazebo11-dev \ + ros-noetic-rgbd-launch + +RUN mkdir -p /workspaces/mr_robo_ws/src + +RUN rm -rf /var/lib/apt/lists/* \ +&& apt-get clean + +CMD ["sleep", "infinity"] \ No newline at end of file diff --git a/build_files/.catkin_workspace b/build_files/.catkin_workspace new file mode 100644 index 0000000..52fd97e --- /dev/null +++ b/build_files/.catkin_workspace @@ -0,0 +1 @@ +# This file currently only serves to mark the location of a catkin workspace for tool integration diff --git a/build_files/src/CMakeLists.txt b/build_files/src/CMakeLists.txt new file mode 120000 index 0000000..2016816 --- /dev/null +++ b/build_files/src/CMakeLists.txt @@ -0,0 +1 @@ +/opt/ros/noetic/share/catkin/cmake/toplevel.cmake \ No newline at end of file diff --git a/build_image.sh b/build_image.sh new file mode 100755 index 0000000..9d5ca92 --- /dev/null +++ b/build_image.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Map host's display socket to docker +DOCKER_ARGS+=("-v /tmp/.X11-unix:/tmp/.X11-unix") +DOCKER_ARGS+=("-v $HOME/.Xauthority:/home/admin/.Xauthority:rw") +# DOCKER_ARGS+=("-e DISPLAY") +DOCKER_ARGS+=("-e NVIDIA_VISIBLE_DEVICES=all") +DOCKER_ARGS+=("-e NVIDIA_DRIVER_CAPABILITIES=all") +# DOCKER_ARGS+=("-e FASTRTPS_DEFAULT_PROFILES_FILE=/usr/local/share/middleware_profiles/rtps_udp_profile.xml") + +xhost +local:root + +image_name="mr_robot_docker" +container_name="mr_robot_docker_build" + +# Initialize variables +force_option=false +clean_option=false + + +# Parse options +while [[ $# -gt 0 ]]; do + case "$1" in + --force) + force_option=true + shift + ;; + + --clean) + clean_option=true + shift + ;; + + *) + echo "Invalid option: $1" + exit 1 + ;; + esac +done + + +if $force_option; then + echo "Buidling Existing Docker Image: $image_name" + docker build -f Dockerfile -t "$image_name":1.0 . + ./build_image.sh + +else + run_command='source /opt/ros/noetic/setup.bash && catkin_make && source devel/setup.bash && exit' + + if $clean_option; then + run_command='source /opt/ros/noetic/setup.bash && rm -rf build devel && catkin_make && source devel/setup.bash && exit' + echo "Force Command Enabled" + + else + echo "Force Command Disabled" + fi + + + if docker images --format '{{.Repository}}' | grep -q "$image_name"; then + + echo "Found Docker Image: $image_name:1.0" + + echo "Updating the existing Docker image: $image_name:1.0" + + docker run -it --rm=false \ + --privileged \ + ${DOCKER_ARGS[@]} \ + -e DISPLAY=$DISPLAY \ + -v $PWD/build_files:/workspaces/mr_robo_ws/ \ + -v $PWD:/workspaces/mr_robo_ws/src \ + -v /etc/localtime:/etc/localtime:ro \ + --name "$container_name" \ + --runtime nvidia \ + --workdir /workspaces/mr_robo_ws \ + $@ \ + "$image_name":1.0 \ + bash -c "$run_command" + + docker rm "$container_name" + + # ./run_image.sh + + else + echo "Building a new Docker image: $image_name" + docker build -f Dockerfile -t "$image_name":1.0 . + ./build_image.sh + fi + +fi \ No newline at end of file diff --git a/mr_robot_description/package.xml b/mr_robot_description/package.xml index 594d3d2..465257f 100644 --- a/mr_robot_description/package.xml +++ b/mr_robot_description/package.xml @@ -7,7 +7,7 @@ - syuntoku14 + singh diff --git a/run_image.sh b/run_image.sh new file mode 100755 index 0000000..1b141a3 --- /dev/null +++ b/run_image.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Map host's display socket to docker +DOCKER_ARGS+=("-v $HOME/.Xauthority:/home/admin/.Xauthority:rw") +DOCKER_ARGS+=("-e DISPLAY") +DOCKER_ARGS+=("-e NVIDIA_VISIBLE_DEVICES=all") +DOCKER_ARGS+=("-e NVIDIA_DRIVER_CAPABILITIES=all") +DOCKER_ARGS+=("-e LIBGL_ALWAYS_SOFTWARE=1") + +xhost +local:root +image_name="mr_robot_docker" +container_name="mr_robot_docker_build" + +if docker ps --format '{{.Names}}' | grep -q "$container_name"; then + docker exec -it $container_name /bin/bash + +else + docker run -it --rm \ + ${DOCKER_ARGS[@]} \ + -e DISPLAY=$DISPLAY \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -v $PWD/build_files:/workspaces/mr_robo_ws/ \ + -v $PWD:/workspaces/mr_robo_ws/src \ + -v /etc/localtime:/etc/localtime:ro \ + --name "$container_name" \ + --runtime nvidia \ + --workdir /workspaces/mr_robo_ws \ + $@ \ + "$image_name":1.0 \ + /bin/bash +fi \ No newline at end of file From 56fd4d6dd7ff5aa6268afd00024b064895072d69 Mon Sep 17 00:00:00 2001 From: Aryans006 Date: Thu, 22 Aug 2024 21:25:16 +0530 Subject: [PATCH 2/4] removed build_files folder --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 67289b7..168374a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .vscode/* -.build_files/* +build_files/* devel/ logs/ From c3703d8fbcbe0a2f0ac309035835251c8b41be8c Mon Sep 17 00:00:00 2001 From: Aryans006 Date: Fri, 23 Aug 2024 00:17:04 +0530 Subject: [PATCH 3/4] fixed build file --- build_files/.catkin_workspace | 1 - build_files/src/CMakeLists.txt | 1 - 2 files changed, 2 deletions(-) delete mode 100644 build_files/.catkin_workspace delete mode 120000 build_files/src/CMakeLists.txt diff --git a/build_files/.catkin_workspace b/build_files/.catkin_workspace deleted file mode 100644 index 52fd97e..0000000 --- a/build_files/.catkin_workspace +++ /dev/null @@ -1 +0,0 @@ -# This file currently only serves to mark the location of a catkin workspace for tool integration diff --git a/build_files/src/CMakeLists.txt b/build_files/src/CMakeLists.txt deleted file mode 120000 index 2016816..0000000 --- a/build_files/src/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -/opt/ros/noetic/share/catkin/cmake/toplevel.cmake \ No newline at end of file From 6b995a0211d768e646650a256316b452706066f3 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 21 Nov 2024 14:41:33 +0530 Subject: [PATCH 4/4] Added nvidia and non-nvidia compatibility to the docker run script --- run_image.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/run_image.sh b/run_image.sh index 1b141a3..32a4492 100755 --- a/run_image.sh +++ b/run_image.sh @@ -1,19 +1,28 @@ #!/bin/bash -# Map host's display socket to docker +# Map host's display socket to Docker DOCKER_ARGS+=("-v $HOME/.Xauthority:/home/admin/.Xauthority:rw") DOCKER_ARGS+=("-e DISPLAY") -DOCKER_ARGS+=("-e NVIDIA_VISIBLE_DEVICES=all") -DOCKER_ARGS+=("-e NVIDIA_DRIVER_CAPABILITIES=all") -DOCKER_ARGS+=("-e LIBGL_ALWAYS_SOFTWARE=1") +DOCKER_ARGS+=("-e LIBGL_ALWAYS_SOFTWARE=1") # Enable software rendering by default xhost +local:root image_name="mr_robot_docker" container_name="mr_robot_docker_build" +# Check if NVIDIA GPU is available +if command -v nvidia-smi &>/dev/null && nvidia-smi -L &>/dev/null; then + echo "NVIDIA GPU detected. Configuring for NVIDIA runtime..." + DOCKER_ARGS+=("--runtime=nvidia") + DOCKER_ARGS+=("-e NVIDIA_VISIBLE_DEVICES=all") + DOCKER_ARGS+=("-e NVIDIA_DRIVER_CAPABILITIES=all") +else + echo "No NVIDIA GPU detected. Configuring for software rendering..." + DOCKER_ARGS+=("-e LIBGL_ALWAYS_SOFTWARE=1") # Ensure software rendering +fi + +# Check if container is already running if docker ps --format '{{.Names}}' | grep -q "$container_name"; then docker exec -it $container_name /bin/bash - else docker run -it --rm \ ${DOCKER_ARGS[@]} \ @@ -23,9 +32,7 @@ else -v $PWD:/workspaces/mr_robo_ws/src \ -v /etc/localtime:/etc/localtime:ro \ --name "$container_name" \ - --runtime nvidia \ --workdir /workspaces/mr_robo_ws \ - $@ \ "$image_name":1.0 \ /bin/bash -fi \ No newline at end of file +fi