Skip to content

Update Dockerfile #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 18 additions & 96 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,103 +1,25 @@
# 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 ./
#
# If you prefer to use Rolling, just add the following build args:
# --build-arg FROM_IMAGE=ros:rolling
# --build-arg REPOS_FILE=ros2_rust_rolling.repos

ARG FROM_IMAGE=ros:foxy
ARG OVERLAY_WS=/opt/overlay_ws
ARG REPOS_FILE=ros2_rust_foxy.repos

# multi-stage for caching
FROM $FROM_IMAGE AS cacher

# clone overlay source
ARG OVERLAY_WS
ARG REPOS_FILE
WORKDIR $OVERLAY_WS/src
COPY ./${REPOS_FILE} ../
RUN vcs import ./ < ../${REPOS_FILE} && \
find ./ -name ".git" | xargs rm -rf
COPY ./ ./ros2-rust/ros2_rust

# copy manifests for caching
WORKDIR /opt
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 builder
FROM ros:foxy as base
ARG DEBIAN_FRONTEND=noninteractive

# install CI dependencies
RUN apt-get update && apt-get install -q -y \
ccache \
clang \
lcov \
libclang-dev \
llvm-dev \
wget \
# Install dependencies
RUN apt-get update && apt-get install -y \
clang \
curl \
git \
libclang-dev \
tmux \
python3-pip \
&& rm -rf /var/lib/apt/lists/*

# install rust dependencies
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.58.0
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;

# install overlay dependencies
ARG OVERLAY_WS
WORKDIR $OVERLAY_WS
COPY --from=cacher /tmp/$OVERLAY_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/*
# Install Rust and the cargo-ament-build plugin
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain 1.59.0 -y
ENV PATH=/root/.cargo/bin:$PATH
RUN cargo install cargo-ament-build

# build overlay source
COPY --from=cacher $OVERLAY_WS ./
ARG OVERLAY_MIXINS="release ccache"
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
colcon build \
--symlink-install \
--mixin $OVERLAY_MIXINS \
|| ([ -z "$FAIL_ON_BUILD_FAILURE" ] || exit 1)
RUN pip install --upgrade pytest

# source overlay from entrypoint
ENV OVERLAY_WS $OVERLAY_WS
RUN sed --in-place \
's|^source .*|source "$OVERLAY_WS/install/setup.bash"|' \
/ros_entrypoint.sh
# Install the colcon-cargo and colcon-ros-cargo plugins
RUN pip install git+https://github.com/colcon/colcon-cargo.git git+https://github.com/colcon/colcon-ros-cargo.git

# test overlay build
ARG RUN_TESTS
ARG FAIL_ON_TEST_FAILURE=True
RUN if [ -n "$RUN_TESTS" ]; then \
. install/setup.sh && \
colcon test && \
colcon test-result \
|| ([ -z "$FAIL_ON_TEST_FAILURE" ] || exit 1) \
fi
RUN mkdir -p /workspace && echo "Did you forget to mount the repository into the Docker container?" > /workspace/HELLO.txt
WORKDIR /workspace