forked from space-ros/space-ros
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEarthfile
More file actions
467 lines (406 loc) · 16.1 KB
/
Earthfile
File metadata and controls
467 lines (406 loc) · 16.1 KB
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# 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.8
ARG --global IMAGE_NAME="osrf/space-ros"
ARG --global IMAGE_TAG="latest"
ARG --global USERNAME="spaceros-user"
ARG --global HOME="/home/${USERNAME}"
ARG --global WORKSPACE_DIR="/spaceros_ws"
###############################################################################
### Target Configurations
# Targets are the main entry points for the Earthfile. They are the commands
# that can be run by the user. The `all` target is the default target that is
# run when no target is specified.
###############################################################################
all:
# Order preserved for build
BUILD +main-image
BUILD +dev-image
# The main-image is a bare bones installation of the Space ROS packages.
main-image:
BUILD +image --IMAGE_VARIANT=${IMAGE_TAG}
# The dev-image persists the entire Space ROS workspace, as well as additional
# dev tooling and packages for working with Space ROS packages.
dev-image:
BUILD +image --IMAGE_VARIANT=dev --IMAGE_TAG=dev
###############################################################################
### PreInstallation Stage
# This stage is responsible for setting up the base image with the necessary
# dependencies required for the subsequent stages.
###############################################################################
pre-installation:
FROM ubuntu:noble
ENV DEBIAN_FRONTEND=noninteractive
ENV ROS_DISTRO="jazzy"
ENV HOME=${HOME}
ENV SPACEROS_DIR="/opt/ros/spaceros"
RUN mkdir -p ${WORKSPACE_DIR}
WORKDIR ${WORKSPACE_DIR}
# Set the locale
RUN 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
# 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.
# Add the ROS 2 apt repository
RUN apt-get update && apt-get install -y \
curl \
git \
cmake \
build-essential \
bison \
wget \
gnupg \
lsb-release \
python3-pip \
python3-setuptools \
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 \
&& apt update
###############################################################################
### Setup Stage
# This stage is responsible for setting up the ROS 2 workspace and the required
# dependencies for the workspace.
###############################################################################
setup:
FROM +pre-installation
# Install required software development tools and ROS tools (and vim included for convenience)
RUN apt-get install -y python3-rosinstall-generator
COPY scripts ./
COPY excluded-pkgs.txt spaceros-pkgs.txt spaceros.repos ./
# This is a fresh image, so we do not need to exclude installed packages.
ENV AMENT_PREFIX_PATH=${SPACEROS_DIR}
RUN sh generate-repos.sh \
--outfile ros2.repos \
--packages spaceros-pkgs.txt \
--excluded-packages excluded-pkgs.txt \
--rosdistro ${ROS_DISTRO}
RUN python3 merge-repos.py ros2.repos spaceros.repos -o output.repos
SAVE ARTIFACT output.repos AS LOCAL ros2.repos
###############################################################################
### IKOS Installation
# This stage is responsible for installing IKOS and its dependencies.
# This will be used for static analysis of the ROS 2 workspace during build
# test and development.
###############################################################################
ikos-install:
FROM +pre-installation
RUN apt-get update && 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 \
ros-dev-tools
RUN git clone -b v3.5 --depth 1 https://github.com/NASA-SW-VnV/ikos.git
RUN cd ikos \
&& mkdir build \
&& cd build \
&& cmake \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_INSTALL_PREFIX="/opt/ikos" \
-DCMAKE_BUILD_TYPE="Release" \
-DLLVM_CONFIG_EXECUTABLE="/usr/lib/llvm-14/bin/llvm-config" \
.. \
&& make -j$(nproc) \
&& make install
ENV PATH="/opt/ikos/bin/:$PATH"
RUN rm -rf ikos
SAVE ARTIFACT /opt/ikos AS LOCAL ikos
ADD_IKOS:
FUNCTION
RUN apt-get update && apt-get install -y \
gcc \
g++ \
cmake \
file \
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 \
ros-dev-tools
COPY +ikos-install/ikos /opt/ikos
ENV PATH="/opt/ikos/bin/:$PATH"
ENV IKOS_SCAN_NOTIFIER_FILES=""
###############################################################################
### Sources Stage
# This stage is responsible for fetching the ROS 2 workspace sources.
###############################################################################
sources:
FROM +setup
RUN apt-get update && apt-get install -y python3-vcstool
RUN mkdir src -p \
&& vcs import --retry 3 src < output.repos \
&& vcs export --exact src > exact.repos
# Save artifacts to be used
SAVE ARTIFACT exact.repos
SAVE ARTIFACT src
###############################################################################
### Rosdep Stage
# This stage is responsible for installing the system dependencies required
# for the ROS 2 workspace.
###############################################################################
rosdep:
FROM +pre-installation
# Rosdep updates
RUN apt-get update && apt-get install -y python3-rosdep \
&& rosdep init \
&& rosdep update
# Copy Repos file
COPY +sources/src ./src
COPY excluded-pkgs.txt excluded-deps.txt ./
# Install system package dependencies using rosdep
RUN rosdep install -y \
--from-paths src --ignore-src \
--simulate \
--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" > rosdeps.txt
# Process rosdeps.txt to a shell script
RUN touch rosdeps.sh \
&& echo "#!/bin/bash" > rosdeps.sh \
&& echo "apt-get update" >> rosdeps.sh \
&& echo "apt-get install -y \\" >> rosdeps.sh \
&& grep -v -F -f excluded-deps.txt rosdeps.txt | sed 's/^/ /' >> rosdeps.sh \
&& chmod +x rosdeps.sh
# The generated shell script is used by the prepare-image stage prior to building the image
# saving build time by not having to install dependencies again.
SAVE ARTIFACT rosdeps.sh
###############################################################################
### Build Stage
# This stage is responsible for building the ROS 2 workspace for either the dev
# or the main image.
###############################################################################
build:
ARG --required IMAGE_VARIANT
FROM +rosdep
# Uncrustify Vendor has vcstool as a dependency
RUN apt-get update && apt-get install -y \
python3-vcstool \
python3-colcon-common-extensions
RUN bash rosdeps.sh
RUN mkdir -p ${SPACEROS_DIR}
DO +BUILD_WORKSPACE --IMAGE_VARIANT=${IMAGE_VARIANT}
SAVE ARTIFACT ${SPACEROS_DIR} spaceros_install
BUILD_WORKSPACE:
FUNCTION
ARG --required IMAGE_VARIANT
# If Dev, we do not use a merge install for the sake of testing and development
IF [ "${IMAGE_VARIANT}" = "dev" ]
COPY colcon_ws_config colcon_ws_config
RUN python3 colcon_ws_config/prepare_workspace.py # outputs spaceros-linters.meta
RUN colcon build \
--metas ./spaceros-linters.meta \
--install-base ${SPACEROS_DIR} \
--merge-install \
--cmake-args \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CXX_FLAGS="--param ggc-min-expand=20" \
--no-warn-unused-cli
# Otherwise, compile the release image
ELSE
RUN colcon build \
--install-base ${SPACEROS_DIR} \
--merge-install \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CXX_FLAGS="--param ggc-min-expand=20" \
--no-warn-unused-cli
END
###############################################################################
### Build Test Stage
# This stage is responsible for running the tests on the ROS 2 workspace.
###############################################################################
build-test:
FROM +build --IMAGE_VARIANT=dev
# Install dependencies for testing
RUN apt-get update && apt-get install -y \
python3-flake8 \
python3-pydocstyle \
clang-tidy \
graphviz \
uncrustify \
python3-pycodestyle \
cppcheck \
python3-nose \
google-mock \
pydocstyle \
python3-pytest \
python3-pytest-timeout \
python3-pytest-mock \
python3-pytest-cov \
python3-matplotlib \
pyflakes3 \
python3-mypy \
python3-argcomplete
RUN pip3 install pytest-rerunfailures \
pytest-cov \
pytest-repeat \
mypy \
argcomplete --break-system-packages
RUN . ${SPACEROS_DIR}/setup.sh && \
colcon test \
--install-base ${SPACEROS_DIR} \
--merge-install \
--retest-until-pass 2 \
--packages-skip ament_lint \
--ctest-args -LE "(ikos|xfail)" \
--ctest-args "--output-on-failure" \
--pytest-args -m "not xfail" \
--pytest-args "--disable-warnings"
RUN . ${SPACEROS_DIR}/setup.sh && \
ros2 run process_sarif make_build_archive
SAVE ARTIFACT log/build_results_archives/build_results_*.tar.bz2 AS LOCAL log/build_results_archives/
###############################################################################
### Image Stage
# This stage is responsible for creating the final image with the ROS 2
# workspace. The image is saved only if the build-test stage is successful.
###############################################################################
prepare-image:
FROM +pre-installation
# Add missing dependencies
RUN apt-get update && apt-get install -y \
libspdlog-dev \
python3-numpy \
tzdata \
sudo \
ros-dev-tools
RUN pip3 install pyyaml \
lark \
packaging \
netifaces \
catkin_pkg \
psutil --break-system-packages
# Prepare the image
RUN mkdir -p ${SPACEROS_DIR}
COPY +rosdep/rosdeps.sh ${SPACEROS_DIR}/rosdeps.sh
RUN bash ${SPACEROS_DIR}/rosdeps.sh
###############################################################################
### Prepare Image Stage
# This stage is responsible for preparing the image with the ROS 2 workspace.
# The image is saved only if the build-test stage is successful.
###############################################################################
image:
ARG --required IMAGE_VARIANT
FROM +prepare-image
COPY +build/spaceros_install ${SPACEROS_DIR}
COPY +sources/exact.repos ${SPACEROS_DIR}/scripts/spaceros.repos
COPY scripts/generate-repos.sh scripts/merge-repos.py ${SPACEROS_DIR}/scripts/
RUN chmod +x ${SPACEROS_DIR}/scripts/generate-repos.sh ${SPACEROS_DIR}/scripts/merge-repos.py \
&& mv ${SPACEROS_DIR}/rosdeps.sh ${SPACEROS_DIR}/scripts/rosdeps.sh
# Post Installation cleanup
DO +POST_INSTALLATION --IMAGE_VARIANT=${IMAGE_VARIANT}
# Add user and group
RUN useradd --create-home -m -s /bin/bash ${USERNAME} && \
echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USERNAME} && \
cp -r /etc/skel/. ${HOME}
# Ensure the user has access to the home and install directories
RUN chown -R ${USERNAME}:${USERNAME} ${HOME}
USER ${USERNAME}
WORKDIR ${HOME}
# Add the entrypoint
COPY ./docker/entrypoint.sh /entrypoint.sh
RUN echo "source /entrypoint.sh" >> ${HOME}/.bashrc
ENTRYPOINT ["/entrypoint.sh"]
SAVE IMAGE ${IMAGE_NAME}:${IMAGE_VARIANT}
###############################################################################
### Post Installation Stage
# This stage is responsible for cleaning up the workspace and installing
# additional dependencies based on the image variant.
###############################################################################
POST_INSTALLATION:
FUNCTION
ARG --required IMAGE_VARIANT
# If Dev, install IKOS and excluded dependencies
IF [ "${IMAGE_VARIANT}" = "dev" ]
DO +ADD_IKOS
COPY excluded-deps.txt ./
RUN apt-get update && apt-get install -y \
$(grep -v '^#' excluded-deps.txt) \
&& rm -rf excluded-deps.txt
# If Core, we only care about the install, and then clear the workspace
ELSE
RUN rm -rf ${WORKSPACE_DIR}
END
# Clear Apt and Pip cache
RUN rm -rf /var/lib/apt/lists/* /tmp/pip-reqs /var/cache/apt/archives \
&& apt-get clean \
&& pip cache purge
###############################################################################
### Push Image Stage for main image
# This stage is responsible for pushing the core image to the registry.
###############################################################################
push-main-image:
# This can be overridden with a blank string to prevent pushing to the registry.
ARG --required VCS_REF
FROM +image --IMAGE_VARIANT=${IMAGE_TAG}
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="Space ROS - Core/Main"
LABEL org.label-schema.description="Core 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/space-ros"
LABEL org.label-schema.vcs-ref=${VCS_REF}
SAVE IMAGE --push ${IMAGE_NAME}:${IMAGE_TAG}
###############################################################################
### Push Image Stage for dev image
# This stage is responsible for pushing the dev image to the registry.
###############################################################################
push-dev-image:
# This can be overridden with a blank string to prevent pushing to the registry.
ARG --required VCS_REF
FROM +image --IMAGE_VARIANT=dev
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="Space ROS - Dev"
LABEL org.label-schema.description="Dev 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/space-ros"
LABEL org.label-schema.vcs-ref=${VCS_REF}
SAVE IMAGE --push ${IMAGE_NAME}:${IMAGE_TAG}