-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.ros2
214 lines (174 loc) · 6.54 KB
/
Dockerfile.ros2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Default platform = opensource gpu acceleration
ARG GRAPHICS_PLATFORM=opensource
# Default python version is 3.8
ARG PYTHONVER=3.10
# ROS Version
ARG ROS_DISTRO=humble
ARG IGNITION_VERSION=fortress
# Workspace
ARG ROS2_WS=/opt/ros2_ws
#############################################################
########## REAL BUILD STARTS HERE ##########
## Build container from specified source
FROM ros_ml_container:baseimage
LABEL org.opencontainers.image.source="https://github.com/SimonSchwaiger/ros-ml-container"
ENV DEBIAN_FRONTEND="noninteractive"
# Install mesa for GUI
RUN apt-get update && apt-get install -q -y --no-install-recommends \
libgl1-mesa-glx libgl1-mesa-dri
ARG ROS2_WS
ENV ROS2_WS $ROS2_WS
## Recreate ROS humble devel image
# ------------------------
# https://github.com/osrf/docker_images/blob/master/ros2/source/devel/Dockerfile
# setup timezone
RUN echo 'Etc/UTC' > /etc/timezone && \
ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
apt-get update && \
apt-get install -q -y --no-install-recommends tzdata && \
rm -rf /var/lib/apt/lists/*
# install packages
RUN apt-get update && apt-get install -q -y --no-install-recommends \
bash-completion \
dirmngr \
gnupg2 \
lsb-release \
python3-flake8 \
python3-flake8-blind-except \
python3-flake8-builtins \
python3-flake8-class-newline \
python3-flake8-comprehensions \
python3-flake8-deprecated \
python3-flake8-docstrings \
python3-flake8-import-order \
python3-flake8-quotes \
python3-pip \
python3-pytest-repeat \
python3-pytest-rerunfailures \
&& rm -rf /var/lib/apt/lists/*
# setup sources.list
RUN echo "deb http://packages.ros.org/ros2/ubuntu jammy main" > /etc/apt/sources.list.d/ros2-latest.list
# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
git \
python3-colcon-common-extensions \
python3-colcon-mixin \
python3-rosdep \
python3-setuptools \
python3-vcstool \
&& rm -rf /var/lib/apt/lists/*
# install python packages
RUN pip3 install -U \
argcomplete pytest
# add pytest here manually as a workaround for intel-based builds
# This is a workaround for pytest not found causing builds to fail
# Following RUN statements tests for regression of https://github.com/ros2/ros2/issues/722
RUN pip3 freeze | grep pytest \
&& python3 -m pytest --version
# 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
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 ~/
WORKDIR /
## Official ROS image recreated
# ------------------------
# Set ROS and ignition versions and install them
ARG ROS_DISTRO
ARG IGNITION_VERSION
ENV ROS_DISTRO ${ROS_DISTRO}
ENV IGNITION_VERSION ${IGNITION_VERSION}
# Fully install ros2 instead of bootstrapping it and install rqt for debugging and rosbridge for web-based visualisation
RUN apt-get update && apt-get install -y ros-$ROS_DISTRO-ros-base ros-dev-tools ros-$ROS_DISTRO-rqt* ros-$ROS_DISTRO-rosbridge-server
# Install ignition gazebo
#RUN apt-get install -y ros-$ROS_DISTRO-ros-ign ignition-$IGNITION_VERSION
# Update os and ros packages due to fix buggy opengl
RUN apt-get update && apt-get upgrade -y
# install python3, pip and venv
# you can change your preferred python version here and it will be installed from the deadsnakes ppa
# some tensorflow implementations (such as gym baselines 2) will require python 3.7
# Forward PYTHONVER argument to the current container
ARG PYTHONVER
ARG GRAPHICS_PLATFORM
RUN apt-get update && apt-get install -y software-properties-common \
&& add-apt-repository -y ppa:deadsnakes/ppa \
&& apt-get update && apt-get install -y python$PYTHONVER python$PYTHONVER-dev python$PYTHONVER-tk
RUN apt-get update && apt-get install -y --no-install-recommends \
python3-pip \
python3-venv \
cmake \
libopenmpi-dev \
zlib1g-dev \
imagemagick
RUN pip3 install virtualenv
# Create virtualenv using the correct python interpreter
# Intel is an edgecase here, since they offer a custom interpreter in the intel distribution for python
RUN if [ "$GRAPHICS_PLATFORM" = "intel" ]; then \
virtualenv -p /opt/intel/oneapi/intelpython/latest/bin/python ~/myenv; else \
virtualenv -p /usr/bin/python$PYTHONVER ~/myenv; fi
# Upgrade to latest pip
RUN /bin/bash -c "source ~/myenv/bin/activate \
&& pip3 install --upgrade pip"
# Install ros python prerequisites
# Pytest is explicitly installed to handle the intel edgecase
# Netifaces, pymongo and Pillow are installed for rosbridge
RUN /bin/bash -c "source ~/myenv/bin/activate \
&& pip3 install launchpadlib \
rosinstall_generator \
rosinstall \
empy \
catkin_tools \
lark \
lxml \
pytest \
numpy \
netifaces pymongo Pillow \
&& pip3 install --upgrade setuptools"
# Install required python packages
ADD ./requirements.txt .
RUN /bin/bash -c "source ~/myenv/bin/activate \
&& pip3 install -r requirements.txt"
# Copy ROS packages for compilation in container
COPY ./src $ROS2_WS/src
# Install ros dependencies
RUN apt-get update && rosdep update && rosdep install --from-paths $ROS2_WS/src -i -y --rosdistro $ROS_DISTRO
# Compile workspace
RUN /bin/bash -c "source /opt/ros/$ROS_DISTRO/setup.bash \
&& cd $ROS2_WS \
&& colcon build --symlink-install"
# Remove src folder used for compilation, since the real src folder will be mounted at runtime
RUN rm -rf $ROS2_WS/src
# Cleanup
RUN rm -rf /var/lib/apt/lists/*
# Add ROS and venv sourcing to bashrc for interactive debugging
RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> ~/.bashrc
RUN echo "source $ROS2_WS/install/local_setup.bash" >> ~/.bashrc
RUN echo "source ~/myenv/bin/activate" >> ~/.bashrc
# Set shell env variable for jupyterlab (this fixes autocompletion in web-based shell)
ENV SHELL=/bin/bash
# Add entrypoint
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]