diff --git a/docker/Dockerfile b/docker/Dockerfile index 5534205363..1bf5b246c4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -5,6 +5,15 @@ FROM $BASE_IMAGE AS base SHELL ["/bin/bash", "-o", "pipefail", "-c"] ARG ROS_DISTRO +# Copy files +COPY setup-dev-env.sh ansible-galaxy-requirements.yaml amd64.env arm64.env /autoware/ +COPY ansible/ /autoware/ansible/ +COPY docker/scripts/cleanup_apt.sh /autoware/cleanup_apt.sh +RUN chmod +x /autoware/cleanup_apt.sh +COPY docker/scripts/cleanup_system.sh /autoware/cleanup_system.sh +RUN chmod +x /autoware/cleanup_system.sh +WORKDIR /autoware + # Install apt packages and add GitHub to known hosts for private repositories RUN rm -f /etc/apt/apt.conf.d/docker-clean \ && echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache @@ -12,23 +21,16 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ gosu \ ssh \ - && apt-get autoremove -y && rm -rf "$HOME"/.cache \ + && /autoware/cleanup_apt.sh \ && mkdir -p ~/.ssh \ && ssh-keyscan github.com >> ~/.ssh/known_hosts -# Copy files -COPY setup-dev-env.sh ansible-galaxy-requirements.yaml amd64.env arm64.env /autoware/ -COPY ansible/ /autoware/ansible/ -COPY docker/scripts/cleanup_system.sh /autoware/cleanup_system.sh -RUN chmod +x /autoware/cleanup_system.sh -WORKDIR /autoware - # Set up base environment RUN --mount=type=ssh \ --mount=type=cache,target=/var/cache/apt,sharing=locked \ ./setup-dev-env.sh -y --module base --no-nvidia --no-cuda-drivers --runtime openadkit \ && pip uninstall -y ansible ansible-core \ - && apt-get autoremove -y && rm -rf "$HOME"/.cache \ + && /autoware/cleanup_apt.sh \ && echo "source /opt/ros/${ROS_DISTRO}/setup.bash" > /etc/bash.bashrc # Create entrypoint @@ -45,7 +47,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN --mount=type=ssh \ ./setup-dev-env.sh -y --module base --download-artifacts --no-cuda-drivers --runtime openadkit \ && pip uninstall -y ansible ansible-core \ - && apt-get autoremove -y && rm -rf "$HOME"/.cache + && /autoware/cleanup_apt.sh true # hadolint ignore=DL3006 FROM $BASE_IMAGE AS rosdep-depend @@ -54,6 +56,8 @@ ARG ROS_DISTRO COPY setup-dev-env.sh ansible-galaxy-requirements.yaml amd64.env arm64.env /autoware/ COPY ansible/ /autoware/ansible/ +COPY docker/scripts/cleanup_apt.sh /autoware/cleanup_apt.sh +RUN chmod +x /autoware/cleanup_apt.sh COPY docker/scripts/resolve_rosdep_keys.sh /autoware/resolve_rosdep_keys.sh RUN chmod +x /autoware/resolve_rosdep_keys.sh WORKDIR /autoware @@ -64,7 +68,7 @@ RUN --mount=type=ssh \ --mount=type=cache,target=/var/cache/apt,sharing=locked \ ./setup-dev-env.sh -y rosdep \ && pip uninstall -y ansible ansible-core \ - && apt-get autoremove -y && rm -rf "$HOME"/.cache + && /autoware/cleanup_apt.sh # Generate install package lists COPY src/core /autoware/src/core @@ -169,7 +173,7 @@ RUN --mount=type=ssh \ ./setup-dev-env.sh -y --module all --no-nvidia --no-cuda-drivers openadkit \ && ./setup-dev-env.sh -y --module dev-tools openadkit \ && pip uninstall -y ansible ansible-core \ - && apt-get autoremove -y && rm -rf "$HOME"/.cache + && /autoware/cleanup_apt.sh # Install rosdep dependencies COPY --from=rosdep-depend /rosdep-core-depend-packages.txt /tmp/rosdep-core-depend-packages.txt @@ -177,7 +181,7 @@ COPY --from=rosdep-depend /rosdep-core-depend-packages.txt /tmp/rosdep-core-depe RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update \ && cat /tmp/rosdep-core-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ - && apt-get autoremove -y && rm -rf "$HOME"/.cache + && /autoware/cleanup_apt.sh RUN --mount=type=cache,target=${CCACHE_DIR} \ --mount=type=bind,from=rosdep-depend,source=/autoware/src/core,target=/autoware/src/core \ @@ -196,9 +200,10 @@ ENV CCACHE_DIR="/root/.ccache" COPY --from=rosdep-depend /rosdep-universe-common-depend-packages.txt /tmp/rosdep-universe-common-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update \ && cat /tmp/rosdep-universe-common-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && /autoware/cleanup_apt.sh # hadolint ignore=SC1091 RUN --mount=type=cache,target=${CCACHE_DIR} \ @@ -219,7 +224,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN --mount=type=ssh \ ./setup-dev-env.sh -y --module all --no-cuda-drivers --runtime openadkit \ && pip uninstall -y ansible ansible-core \ - && apt-get autoremove -y && rm -rf "$HOME"/.cache + && /autoware/cleanup_apt.sh true ENTRYPOINT ["/ros_entrypoint.sh"] CMD ["/bin/bash"] @@ -233,9 +238,10 @@ ENV CCACHE_DIR="/root/.ccache" COPY --from=rosdep-universe-sensing-perception-depend /rosdep-universe-sensing-perception-depend-packages.txt /tmp/rosdep-universe-sensing-perception-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update \ && cat /tmp/rosdep-universe-sensing-perception-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && /autoware/cleanup_apt.sh # hadolint ignore=SC1091 RUN --mount=type=cache,target=${CCACHE_DIR} \ @@ -257,9 +263,10 @@ ENV CCACHE_DIR="/root/.ccache" COPY --from=rosdep-universe-sensing-perception-depend /rosdep-universe-sensing-perception-depend-packages.txt /tmp/rosdep-universe-sensing-perception-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update \ && cat /tmp/rosdep-universe-sensing-perception-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && /autoware/cleanup_apt.sh # hadolint ignore=SC1091 RUN --mount=type=cache,target=${CCACHE_DIR} \ @@ -293,9 +300,10 @@ ENV CCACHE_DIR="/root/.ccache" COPY --from=rosdep-universe-localization-mapping-depend /rosdep-universe-localization-mapping-depend-packages.txt /tmp/rosdep-universe-localization-mapping-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update \ && cat /tmp/rosdep-universe-localization-mapping-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && /autoware/cleanup_apt.sh # hadolint ignore=SC1091 RUN --mount=type=cache,target=${CCACHE_DIR} \ @@ -314,9 +322,10 @@ ENV CCACHE_DIR="/root/.ccache" COPY --from=rosdep-universe-planning-control-depend /rosdep-universe-planning-control-depend-packages.txt /tmp/rosdep-universe-planning-control-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update \ && cat /tmp/rosdep-universe-planning-control-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && /autoware/cleanup_apt.sh # hadolint ignore=SC1091 RUN --mount=type=cache,target=${CCACHE_DIR} \ @@ -343,9 +352,10 @@ ENV CCACHE_DIR="/root/.ccache" COPY --from=rosdep-universe-vehicle-system-depend /rosdep-universe-vehicle-system-depend-packages.txt /tmp/rosdep-universe-vehicle-system-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update \ && cat /tmp/rosdep-universe-vehicle-system-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && /autoware/cleanup_apt.sh # hadolint ignore=SC1091 RUN --mount=type=cache,target=${CCACHE_DIR} \ @@ -369,9 +379,10 @@ ENV CCACHE_DIR="/root/.ccache" COPY --from=rosdep-universe-depend /rosdep-universe-depend-packages.txt /tmp/rosdep-universe-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update \ && cat /tmp/rosdep-universe-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && /autoware/cleanup_apt.sh COPY --from=universe-sensing-perception-devel /opt/autoware /opt/autoware COPY --from=universe-localization-mapping-devel /opt/autoware /opt/autoware @@ -402,9 +413,10 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] COPY --from=rosdep-universe-depend /rosdep-universe-depend-packages.txt /tmp/rosdep-universe-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update \ && cat /tmp/rosdep-universe-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && /autoware/cleanup_apt.sh COPY --from=universe-sensing-perception-devel-cuda /opt/autoware /opt/autoware COPY --from=universe-devel /opt/autoware /opt/autoware diff --git a/docker/scripts/cleanup_apt.sh b/docker/scripts/cleanup_apt.sh new file mode 100755 index 0000000000..883df9ba8a --- /dev/null +++ b/docker/scripts/cleanup_apt.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +function cleanup() { + local remove_var_lib_apt_lists=false + apt-get autoremove -y && rm -rf "$HOME"/.cache + if "$remove_var_lib_apt_lists"; then + rm -rf /var/lib/apt/lists/* + fi +} + +cleanup "$@"