-
-
Save GowriUmesh/ae5da412b78bbdf58c2d2090ceba32e9 to your computer and use it in GitHub Desktop.
Dockerfile to create desktop images with ZED SDK and ROS/ROS2 support.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# This is a shell script that configures the build arguements to the Dockefile | |
# and builds a Docker image with a default tag. | |
# | |
# Available versions to configure the arguements: | |
# UBUNTU_RELEASE_YEAR = 18 and 20 | |
# ZED SDK Versions = 3.0 to 3.7 (ZED SDK version <3 are too old and outdated) | |
# CUDA Versions = 10.0, 10.2, 11.0, 11.1, 11.4, 11.5 | |
# ROS2_FLAG takes either 1 or 0 | |
# 1 sets the ROS_DISTRO_ARG to ROS2 Foxy Fitzroy | |
# 0 sets the ROS_DISTRO_ARG to ROS1 versions based on Ubuntu Release year | |
UBUNTU_RELEASE_YEAR=20 #Specify the Ubunutu release year | |
ZED_SDK_MAJOR=3 # ZED SDK major version | |
ZED_SDK_MINOR=7 # ZED SDK minor version | |
CUDA_MAJOR=11 # CUDA major version | |
CUDA_MINOR=4 # CUDA minor version | |
ROS2_FLAG=0 # Change it to 1 to setup ROS 2 | |
#Check for the version compatibilities | |
if [ ${UBUNTU_RELEASE_YEAR} == "18" ] ; then | |
echo "Ubuntu 18.04" | |
ROS_DISTRO_ARG="melodic" | |
# Not compatible with CUDA <= 9 | |
if [ ${CUDA_MAJOR} -le "9" ] ; then | |
echo "Ubunutu 18.04 Not compatible with CUDA <= 9" | |
exit | |
fi | |
elif [ ${UBUNTU_RELEASE_YEAR} == "20" ] ; then | |
if [ ${ROS2_FLAG} == 1 ] ; then | |
ROS_DISTRO_ARG="foxy" | |
else | |
ROS_DISTRO_ARG="noetic" | |
fi | |
# Not compatible with CUDA <= 10 | |
if [ ${CUDA_MAJOR} -le "10" ] ; then | |
echo "Ubunutu 20.04 is not compatible with CUDA <= 10 " | |
exit | |
fi | |
else | |
echo "UBUNTU_RELEASE_YEAR! Allowed values are 18 or 20 " | |
exit | |
fi | |
if [ ${CUDA_MAJOR} -ge "11" ] ; then | |
if [ ${ZED_SDK_MINOR} -lt "2" ] ; then # CUDA 11.0 was introduced with 3.2 | |
echo "CUDA 11.0 was introduced with 3.2" | |
exit | |
fi | |
if [ ${CUDA_MINOR} -ge "1" ] ; then | |
if [ ${ZED_SDK_MINOR} -lt "3" ] ; then # CUDA 11.1 was introduced with 3.3 | |
echo "CUDA 11.1 was introduced with 3.3" | |
exit | |
fi | |
fi | |
if [ ${CUDA_MINOR} == "2" ] || [ ${CUDA_MINOR} == "3" ] || [ ${CUDA_MINOR} -ge "6" ] ; then | |
#invalid CUDA versions | |
echo "Invalid CUDA_MINOR! Allowed values : 0,1,4,5" | |
exit | |
fi | |
elif [ ${CUDA_MAJOR} == "10" ] ; then | |
if [ ${CUDA_MINOR} != "0" ] || [ ${CUDA_MINOR} != "2" ] ; then | |
echo "Invalid CUDA_MINOR! Allowed values are 0 or 2" | |
exit | |
fi | |
else | |
echo "Invalid CUDA_MAJOR! Allowed values are 10 or 11" | |
fi | |
# Default Tag based on the selected versions | |
if [ ${ROS2_FLAG} == 1 ] ; then | |
echo "ROS2 flag == 1 " | |
TAG="${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-ros2-gl-devel-cuda${CUDA_MAJOR}.${CUDA_MINOR}-ubuntu${UBUNTU_RELEASE_YEAR}.04" | |
DOCKERFILE="Dockerfile.ros2" | |
else | |
TAG="${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-ros-gl-devel-cuda${CUDA_MAJOR}.${CUDA_MINOR}-ubuntu${UBUNTU_RELEASE_YEAR}.04" | |
DOCKERFILE="Dockerfile.ros" | |
fi | |
echo "Building '${TAG}'" | |
docker build --build-arg UBUNTU_RELEASE_YEAR=${UBUNTU_RELEASE_YEAR} \ | |
--build-arg ZED_SDK_MAJOR=${ZED_SDK_MAJOR} \ | |
--build-arg ZED_SDK_MINOR=${ZED_SDK_MINOR} \ | |
--build-arg ROS_DISTRO_ARG=${ROS_DISTRO_ARG} \ | |
--build-arg CUDA_MAJOR=${CUDA_MAJOR} \ | |
--build-arg CUDA_MINOR=${CUDA_MINOR} \ | |
-t "${TAG}" -f "${DOCKERFILE}" . | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Build arguments | |
ARG UBUNTU_RELEASE_YEAR | |
ARG ZED_SDK_MAJOR | |
ARG ZED_SDK_MINOR | |
ARG CUDA_MAJOR | |
ARG CUDA_MINOR | |
# Specify the parent image from which we build | |
FROM stereolabs/zed:${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-gl-devel-cuda${CUDA_MAJOR}.${CUDA_MINOR}-ubuntu${UBUNTU_RELEASE_YEAR}.04 | |
ARG ROS_DISTRO_ARG | |
ENV LOGNAME root | |
ENV ROS_DISTRO ${ROS_DISTRO_ARG} | |
ENV LANG C.UTF-8 | |
ENV LC_ALL C.UTF-8 | |
# Setup ROS | |
RUN apt-get update -y || true && \ | |
DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata curl && \ | |
sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' && \ | |
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - && \ | |
apt-get update || true &&\ | |
DEBIAN_FRONTEND=noninteractive apt-get install -y ros-$ROS_DISTRO-desktop-full build-essential cmake usbutils libusb-1.0-0-dev git -y --allow-unauthenticated && \ | |
RUN apt-get update -y || true && \ | |
DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata curl && \ | |
sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' && \ | |
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - && \ | |
apt-get update || true &&\ | |
DEBIAN_FRONTEND=noninteractive apt-get install -y ros-$ROS_DISTRO-desktop-full build-essential cmake usbutils libusb-1.0-0-dev git -y --allow-unauthenticated | |
# Install Packages depending on ROS distro | |
RUN if [ "$ROS_DISTRO_ARG" = "noetic" ] ; then \ | |
apt-get install -y python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool ;\ | |
else \ | |
apt-get install -y python-rosdep python-rosinstall python-rosinstall-generator python-wstool ; \ | |
fi | |
RUN rm -rf /var/lib/apt/lists/* | |
#Setup ROS workspace | |
RUN mkdir -p /opt/ros_ws/src | |
WORKDIR /opt/ros_ws | |
RUN . /opt/ros/noetic/setup.sh && \ | |
catkin_make | |
# setup entrypoint | |
COPY ./ros_entrypoint.sh / | |
ENTRYPOINT ["/ros_entrypoint.sh"] | |
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG UBUNTU_RELEASE_YEAR | |
ARG ZED_SDK_MAJOR | |
ARG ZED_SDK_MINOR | |
ARG CUDA_MAJOR | |
ARG CUDA_MINOR | |
FROM stereolabs/zed:${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-gl-devel-cuda${CUDA_MAJOR}.${CUDA_MINOR}-ubuntu${UBUNTU_RELEASE_YEAR}.04 | |
ARG ROS_DISTRO_ARG | |
ENV LOGNAME root | |
ENV ROS_DISTRO ${ROS_DISTRO_ARG} | |
ENV LANG C.UTF-8 | |
ENV LC_ALL C.UTF-8 | |
# install packages | |
RUN apt-get update || true && apt-get install -q -y --no-install-recommends \ | |
bash-completion \ | |
dirmngr \ | |
gnupg2 \ | |
lsb-release \ | |
python3-pip \ | |
&& rm -rf /var/lib/apt/lists/* | |
# setup sources.list and keys | |
RUN echo "deb http://packages.ros.org/ros2/ubuntu focal main" > /etc/apt/sources.list.d/ros2-latest.list && \ | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 | |
# install bootstrap tools | |
RUN apt-get update || true && apt-get install --no-install-recommends -y \ | |
build-essential \ | |
git \ | |
python3-colcon-common-extensions \ | |
python3-colcon-mixin \ | |
python3-rosdep \ | |
python3-vcstool \ | |
&& rm -rf /var/lib/apt/lists/* | |
# install python packages | |
RUN pip3 install -U \ | |
argcomplete \ | |
flake8 \ | |
flake8-blind-except \ | |
flake8-builtins \ | |
flake8-class-newline \ | |
flake8-comprehensions \ | |
flake8-deprecated \ | |
flake8-docstrings \ | |
flake8-import-order \ | |
flake8-quotes \ | |
pytest-repeat \ | |
pytest-rerunfailures | |
# bootstrap rosdep | |
RUN rosdep init \ | |
&& rosdep update | |
# setup colcon mixin and metadata | |
RUN colcon mixin add default \ | |
https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml && \ | |
colcon mixin update && \ | |
colcon metadata add default \ | |
https://raw.githubusercontent.com/colcon/colcon-metadata-repository/master/index.yaml && \ | |
colcon metadata update | |
# clone source | |
ENV ROS2_WS /opt/ros2_ws | |
RUN mkdir -p $ROS2_WS/src | |
WORKDIR $ROS2_WS | |
# build source | |
RUN colcon \ | |
build \ | |
--cmake-args \ | |
-DSECURITY=ON --no-warn-unused-cli \ | |
--symlink-install | |
# setup bashrc | |
RUN cp /etc/skel/.bashrc ~/ | |
# setup entrypoint | |
COPY ./ros_entrypoint.sh / | |
ENTRYPOINT ["/ros_entrypoint.sh"] | |
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# setup ros environment | |
if [ ${ROS_DISTRO} == "foxy" ] ; then | |
source "$ROS2_WS/install/local_setup.bash" | |
else | |
source "/opt/ros/$ROS_DISTRO/setup.bash" | |
source "$ROS_WS/devel/setup.bash" | |
fi | |
exec "$@" |
Hi thanks for providing these very useful scripts! Could it be that in the ROS2 Dockerfile the command to actually install Foxy is missing?
I'm relatively new to docker but I think you're right. ROS/ROS2 aren't part of the base image at stereolabs/zed:4.0-gl-devel-cuda11.4-ubuntu20.04 and I don't see where it might be installed in Dockerfile.ros2.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi thanks for providing these very useful scripts! Could it be that in the ROS2 Dockerfile the command to actually install Foxy is missing?