From 2b9fcf5a66e936269244e8d18914c91579fcbf23 Mon Sep 17 00:00:00 2001 From: ruffsl Date: Mon, 24 Aug 2020 10:50:16 -0700 Subject: [PATCH 01/11] Stage Docker changes --- .dockerignore | 58 +++++++++++++++++++++++++++++++++++++ Dockerfile | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ ros2_rust.repos | 14 ++++----- 3 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..c3e11a38d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,58 @@ +################################################################################ +# Repo + +.git/* +.dockerignore +.gitignore +**Dockerfile +**.Dockerfile + +################################################################################ +# Rust + +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +################################################################################ +# C++ + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..be2518965 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,76 @@ +ARG FROM_IMAGE=ros:eloquent + +# multi-stage for caching +FROM $FROM_IMAGE AS cache + +# clone overlay source +ENV OVERLAY_WS /opt/overlay_ws +RUN mkdir -p $OVERLAY_WS/src +WORKDIR $OVERLAY_WS +COPY ./ros2_rust.repos ./ +RUN vcs import src < ros2_rust.repos +COPY ./ src/ros2-rust/ros2_rust + +# copy manifests for caching +WORKDIR /opt +RUN find ./ -name "package.xml" | \ + xargs cp --parents -t /tmp + # find ./ -name "COLCON_IGNORE" | \ + # xargs cp --parents -t /tmp + +# multi-stage for building +FROM $FROM_IMAGE AS build + +# install CI dependencies +RUN apt-get update && apt-get install -q -y \ + ccache \ + clang \ + lcov \ + libclang-dev \ + llvm-dev \ + wget \ + && rm -rf /var/lib/apt/lists/* + +# copy overlay manifests +ENV OVERLAY_WS /opt/overlay_ws +COPY --from=cache /tmp/overlay_ws $OVERLAY_WS +WORKDIR $OVERLAY_WS + +# install overlay dependencies +RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ + apt-get update && rosdep install -q -y \ + --from-paths src \ + --ignore-src \ + && rm -rf /var/lib/apt/lists/* + +# install rust +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH \ + RUST_VERSION=1.41.1 +RUN set -eux; \ + wget -O rustup-init "https://sh.rustup.rs"; \ + chmod +x rustup-init; \ + ./rustup-init -y \ + --no-modify-path \ + --default-toolchain $RUST_VERSION; \ + rm rustup-init; \ + chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \ + rustup --version; \ + cargo --version; \ + rustc --version; + +# copy overlay source +COPY --from=cache $OVERLAY_WS ./ + +# build overlay source +ARG OVERLAY_MIXINS="release ccache" +RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ + colcon build \ + --symlink-install \ + --mixin $OVERLAY_MIXINS + +# source overlay from entrypoint +RUN sed --in-place \ + 's|^source .*|source "$OVERLAY_WS/install/setup.bash"|' \ + /ros_entrypoint.sh \ No newline at end of file diff --git a/ros2_rust.repos b/ros2_rust.repos index 18b65fb40..ceb039b9e 100644 --- a/ros2_rust.repos +++ b/ros2_rust.repos @@ -2,16 +2,16 @@ repositories: ros2/common_interfaces: type: git url: https://github.com/ros2/common_interfaces.git - version: crystal + version: eloquent ros2/rcl_interfaces: type: git url: https://github.com/ros2/rcl_interfaces.git - version: crystal + version: eloquent ros2/rosidl_defaults: type: git url: https://github.com/ros2/rosidl_defaults.git - version: crystal - ros2_rust/ros2_rust: - type: git - url: https://github.com/ros2-rust/ros2_rust.git - version: master + version: eloquent + # ros2-rust/ros2_rust: + # type: git + # url: https://github.com/ros2-rust/ros2_rust.git + # version: master From 291b2fe88ddb20f4adc535b6bbd0fee8e2de5ba5 Mon Sep 17 00:00:00 2001 From: ruffsl Date: Mon, 24 Aug 2020 11:16:17 -0700 Subject: [PATCH 02/11] Update underlay and overlay --- Dockerfile | 104 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index be2518965..19b3f3b63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,33 @@ -ARG FROM_IMAGE=ros:eloquent +ARG FROM_IMAGE=ros:foxy +ARG UNDERLAY_WS=/opt/underlay_ws +ARG OVERLAY_WS=/opt/overlay_ws # multi-stage for caching -FROM $FROM_IMAGE AS cache +FROM $FROM_IMAGE AS cacher + +# copy underlay source +ARG UNDERLAY_WS +WORKDIR $UNDERLAY_WS/src +COPY ./ ./ros2-rust/ros2_rust # clone overlay source -ENV OVERLAY_WS /opt/overlay_ws -RUN mkdir -p $OVERLAY_WS/src -WORKDIR $OVERLAY_WS -COPY ./ros2_rust.repos ./ -RUN vcs import src < ros2_rust.repos -COPY ./ src/ros2-rust/ros2_rust +ARG OVERLAY_WS +WORKDIR $OVERLAY_WS/src +COPY ./ros2_rust.repos ../ +RUN vcs import ./ < ../ros2_rust.repos && \ + find ./ -name ".git" | xargs rm -rf # copy manifests for caching WORKDIR /opt -RUN find ./ -name "package.xml" | \ - xargs cp --parents -t /tmp - # find ./ -name "COLCON_IGNORE" | \ - # xargs cp --parents -t /tmp +RUN mkdir -p /tmp/opt && \ + find ./ -name "package.xml" | \ + xargs cp --parents -t /tmp/opt && \ + find ./ -name "COLCON_IGNORE" | \ + xargs cp --parents -t /tmp/opt || true # multi-stage for building -FROM $FROM_IMAGE AS build +FROM $FROM_IMAGE AS builder +ARG DEBIAN_FRONTEND=noninteractive # install CI dependencies RUN apt-get update && apt-get install -q -y \ @@ -31,23 +39,11 @@ RUN apt-get update && apt-get install -q -y \ wget \ && rm -rf /var/lib/apt/lists/* -# copy overlay manifests -ENV OVERLAY_WS /opt/overlay_ws -COPY --from=cache /tmp/overlay_ws $OVERLAY_WS -WORKDIR $OVERLAY_WS - -# install overlay dependencies -RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ - apt-get update && rosdep install -q -y \ - --from-paths src \ - --ignore-src \ - && rm -rf /var/lib/apt/lists/* - -# install rust +# install rust dependencies ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ PATH=/usr/local/cargo/bin:$PATH \ - RUST_VERSION=1.41.1 + RUST_VERSION=1.45.2 RUN set -eux; \ wget -O rustup-init "https://sh.rustup.rs"; \ chmod +x rustup-init; \ @@ -60,17 +56,61 @@ RUN set -eux; \ cargo --version; \ rustc --version; -# copy overlay source -COPY --from=cache $OVERLAY_WS ./ +# install underlay dependencies +ARG UNDERLAY_WS +WORKDIR $UNDERLAY_WS +COPY --from=cacher /tmp/$UNDERLAY_WS ./ +RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ + apt-get update && rosdep install -q -y \ + --from-paths src \ + --ignore-src \ + && rm -rf /var/lib/apt/lists/* + +# build underlay source +COPY --from=cacher $UNDERLAY_WS ./ +ARG UNDERLAY_MIXINS="release ccache" +ARG FAIL_ON_BUILD_FAILURE=True +RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ + colcon build \ + --symlink-install \ + --mixin $UNDERLAY_MIXINS \ + --event-handlers console_direct+ \ + || ([ -z "$FAIL_ON_BUILD_FAILURE" ] || exit 1) + +# install overlay dependencies +ARG OVERLAY_WS +WORKDIR $OVERLAY_WS +COPY --from=cacher /tmp/$OVERLAY_WS ./ +RUN . $UNDERLAY_WS/install/setup.sh && \ + apt-get update && rosdep install -q -y \ + --from-paths src \ + $UNDERLAY_WS/src \ + --ignore-src \ + && rm -rf /var/lib/apt/lists/* # build overlay source +COPY --from=cacher $OVERLAY_WS ./ ARG OVERLAY_MIXINS="release ccache" -RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ +RUN . $UNDERLAY_WS/install/setup.sh && \ colcon build \ --symlink-install \ - --mixin $OVERLAY_MIXINS + --mixin $OVERLAY_MIXINS \ + || ([ -z "$FAIL_ON_BUILD_FAILURE" ] || exit 1) # source overlay from entrypoint +ENV UNDERLAY_WS $UNDERLAY_WS +ENV OVERLAY_WS $OVERLAY_WS RUN sed --in-place \ 's|^source .*|source "$OVERLAY_WS/install/setup.bash"|' \ - /ros_entrypoint.sh \ No newline at end of file + /ros_entrypoint.sh + +# test overlay build +ARG RUN_TESTS +ARG FAIL_ON_TEST_FAILURE=Ture +RUN if [ -n "$RUN_TESTS" ]; then \ + . $OVERLAY_WS/install/setup.sh && \ + colcon test \ + --mixin $OVERLAY_MIXINS \ + && colcon test-result \ + || ([ -z "$FAIL_ON_TEST_FAILURE" ] || exit 1) \ + fi \ No newline at end of file From c237feccce2411e7ac294b9162e23e6cf11f26f0 Mon Sep 17 00:00:00 2001 From: ruffsl Date: Mon, 24 Aug 2020 11:17:35 -0700 Subject: [PATCH 03/11] Only use combined overlay given mix of build dependencies --- Dockerfile | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index 19b3f3b63..21e7b7081 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,16 @@ ARG FROM_IMAGE=ros:foxy -ARG UNDERLAY_WS=/opt/underlay_ws ARG OVERLAY_WS=/opt/overlay_ws # multi-stage for caching FROM $FROM_IMAGE AS cacher -# copy underlay source -ARG UNDERLAY_WS -WORKDIR $UNDERLAY_WS/src -COPY ./ ./ros2-rust/ros2_rust - # clone overlay source ARG OVERLAY_WS WORKDIR $OVERLAY_WS/src COPY ./ros2_rust.repos ../ RUN vcs import ./ < ../ros2_rust.repos && \ find ./ -name ".git" | xargs rm -rf +COPY ./ ./ros2-rust/ros2_rust # copy manifests for caching WORKDIR /opt @@ -56,49 +51,26 @@ RUN set -eux; \ cargo --version; \ rustc --version; -# install underlay dependencies -ARG UNDERLAY_WS -WORKDIR $UNDERLAY_WS -COPY --from=cacher /tmp/$UNDERLAY_WS ./ -RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ - apt-get update && rosdep install -q -y \ - --from-paths src \ - --ignore-src \ - && rm -rf /var/lib/apt/lists/* - -# build underlay source -COPY --from=cacher $UNDERLAY_WS ./ -ARG UNDERLAY_MIXINS="release ccache" -ARG FAIL_ON_BUILD_FAILURE=True -RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ - colcon build \ - --symlink-install \ - --mixin $UNDERLAY_MIXINS \ - --event-handlers console_direct+ \ - || ([ -z "$FAIL_ON_BUILD_FAILURE" ] || exit 1) - # install overlay dependencies ARG OVERLAY_WS WORKDIR $OVERLAY_WS COPY --from=cacher /tmp/$OVERLAY_WS ./ -RUN . $UNDERLAY_WS/install/setup.sh && \ +RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ apt-get update && rosdep install -q -y \ --from-paths src \ - $UNDERLAY_WS/src \ --ignore-src \ && rm -rf /var/lib/apt/lists/* # build overlay source COPY --from=cacher $OVERLAY_WS ./ ARG OVERLAY_MIXINS="release ccache" -RUN . $UNDERLAY_WS/install/setup.sh && \ +RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ colcon build \ --symlink-install \ --mixin $OVERLAY_MIXINS \ || ([ -z "$FAIL_ON_BUILD_FAILURE" ] || exit 1) # source overlay from entrypoint -ENV UNDERLAY_WS $UNDERLAY_WS ENV OVERLAY_WS $OVERLAY_WS RUN sed --in-place \ 's|^source .*|source "$OVERLAY_WS/install/setup.bash"|' \ From f856f0d2b99313ca2cb6da508c03b83d6fbcb6db Mon Sep 17 00:00:00 2001 From: ruffsl Date: Mon, 24 Aug 2020 11:19:52 -0700 Subject: [PATCH 04/11] Remove mxin from test --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 21e7b7081..4a57f22b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -82,7 +82,6 @@ ARG FAIL_ON_TEST_FAILURE=Ture RUN if [ -n "$RUN_TESTS" ]; then \ . $OVERLAY_WS/install/setup.sh && \ colcon test \ - --mixin $OVERLAY_MIXINS \ && colcon test-result \ || ([ -z "$FAIL_ON_TEST_FAILURE" ] || exit 1) \ fi \ No newline at end of file From a1344f3c0232def9562740731b74a6315e7c58ad Mon Sep 17 00:00:00 2001 From: ruffsl Date: Mon, 24 Aug 2020 11:23:50 -0700 Subject: [PATCH 05/11] Add comment with build example --- Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Dockerfile b/Dockerfile index 4a57f22b2..202bc70cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,13 @@ +# This dockerfile can be configured via --build-arg +# Build context must be the /ros2_rust root folder for COPY. +# Example build command: +# export OVERLAY_MIXINS="debug ccache coverage" +# export RUN_TESTS="true" +# docker build -t nav2:latest \ +# --build-arg OVERLAY_MIXINS \ +# --build-arg RUN_TESTS +# --pull ./ + ARG FROM_IMAGE=ros:foxy ARG OVERLAY_WS=/opt/overlay_ws From 0b76c1056488219673b012e8c1d4f518c62dafdd Mon Sep 17 00:00:00 2001 From: ruffsl Date: Mon, 24 Aug 2020 11:30:19 -0700 Subject: [PATCH 06/11] Update repos file --- ros2_rust.repos | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ros2_rust.repos b/ros2_rust.repos index ceb039b9e..61b6ae041 100644 --- a/ros2_rust.repos +++ b/ros2_rust.repos @@ -2,15 +2,15 @@ repositories: ros2/common_interfaces: type: git url: https://github.com/ros2/common_interfaces.git - version: eloquent + version: foxy ros2/rcl_interfaces: type: git url: https://github.com/ros2/rcl_interfaces.git - version: eloquent + version: foxy ros2/rosidl_defaults: type: git url: https://github.com/ros2/rosidl_defaults.git - version: eloquent + version: foxy # ros2-rust/ros2_rust: # type: git # url: https://github.com/ros2-rust/ros2_rust.git From 79edf48329348c2805208a1f3ddefc647a8b18af Mon Sep 17 00:00:00 2001 From: ruffsl Date: Mon, 24 Aug 2020 11:33:18 -0700 Subject: [PATCH 07/11] Fix newline --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 202bc70cc..5f34a7c7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -94,4 +94,4 @@ RUN if [ -n "$RUN_TESTS" ]; then \ colcon test \ && colcon test-result \ || ([ -z "$FAIL_ON_TEST_FAILURE" ] || exit 1) \ - fi \ No newline at end of file + fi From d5c6adbb73c6dcce8de5fe75c521c649914e9b2d Mon Sep 17 00:00:00 2001 From: ruffsl Date: Mon, 24 Aug 2020 14:32:24 -0700 Subject: [PATCH 08/11] Update readme --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 039d2dc2b..ef6cdf8b9 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,11 @@ The following steps were last tested on Ubuntu 18.04. They show how to build the # sudo apt install ros-foxy-desktop python3-vcstool libclang-dev clang # pip install vcstool -mkdir -p ~/ros2_rust_ws/src -cd ~/ros2_rust_ws -wget https://raw.githubusercontent.com/ros2-rust/ros2_rust/master/ros2_rust.repos -vcs import src < ros2_rust.repos +mkdir -p ~/ros2_rust_ws/src/ros2-rust +cd ~/ros2_rust_ws/src/ros2-rust +git clone https://github.com/ros2-rust/ros2_rust.git +cd ../../ +vcs import src < src/ros2-rust/ros2_rust/ros2_rust.repos source /opt/ros/foxy/setup.sh colcon build ``` From b953759d77393aaabf2e1245cb6e8f8504aa5ce2 Mon Sep 17 00:00:00 2001 From: ruffsl Date: Mon, 24 Aug 2020 14:44:03 -0700 Subject: [PATCH 09/11] Add docker example to readme --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef6cdf8b9..3826179cb 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,20 @@ Lots of things! Sounds great, how can I try this out? ------------------------------------- -The following steps were last tested on Ubuntu 18.04. They show how to build the examples: +You can build and run the example using the included Dockerfile: +``` +git clone https://github.com/ros2-rust/ros2_rust.git +docker build --tag ros2:rust . +docker run -it --rm ros2:rust +ros2 run rclrs_examples rclrs_publisher & +ros2 run rclrs_examples rclrs_subscriber + +``` + +Or do so manually as summarized in the steps below: + +> The following steps were last tested on Ubuntu 20.04. ``` # first, install vcstool from PyPI or apt: From 62af49fd63005dce4f345a3615e4c5bdf222c2ca Mon Sep 17 00:00:00 2001 From: ruffsl Date: Tue, 20 Oct 2020 21:21:26 -0700 Subject: [PATCH 10/11] Update rust version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5f34a7c7f..1bdcde43f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,7 +48,7 @@ RUN apt-get update && apt-get install -q -y \ ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ PATH=/usr/local/cargo/bin:$PATH \ - RUST_VERSION=1.45.2 + RUST_VERSION=1.47.0 RUN set -eux; \ wget -O rustup-init "https://sh.rustup.rs"; \ chmod +x rustup-init; \ From 6333263e630a77d3ef65e9f3364fd802a60064f7 Mon Sep 17 00:00:00 2001 From: ruffsl Date: Tue, 20 Oct 2020 21:21:55 -0700 Subject: [PATCH 11/11] Update testing in dockerfile --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1bdcde43f..d8c6b0b61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -88,10 +88,10 @@ RUN sed --in-place \ # test overlay build ARG RUN_TESTS -ARG FAIL_ON_TEST_FAILURE=Ture +ARG FAIL_ON_TEST_FAILURE=True RUN if [ -n "$RUN_TESTS" ]; then \ - . $OVERLAY_WS/install/setup.sh && \ - colcon test \ - && colcon test-result \ + . install/setup.sh && \ + colcon test && \ + colcon test-result \ || ([ -z "$FAIL_ON_TEST_FAILURE" ] || exit 1) \ fi