Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Dockerization #26

Open
wants to merge 4 commits into
base: ros
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
89 changes: 89 additions & 0 deletions build_image.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion mr_robot_description/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
<maintainer email="syuntoku14@todo.todo">syuntoku14</maintainer>
<maintainer email="singh@todo.todo">singh</maintainer>


<!-- One license tag required, multiple allowed, one license per tag -->
Expand Down
38 changes: 38 additions & 0 deletions run_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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 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[@]} \
-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" \
--workdir /workspaces/mr_robo_ws \
"$image_name":1.0 \
/bin/bash
fi