forked from space-ros/space-ros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
288 lines (254 loc) · 10.2 KB
/
Earthfile
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# Copyright 2021 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
VERSION 0.6
FROM ubuntu:jammy
# Defaulting to ROS 2 humble
ARG ROS_DISTRO="humble"
setup:
# Disable prompting during package installation
ARG DEBIAN_FRONTEND=noninteractive
ARG ROS_DISTRO
# TODO - the `setup` step will be merged with the `setup` step in spaceros docker Earthfile
# This variable will then act as a single source of truth.
ENV ROS_DISTRO ${ROS_DISTRO}
# The following commands are based on the source install for ROS 2 Rolling Ridley.
# See: https://docs.ros.org/en/ros2_documentation/rolling/Installation/Ubuntu-Development-Setup.html
# The main variation is getting Space ROS sources instead of the Rolling sources.
# Set the locale
RUN --mount=type=cache,mode=0777,target=/var/cache/apt,sharing=locked,id=cache_apt_cache \
--mount=type=cache,mode=0777,target=/var/lib/apt,sharing=locked,id=lib_apt_cache \
apt-get update && \
apt-get install -y locales
RUN locale-gen en_US en_US.UTF-8
RUN update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG=en_US.UTF-8
# Add the ROS 2 apt repository
RUN --mount=type=cache,mode=0777,target=/var/cache/apt,sharing=locked,id=cache_apt_cache \
--mount=type=cache,mode=0777,target=/var/lib/apt,sharing=locked,id=lib_apt_cache \
apt-get update && \
apt-get install -y \
curl \
gnupg \
lsb-release \
software-properties-common
RUN add-apt-repository universe
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null
# Install required software development tools and ROS tools (and vim included for convenience)
RUN --mount=type=cache,mode=0777,target=/var/cache/apt,sharing=locked,id=cache_apt_cache \
--mount=type=cache,mode=0777,target=/var/lib/apt,sharing=locked,id=lib_apt_cache \
apt-get update && \
apt-get install -y \
bison \
build-essential \
cmake \
git \
python3-colcon-common-extensions \
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 \
python3-pytest-cov \
python3-pytest-repeat \
python3-pytest-rerunfailures \
python3-rosdep \
python3-rosinstall-generator \
python3-setuptools \
python3-vcstool \
wget \
vim
# Define the username and key variables
ENV USERNAME spaceros-user
ENV HOME_DIR=/home/${USERNAME}
ENV SPACEROS_DIR=/opt/spaceros
# Create the spaceros directory
RUN mkdir --mode=777 -p ${SPACEROS_DIR}
# Create a spaceros user
RUN useradd -m ${USERNAME} && \
echo "${USERNAME}:${USERNAME}" | chpasswd && \
usermod --shell /bin/bash ${USERNAME} && \
usermod -aG sudo ${USERNAME} && \
mkdir -p /etc/sudoers.d && \
echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/${USERNAME} && \
chmod 0440 /etc/sudoers.d/${USERNAME}
USER ${USERNAME}
WORKDIR ${SPACEROS_DIR}
# Update the OpenGL version
RUN sudo add-apt-repository ppa:kisak/kisak-mesa
RUN --mount=type=cache,mode=0777,target=/var/cache/apt,sharing=locked,id=cache_apt_cache \
--mount=type=cache,mode=0777,target=/var/lib/apt,sharing=locked,id=lib_apt_cache \
sudo apt update && sudo apt upgrade -y
# Create install location and copy in relevant scripts
COPY --chown ${USERNAME}:${USERNAME} --dir docker/scripts/ ${SPACEROS_DIR}
repos-file:
FROM +setup
COPY excluded-pkgs.txt ./
COPY spaceros-pkgs.txt ./
COPY spaceros.repos ./
# This is a fresh image, so we do not need to exclude installed packages.
RUN --no-cache sh scripts/generate-repos.sh \
--outfile ros2.repos \
--packages spaceros-pkgs.txt \
--excluded-packages excluded-pkgs.txt \
--exclude-installed false \
--rosdistro ${ROS_DISTRO}
RUN --no-cache python3 scripts/merge-repos.py ros2.repos spaceros.repos -o output.repos
SAVE ARTIFACT output.repos AS LOCAL ros2.repos
spaceros-artifacts:
# we must run it in a separate container, so that downstream tasks can be cached if vcs file does not change
FROM +setup
USER ${USERNAME}
WORKDIR ${SPACEROS_DIR}
COPY ros2.repos ./
COPY excluded-pkgs.txt ./
# this ensure the vcs import and export results are not cached
RUN --no-cache echo "Cloning spaceros repo artifacts"
# we run vcstool inside this task, because some packages in `ros2.repos` are not pinned and otherwise
# earthly won't pull latest changes
RUN mkdir src
RUN vcs import --shallow --retry 3 --input ros2.repos src
RUN vcs export --exact src > exact.repos
SAVE ARTIFACT ros2.repos
SAVE ARTIFACT exact.repos # `ros2.repos`, but with pinned versions (e.g. SHAs instead of branches)
SAVE ARTIFACT excluded-pkgs.txt
sources:
FROM +setup
COPY +spaceros-artifacts/ros2.repos ros2.repos
COPY +spaceros-artifacts/excluded-pkgs.txt excluded-pkgs.txt
COPY +spaceros-artifacts/exact.repos exact.repos
RUN mkdir src
RUN vcs import --shallow --retry 3 --input exact.repos src
SAVE ARTIFACT src AS LOCAL src
vcs-exact:
COPY +spaceros-artifacts/${SPACEROS_DIR}/exact.repos exact.repos
SAVE ARTIFACT exact.repos AS LOCAL exact.repos
rosdep:
FROM +sources
COPY src src/
# Install system package dependencies using rosdep
RUN sudo rosdep init && rosdep update
RUN --mount=type=cache,mode=0777,target=/var/cache/apt,sharing=locked,id=cache_apt_cache \
--mount=type=cache,mode=0777,target=/var/lib/apt,sharing=locked,id=lib_apt_cache \
sudo apt-get update && \
rosdep update && \
rosdep install -y \
--from-paths src --ignore-src \
--rosdistro ${ROS_DISTRO} \
# `urdfdom_headers` is cloned from source, however rosdep can't find it.
# It is because package.xml manifest is missing. See: https://github.com/ros/urdfdom_headers
# Additionally, IKOS must be excluded as per: https://github.com/space-ros/docker/issues/99
--skip-keys "$(tr '\n' ' ' < 'excluded-pkgs.txt') urdfdom_headers ikos"
RUN rm excluded-pkgs.txt
RUN --mount=type=cache,mode=0777,target=/var/cache/apt,sharing=locked,id=cache_apt_cache \
--mount=type=cache,mode=0777,target=/var/lib/apt,sharing=locked,id=lib_apt_cache \
sudo apt-get update && \
sudo apt-get install --yes \
gcc \
g++ \
cmake \
libgmp-dev \
libboost-dev \
libboost-filesystem-dev \
libboost-thread-dev \
libboost-test-dev \
libsqlite3-dev \
libtbb-dev \
libz-dev \
libedit-dev \
python3 \
python3-pip \
python3-venv \
llvm-14 \
llvm-14-dev \
llvm-14-tools \
clang-14
WORKDIR ${SPACEROS_DIR}
RUN git clone -b v3.2 --depth 1 https://github.com/NASA-SW-VnV/ikos.git
WORKDIR ${SPACEROS_DIR}/ikos
RUN mkdir build
WORKDIR ${SPACEROS_DIR}/ikos/build
RUN cmake \
-DCMAKE_INSTALL_PREFIX="/opt/ikos" \
-DCMAKE_BUILD_TYPE="Debug" \
-DLLVM_CONFIG_EXECUTABLE="/usr/lib/llvm-14/bin/llvm-config" \
..
RUN make
RUN sudo make install
ENV PATH="/opt/ikos/bin/:$PATH"
WORKDIR ${SPACEROS_DIR}
RUN sudo rm -rf ikos/
build:
FROM +rosdep
RUN colcon build \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
--no-warn-unused-cli
COPY +spaceros-artifacts/exact.repos install/exact.repos
SAVE ARTIFACT install AS LOCAL install
build-dev:
FROM +rosdep
RUN colcon build \
--cmake-args \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
--no-warn-unused-cli
# TODO: Consider pushing pre-built dev images to the registry.
# SAVE IMAGE --push osrf/space-ros-dev:latest osrf/space-ros-dev:$tag
build-testing:
FROM +build-dev
RUN . install/setup.sh && \
colcon test \
--retest-until-pass 2 \
--ctest-args -LE "(ikos|xfail)" \
--pytest-args -m "not xfail"
RUN . install/setup.sh && \
ros2 run process_sarif make_build_archive
COPY +spaceros-artifacts/exact.repos install/exact.repos
SAVE ARTIFACT log/build_results_archives/build_results_*.tar.bz2 AS LOCAL log/build_results_archives/
SAVE ARTIFACT install AS LOCAL install
image:
FROM +rosdep
ARG VCS_REF
ARG VERSION="latest"
# Specify the docker image metadata
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="Space ROS"
LABEL org.label-schema.description="Preview version of the Space ROS platform"
LABEL org.label-schema.vendor="Open Robotics"
LABEL org.label-schema.url="https://github.com/space-ros"
LABEL org.label-schema.vcs-url="https://github.com/space-ros/docker-images"
LABEL org.label-schema.vcs-ref=${VCS_REF}
COPY +build/install ${SPACEROS_DIR}/install
COPY +spaceros-artifacts/exact.repos ${SPACEROS_DIR}/exact.repos
RUN rm -r src
WORKDIR ${HOME_DIR}
COPY docker/entrypoint.sh /ros_entrypoint.sh
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
SAVE IMAGE osrf/space-ros:${VERSION}
# Target for prepping image(s) to be pushed to remote registries.
push-image:
FROM +image
# This can be overridden with a blank string to prevent pushing to the registry.
ARG LATEST="osrf/space-ros:latest"
ARG TAG
SAVE IMAGE --push ${LATEST} ${TAG}