From 45c3a785a7af5792f24dae5b9a442b623f77bc07 Mon Sep 17 00:00:00 2001 From: Yutaka Kondo Date: Tue, 16 Jul 2024 21:06:24 +0900 Subject: [PATCH] feat(docker,ci): split prebuilt stage into autoware-core and autoware-universe stages (#4961) * add autoware-core stage Signed-off-by: Yutaka Kondo * rename autoware-universe Signed-off-by: Yutaka Kondo * chage copy order Signed-off-by: Yutaka Kondo * run on pr Signed-off-by: Yutaka Kondo * remove --from Signed-off-by: Yutaka Kondo * fix copy Signed-off-by: Yutaka Kondo * update bake Signed-off-by: Yutaka Kondo * revert pr Signed-off-by: Yutaka Kondo * rename to rosdep-depend Signed-off-by: Yutaka Kondo * alphabet order Signed-off-by: Yutaka Kondo --------- Signed-off-by: Yutaka Kondo --- .../actions/docker-build-and-push/action.yaml | 25 +++++-- docker/Dockerfile | 72 ++++++++++++++----- docker/docker-bake.hcl | 17 +++-- 3 files changed, 85 insertions(+), 29 deletions(-) diff --git a/.github/actions/docker-build-and-push/action.yaml b/.github/actions/docker-build-and-push/action.yaml index 15f12d59759..aae6a9747f2 100644 --- a/.github/actions/docker-build-and-push/action.yaml +++ b/.github/actions/docker-build-and-push/action.yaml @@ -109,16 +109,27 @@ runs: latest=false suffix=-base - - name: Docker meta for prebuilt - id: meta-prebuilt + - name: Docker meta for autoware-core + id: meta-autoware-core uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }} tags: ${{ steps.set-docker-tags.outputs.tags }} - bake-target: docker-metadata-action-prebuilt + bake-target: docker-metadata-action-autoware-core flavor: | latest=false - suffix=-prebuilt${{ inputs.tag-suffix }} + suffix=-autoware-core${{ inputs.tag-suffix }} + + - name: Docker meta for autoware-universe + id: meta-autoware-universe + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.actor }}/${{ inputs.bake-target }} + tags: ${{ steps.set-docker-tags.outputs.tags }} + bake-target: docker-metadata-action-autoware-universe + flavor: | + latest=false + suffix=-autoware-universe${{ inputs.tag-suffix }} - name: Docker meta for devel id: meta-devel @@ -161,7 +172,8 @@ runs: files: | docker/docker-bake.hcl ${{ steps.meta-base.outputs.bake-file }} - ${{ steps.meta-prebuilt.outputs.bake-file }} + ${{ steps.meta-autoware-core.outputs.bake-file }} + ${{ steps.meta-autoware-universe.outputs.bake-file }} ${{ steps.meta-devel.outputs.bake-file }} ${{ steps.meta-runtime.outputs.bake-file }} provenance: false @@ -176,7 +188,8 @@ runs: files: | docker/docker-bake.hcl ${{ steps.meta-base.outputs.bake-file }} - ${{ steps.meta-prebuilt.outputs.bake-file }} + ${{ steps.meta-autoware-core.outputs.bake-file }} + ${{ steps.meta-autoware-universe.outputs.bake-file }} ${{ steps.meta-devel.outputs.bake-file }} ${{ steps.meta-runtime.outputs.bake-file }} provenance: false diff --git a/docker/Dockerfile b/docker/Dockerfile index cc2534c48c0..a1792c6efff 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -34,11 +34,10 @@ RUN --mount=type=ssh \ # Create entrypoint CMD ["/bin/bash"] -FROM $BASE_IMAGE as src-imported +FROM $BASE_IMAGE as rosdep-depend 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/ WORKDIR /autoware @@ -52,17 +51,28 @@ RUN --mount=type=ssh \ && pip uninstall -y ansible ansible-core \ && apt-get autoremove -y && rm -rf "$HOME"/.cache -# Copy repository files -COPY src /autoware/src - # Generate install package lists +COPY src/core /autoware/src/core RUN rosdep update && rosdep keys --ignore-src --from-paths src \ | xargs rosdep resolve --rosdistro ${ROS_DISTRO} \ | grep -v '^#' \ | sed 's/ \+/\n/g'\ | sort \ - > /rosdep-all-depend-packages.txt \ - && cat /rosdep-all-depend-packages.txt + > /rosdep-core-depend-packages.txt \ + && cat /rosdep-core-depend-packages.txt +COPY src/launcher /autoware/src/launcher +COPY src/param /autoware/src/param +COPY src/sensor_component /autoware/src/sensor_component +COPY src/sensor_kit /autoware/src/sensor_kit +COPY src/universe /autoware/src/universe +COPY src/vehicle /autoware/src/vehicle +RUN rosdep keys --ignore-src --from-paths src \ + | xargs rosdep resolve --rosdistro ${ROS_DISTRO} \ + | grep -v '^#' \ + | sed 's/ \+/\n/g'\ + | sort \ + > /rosdep-universe-depend-packages.txt \ + && cat /rosdep-universe-depend-packages.txt RUN rosdep keys --dependency-types=exec --ignore-src --from-paths src \ | xargs rosdep resolve --rosdistro ${ROS_DISTRO} \ | grep -v '^#' \ @@ -71,7 +81,7 @@ RUN rosdep keys --dependency-types=exec --ignore-src --from-paths src \ > /rosdep-exec-depend-packages.txt \ && cat /rosdep-exec-depend-packages.txt -FROM base as prebuilt +FROM base as autoware-core SHELL ["/bin/bash", "-o", "pipefail", "-c"] ARG ROS_DISTRO ARG SETUP_ARGS @@ -87,16 +97,15 @@ RUN --mount=type=ssh \ && apt-get autoremove -y && rm -rf "$HOME"/.cache # Install rosdep dependencies -COPY --from=src-imported /rosdep-all-depend-packages.txt /tmp/rosdep-all-depend-packages.txt +COPY --from=rosdep-depend /rosdep-core-depend-packages.txt /tmp/rosdep-core-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ apt-get update \ - && cat /tmp/rosdep-all-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ + && cat /tmp/rosdep-core-depend-packages.txt | xargs apt-get install -y --no-install-recommends \ && apt-get autoremove -y && rm -rf "$HOME"/.cache -# Build Autoware -COPY --from=src-imported /autoware/src /autoware/src +COPY src/core /autoware/src/core RUN --mount=type=cache,target=${CCACHE_DIR} \ source /opt/ros/"$ROS_DISTRO"/setup.bash \ && du -sh ${CCACHE_DIR} && ccache -s \ @@ -104,13 +113,41 @@ RUN --mount=type=cache,target=${CCACHE_DIR} \ " -Wno-dev" \ " --no-warn-unused-cli" \ --mixin release compile-commands ccache \ + && du -sh ${CCACHE_DIR} && ccache -s + +FROM autoware-core as autoware-universe +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +ARG ROS_DISTRO +ARG SETUP_ARGS +ENV CCACHE_DIR="/root/.ccache" + +# Install rosdep dependencies +COPY --from=rosdep-depend /rosdep-universe-depend-packages.txt /tmp/rosdep-universe-depend-packages.txt +# hadolint ignore=SC2002 +RUN --mount=type=ssh \ + 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 + +# Build Autoware +COPY src/launcher /autoware/src/launcher +COPY src/param /autoware/src/param +COPY src/sensor_component /autoware/src/sensor_component +COPY src/sensor_kit /autoware/src/sensor_kit +COPY src/universe /autoware/src/universe +COPY src/vehicle /autoware/src/vehicle +RUN --mount=type=cache,target=${CCACHE_DIR} \ + source /opt/ros/"$ROS_DISTRO"/setup.bash \ && du -sh ${CCACHE_DIR} && ccache -s \ - && find /autoware/install -type d -exec chmod 777 {} \; \ - && rm -rf /autoware/build /autoware/src + && colcon build --cmake-args \ + " -Wno-dev" \ + " --no-warn-unused-cli" \ + --mixin release compile-commands ccache \ + && du -sh ${CCACHE_DIR} && ccache -s CMD ["/bin/bash"] -FROM prebuilt as devel +FROM autoware-universe as devel SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install development tools and artifacts @@ -134,7 +171,7 @@ ARG LIB_DIR ARG SETUP_ARGS # Set up runtime environment and artifacts -COPY --from=src-imported /rosdep-exec-depend-packages.txt /tmp/rosdep-exec-depend-packages.txt +COPY --from=rosdep-depend /rosdep-exec-depend-packages.txt /tmp/rosdep-exec-depend-packages.txt # hadolint ignore=SC2002 RUN --mount=type=ssh \ --mount=type=cache,target=/var/cache/apt,sharing=locked \ @@ -153,8 +190,7 @@ RUN --mount=type=ssh \ /etc/apt/sources.list.d/docker.list /etc/apt/sources.list.d/nvidia-docker.list \ /usr/include /usr/share/doc /usr/lib/gcc /usr/lib/jvm /usr/lib/llvm* -# Copy prebuilt binaries -COPY --from=prebuilt /autoware/install/ /autoware/install/ +COPY --from=autoware-universe /autoware/install/ /autoware/install/ # Copy bash aliases COPY docker/etc/.bash_aliases /root/.bash_aliases diff --git a/docker/docker-bake.hcl b/docker/docker-bake.hcl index 95aa124fb4b..9e3fb6536a7 100644 --- a/docker/docker-bake.hcl +++ b/docker/docker-bake.hcl @@ -1,10 +1,11 @@ group "default" { - targets = ["base", "prebuilt", "devel", "runtime"] + targets = ["base", "autoware-core", "autoware-universe", "devel", "runtime"] } // For docker/metadata-action target "docker-metadata-action-base" {} -target "docker-metadata-action-prebuilt" {} +target "docker-metadata-action-autoware-core" {} +target "docker-metadata-action-autoware-universe" {} target "docker-metadata-action-devel" {} target "docker-metadata-action-runtime" {} @@ -14,10 +15,16 @@ target "base" { target = "base" } -target "prebuilt" { - inherits = ["docker-metadata-action-prebuilt"] +target "autoware-core" { + inherits = ["docker-metadata-action-autoware-core"] dockerfile = "docker/Dockerfile" - target = "prebuilt" + target = "autoware-core" +} + +target "autoware-universe" { + inherits = ["docker-metadata-action-autoware-universe"] + dockerfile = "docker/Dockerfile" + target = "autoware-universe" } target "devel" {