|
| 1 | +# Stage 1: Cache source dependencies |
| 2 | +FROM ros:lyrical-ros-base AS cacher |
| 3 | + |
| 4 | +WORKDIR /ws/src |
| 5 | + |
| 6 | +COPY docker/files/lyrical.repos . |
| 7 | +RUN vcs import < lyrical.repos |
| 8 | + |
| 9 | +COPY docker/files/patches/lyrical /tmp/patches |
| 10 | +RUN bash -c '\ |
| 11 | + for subdep in `ls`; do \ |
| 12 | + pushd $subdep && \ |
| 13 | + if [ -f /tmp/patches/$subdep.sh ]; then \ |
| 14 | + echo "Post-processing $subdep source dependency" && /bin/bash /tmp/patches/$subdep.sh; \ |
| 15 | + fi && \ |
| 16 | + popd; \ |
| 17 | + done' |
| 18 | + |
| 19 | +COPY . beluga/ |
| 20 | + |
| 21 | +# Copy minimal workspace contents for dependency resolution |
| 22 | +RUN mkdir -p /tmp/ws/src \ |
| 23 | + && find ./ -name "package.xml" | xargs cp --parents -t /tmp/ws/src \ |
| 24 | + && find ./ -name "COLCON_IGNORE" | xargs cp --parents -t /tmp/ws/src \ |
| 25 | + || true |
| 26 | + |
| 27 | +# Stage 2: Build timem from timemory |
| 28 | +FROM ros:lyrical-ros-base AS timem-builder |
| 29 | + |
| 30 | +RUN apt-get update \ |
| 31 | + && apt-get install --no-install-recommends -y \ |
| 32 | + git \ |
| 33 | + && rm -rf /var/lib/apt/lists/* |
| 34 | + |
| 35 | +WORKDIR /opt |
| 36 | + |
| 37 | +RUN git clone -b develop https://github.com/NERSC/timemory.git \ |
| 38 | + && cd timemory \ |
| 39 | + && git checkout 415650ee26f358218908983c87212b620c3a0328 \ |
| 40 | + && cmake -B ./build \ |
| 41 | + -DTIMEMORY_INSTALL_HEADERS=OFF \ |
| 42 | + -DTIMEMORY_INSTALL_CONFIG=OFF \ |
| 43 | + -DTIMEMORY_INSTALL_ALL=OFF \ |
| 44 | + -DTIMEMORY_BUILD_TIMEM=ON \ |
| 45 | + . \ |
| 46 | + && cmake --build ./build --target timem |
| 47 | + |
| 48 | +# Stage 3: Main builder image |
| 49 | +FROM ros:lyrical-ros-base AS builder |
| 50 | + |
| 51 | +ENV DEBIAN_FRONTEND=noninteractive |
| 52 | + |
| 53 | +# Install build/debug/dev tools |
| 54 | +RUN apt-get update \ |
| 55 | + && apt-get install --no-install-recommends -y \ |
| 56 | + ccache \ |
| 57 | + curl \ |
| 58 | + gcovr \ |
| 59 | + gdb \ |
| 60 | + git \ |
| 61 | + lcov \ |
| 62 | + linux-perf \ |
| 63 | + linux-tools-common \ |
| 64 | + linux-tools-generic \ |
| 65 | + python3-colcon-coveragepy-result \ |
| 66 | + python3-colcon-lcov-result \ |
| 67 | + python3-pip \ |
| 68 | + tmux \ |
| 69 | + && rm -rf /var/lib/apt/lists/* |
| 70 | + |
| 71 | +ENV PIP_BREAK_SYSTEM_PACKAGES=1 |
| 72 | +RUN pip install \ |
| 73 | + evo==1.21.0 \ |
| 74 | + pre-commit==2.20.0 |
| 75 | + |
| 76 | +# Install timem from previous stage |
| 77 | +COPY --from=timem-builder --chown=developer:ekumen /opt/timemory/ /opt/timemory |
| 78 | +RUN cmake --build /opt/timemory/build --target install |
| 79 | + |
| 80 | +# Check if perf is working, if not replace it with the perf version available |
| 81 | +RUN perf help || ( \ |
| 82 | + mv /usr/bin/perf /usr/bin/perf.bkp && \ |
| 83 | + ln -s $(ls -d /usr/lib/linux-tools/* | tail -n1)/perf /usr/bin/perf) |
| 84 | + |
| 85 | +# Create developer user |
| 86 | +ARG USER=developer |
| 87 | +ARG GROUP=ekumen |
| 88 | + |
| 89 | +RUN deluser ubuntu |
| 90 | + |
| 91 | +RUN addgroup --gid 1001 $GROUP \ |
| 92 | + && adduser --uid 1001 --ingroup $GROUP --home /home/$USER --shell /bin/sh --disabled-password --gecos "" $USER \ |
| 93 | + && adduser $USER sudo \ |
| 94 | + && echo "$USER ALL=NOPASSWD: ALL" >> /etc/sudoers.d/$USER |
| 95 | + |
| 96 | +# Install fixuid |
| 97 | +COPY docker/files/fixuid_config.yml /etc/fixuid/config.yml |
| 98 | +RUN /bin/bash -c '\ |
| 99 | + ARCH=`uname -m` && if [ "$ARCH" == "aarch64" ]; then FIXUID_ARCH="arm64"; else FIXUID_ARCH="amd64"; fi \ |
| 100 | + && curl -SsL https://github.com/boxboat/fixuid/releases/download/v0.6.0/fixuid-0.6.0-linux-$FIXUID_ARCH.tar.gz | tar -C /usr/local/bin -xzf - \ |
| 101 | + && chmod 4755 /usr/local/bin/fixuid \ |
| 102 | + && cd /etc/fixuid \ |
| 103 | + && sed -i "s/_USER_/$USER/" config.yml \ |
| 104 | + && sed -i "s/_GROUP_/$GROUP/" config.yml' |
| 105 | + |
| 106 | +# Clone FlameGraph |
| 107 | +RUN cd /opt && git clone https://github.com/brendangregg/FlameGraph |
| 108 | + |
| 109 | +# Switch to developer user |
| 110 | +USER $USER:$GROUP |
| 111 | + |
| 112 | +ENV USER_WS=/ws |
| 113 | +WORKDIR $USER_WS |
| 114 | + |
| 115 | +# Colcon mixins and workspace setup |
| 116 | +RUN colcon mixin add default https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml \ |
| 117 | + && colcon mixin update default |
| 118 | +COPY --chown=$USER:$GROUP docker/files/colcon_defaults.yaml /home/$USER/.colcon/defaults.yaml |
| 119 | + |
| 120 | +RUN mkdir -p /home/$USER/.ccache $USER_WS/src |
| 121 | + |
| 122 | +# Copy only minimal files from the cache stage for rosdep install |
| 123 | +COPY --from=cacher --chown=$USER:$GROUP /tmp/ws/ $USER_WS/ |
| 124 | + |
| 125 | +# Back to root to install dependencies |
| 126 | +USER root |
| 127 | + |
| 128 | +ENV PIP_BREAK_SYSTEM_PACKAGES=1 |
| 129 | + |
| 130 | +RUN apt-get update \ |
| 131 | + && apt-get -y dist-upgrade \ |
| 132 | + && . /opt/ros/lyrical/setup.sh \ |
| 133 | + && rosdep update \ |
| 134 | + && rosdep install -i -y --from-path src --skip-keys 'slam_toolbox' \ |
| 135 | + && rosdep install -i -y --from-path src -t doc \ |
| 136 | + && rm -rf /var/lib/apt/lists/* |
| 137 | + |
| 138 | +# Final source copy |
| 139 | +USER $USER:$GROUP |
| 140 | +COPY --from=cacher --chown=$USER:$GROUP /ws/ $USER_WS/ |
| 141 | + |
| 142 | +ENV WITHIN_DEV=1 |
| 143 | +ENV SHELL=/bin/bash |
| 144 | + |
| 145 | +ENTRYPOINT ["fixuid", "-q", "/ros_entrypoint.sh", "/bin/bash"] |
0 commit comments