From cc26a02f461f2cceefa718f0bca666deff38cb41 Mon Sep 17 00:00:00 2001 From: Yutaka Kondo Date: Thu, 11 Jul 2024 17:19:33 +0900 Subject: [PATCH 1/5] feat(docker,ci): cache apt archives to GitHub Actions cache (#4971) --- .../actions/docker-build-and-push/action.yaml | 23 +++++++-- .github/actions/docker-build/action.yaml | 51 +++++++++++++++---- docker/Dockerfile | 35 +++++++++---- 3 files changed, 86 insertions(+), 23 deletions(-) diff --git a/.github/actions/docker-build-and-push/action.yaml b/.github/actions/docker-build-and-push/action.yaml index 25b482bce2b..235b5e134fd 100644 --- a/.github/actions/docker-build-and-push/action.yaml +++ b/.github/actions/docker-build-and-push/action.yaml @@ -44,22 +44,37 @@ runs: - name: Setup Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Restore cache + - name: Restore ccache uses: actions/cache/restore@v4 with: path: | root-ccache key: cache-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('src/**/*.cpp') }} restore-keys: | - cache-${{ inputs.platform }}-${{ inputs.name }}- - cache-${{ inputs.platform }}- + ccache-${{ inputs.platform }}-${{ inputs.name }}- + ccache-${{ inputs.platform }}- + cache-${{ inputs.platform }}-${{ inputs.name }}- # TODO(youtalk): Remove obsolete cache key + cache-${{ inputs.platform }}- # TODO(youtalk): Remove obsolete cache key + + - name: Restore apt-get + uses: actions/cache/restore@v4 + with: + path: | + var-cache-apt + var-lib-apt + key: apt-get-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('src/**/package.xml') }} + restore-keys: | + apt-get-${{ inputs.platform }}-${{ inputs.name }}- + apt-get-${{ inputs.platform }}- - name: Inject cache into docker uses: reproducible-containers/buildkit-cache-dance@v3.1.2 with: cache-map: | { - "root-ccache": "/root/.ccache" + "root-ccache": "/root/.ccache", + "var-cache-apt": "/var/cache/apt", + "var-lib-apt": "/var/lib/apt" } skip-extraction: true diff --git a/.github/actions/docker-build/action.yaml b/.github/actions/docker-build/action.yaml index 7b36ab426a9..ba369946981 100644 --- a/.github/actions/docker-build/action.yaml +++ b/.github/actions/docker-build/action.yaml @@ -34,37 +34,68 @@ runs: vcs import src < autoware.repos shell: bash - - name: Cache + - name: Cache ccache uses: actions/cache@v4 if: ${{ inputs.name == 'no-cuda' }} - id: cache + id: cache-ccahce with: path: | root-ccache key: cache-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('src/**/*.cpp') }} restore-keys: | - cache-${{ inputs.platform }}-${{ inputs.name }}- - cache-${{ inputs.platform }}- + ccache-${{ inputs.platform }}-${{ inputs.name }}- + ccache-${{ inputs.platform }}- + cache-${{ inputs.platform }}-${{ inputs.name }}- # TODO(youtalk): Remove obsolete cache key + cache-${{ inputs.platform }}- # TODO(youtalk): Remove obsolete cache key - - name: Restore cache + - name: Cache apt-get + uses: actions/cache@v4 + if: ${{ inputs.name == 'no-cuda' }} + id: cache-apt-get + with: + path: | + var-cache-apt + var-lib-apt + key: apt-get-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('src/**/package.xml') }} + restore-keys: | + apt-get-${{ inputs.platform }}-${{ inputs.name }}- + apt-get-${{ inputs.platform }}- + + - name: Restore ccache uses: actions/cache/restore@v4 if: ${{ inputs.name != 'no-cuda' }} with: path: | root-ccache - key: cache-${{ matrix.platform }}-${{ matrix.name }}-${{ hashFiles('src/**/*.cpp') }} + key: ccache-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('src/**/*.cpp') }} + restore-keys: | + ccache-${{ inputs.platform }}-${{ inputs.name }}- + ccache-${{ inputs.platform }}- + cache-${{ inputs.platform }}-${{ inputs.name }}- # TODO(youtalk): Remove obsolete cache key + cache-${{ inputs.platform }}- # TODO(youtalk): Remove obsolete cache key + + - name: Restore apt-get + uses: actions/cache/restore@v4 + if: ${{ inputs.name != 'no-cuda' }} + with: + path: | + var-cache-apt + var-lib-apt + key: apt-get-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('src/**/package.xml') }} restore-keys: | - cache-${{ matrix.platform }}-${{ matrix.name }}- - cache-${{ matrix.platform }}- + apt-get-${{ inputs.platform }}-${{ inputs.name }}- + apt-get-${{ inputs.platform }}- - name: Inject cache into docker uses: reproducible-containers/buildkit-cache-dance@v3.1.2 with: cache-map: | { - "root-ccache": "/root/.ccache" + "root-ccache": "/root/.ccache", + "var-cache-apt": "/var/cache/apt", + "var-lib-apt": "/var/lib/apt" } - skip-extraction: ${{ steps.cache.outputs.cache-hit }} + skip-extraction: ${{ steps.cache-ccache.outputs.cache-hit && steps.cache-apt-get.outputs.cache-hit }} - name: Login to GitHub Container Registry uses: docker/login-action@v3 diff --git a/docker/Dockerfile b/docker/Dockerfile index 646a894f711..cc2534c48c0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,10 +6,14 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] ARG ROS_DISTRO # Install apt packages and add GitHub to known hosts for private repositories -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ +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 +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ gosu \ ssh \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache \ + && apt-get autoremove -y && rm -rf "$HOME"/.cache \ && mkdir -p ~/.ssh \ && ssh-keyscan github.com >> ~/.ssh/known_hosts @@ -20,9 +24,11 @@ WORKDIR /autoware # Set up base environment RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ ./setup-dev-env.sh -y --module base --runtime openadkit \ && pip uninstall -y ansible ansible-core \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache \ + && apt-get autoremove -y && rm -rf "$HOME"/.cache \ && echo "source /opt/ros/${ROS_DISTRO}/setup.bash" > /etc/bash.bashrc # Create entrypoint @@ -37,10 +43,14 @@ COPY setup-dev-env.sh ansible-galaxy-requirements.yaml amd64.env arm64.env /auto COPY ansible/ /autoware/ansible/ WORKDIR /autoware +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 RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ ./setup-dev-env.sh -y rosdep \ && pip uninstall -y ansible ansible-core \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && apt-get autoremove -y && rm -rf "$HOME"/.cache # Copy repository files COPY src /autoware/src @@ -70,17 +80,20 @@ ENV CCACHE_DIR="/root/.ccache" # cspell: ignore libcu libnv # Set up development environment RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ ./setup-dev-env.sh -y --module all ${SETUP_ARGS} --no-cuda-drivers openadkit \ && pip uninstall -y ansible ansible-core \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && 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 # hadolint ignore=SC2002 -RUN --mount=type=ssh \ +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 \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && apt-get autoremove -y && rm -rf "$HOME"/.cache # Build Autoware COPY --from=src-imported /autoware/src /autoware/src @@ -102,9 +115,11 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install development tools and artifacts RUN --mount=type=ssh \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ ./setup-dev-env.sh -y --module dev-tools --download-artifacts openadkit \ && pip uninstall -y ansible ansible-core \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache + && apt-get autoremove -y && rm -rf "$HOME"/.cache # Create entrypoint COPY docker/etc/ros_entrypoint.sh /ros_entrypoint.sh @@ -122,11 +137,13 @@ ARG SETUP_ARGS COPY --from=src-imported /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 \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ ./setup-dev-env.sh -y --module all ${SETUP_ARGS} --download-artifacts --no-cuda-drivers --runtime openadkit \ && pip uninstall -y ansible ansible-core \ && apt-get update \ && cat /tmp/rosdep-exec-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 \ + && apt-get autoremove -y && rm -rf "$HOME"/.cache \ && find /usr/lib/$LIB_DIR-linux-gnu -name "*.a" -type f -delete \ && find / -name "*.o" -type f -delete \ && find / -name "*.h" -type f -delete \ From 2a002156ab0d0c451341eee52eb3fdb5a72364c0 Mon Sep 17 00:00:00 2001 From: Yutaka Kondo Date: Thu, 11 Jul 2024 22:24:42 +0900 Subject: [PATCH 2/5] fix(ci): run `health-check` on schedule and workflow_dispatch events (#4974) run health-check on schedule and workflow_dispatch Signed-off-by: Yutaka Kondo --- .github/workflows/health-check.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/health-check.yaml b/.github/workflows/health-check.yaml index 0fbd76375a7..bed2d8f51a6 100644 --- a/.github/workflows/health-check.yaml +++ b/.github/workflows/health-check.yaml @@ -19,7 +19,9 @@ jobs: load-env: needs: label-check - if: ${{ needs.label-check.outputs.result == 'true' }} + if: ${{ needs.label-check.outputs.result == 'true' || + github.event_name == 'schedule' || + github.event_name == 'workflow_dispatch' }} uses: ./.github/workflows/load-env.yaml docker-build: From da239ad1ad1486c174fda46f01a1dd3045e75de6 Mon Sep 17 00:00:00 2001 From: Yutaka Kondo Date: Thu, 11 Jul 2024 22:38:35 +0900 Subject: [PATCH 3/5] update condition Signed-off-by: Yutaka Kondo --- .github/actions/docker-build/action.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/docker-build/action.yaml b/.github/actions/docker-build/action.yaml index ba369946981..9d8d7672bdd 100644 --- a/.github/actions/docker-build/action.yaml +++ b/.github/actions/docker-build/action.yaml @@ -36,7 +36,7 @@ runs: - name: Cache ccache uses: actions/cache@v4 - if: ${{ inputs.name == 'no-cuda' }} + if: ${{ inputs.name == 'no-cuda' && github.ref == 'refs/heads/main' }} id: cache-ccahce with: path: | @@ -50,7 +50,7 @@ runs: - name: Cache apt-get uses: actions/cache@v4 - if: ${{ inputs.name == 'no-cuda' }} + if: ${{ inputs.name == 'no-cuda' && github.ref == 'refs/heads/main' }} id: cache-apt-get with: path: | @@ -63,7 +63,7 @@ runs: - name: Restore ccache uses: actions/cache/restore@v4 - if: ${{ inputs.name != 'no-cuda' }} + if: ${{ inputs.name != 'no-cuda' || github.ref != 'refs/heads/main' }} with: path: | root-ccache @@ -76,7 +76,7 @@ runs: - name: Restore apt-get uses: actions/cache/restore@v4 - if: ${{ inputs.name != 'no-cuda' }} + if: ${{ inputs.name != 'no-cuda' || github.ref != 'refs/heads/main' }} with: path: | var-cache-apt From f3a072bb9163e058d0862089a6837a9a49fc419f Mon Sep 17 00:00:00 2001 From: Yutaka Kondo Date: Fri, 12 Jul 2024 06:51:48 +0900 Subject: [PATCH 4/5] fix ccache key Signed-off-by: Yutaka Kondo --- .github/actions/docker-build/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/docker-build/action.yaml b/.github/actions/docker-build/action.yaml index ba369946981..966a9bbe879 100644 --- a/.github/actions/docker-build/action.yaml +++ b/.github/actions/docker-build/action.yaml @@ -41,7 +41,7 @@ runs: with: path: | root-ccache - key: cache-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('src/**/*.cpp') }} + key: ccache-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('src/**/*.cpp') }} restore-keys: | ccache-${{ inputs.platform }}-${{ inputs.name }}- ccache-${{ inputs.platform }}- From fb22410f1e9d0eaa1f477a56e44faa660bf6fc61 Mon Sep 17 00:00:00 2001 From: Yutaka Kondo Date: Fri, 12 Jul 2024 07:04:52 +0900 Subject: [PATCH 5/5] move todo comments Signed-off-by: Yutaka Kondo --- .github/actions/docker-build-and-push/action.yaml | 5 +++-- .github/actions/docker-build/action.yaml | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/actions/docker-build-and-push/action.yaml b/.github/actions/docker-build-and-push/action.yaml index 235b5e134fd..15f12d59759 100644 --- a/.github/actions/docker-build-and-push/action.yaml +++ b/.github/actions/docker-build-and-push/action.yaml @@ -44,6 +44,7 @@ runs: - name: Setup Docker Buildx uses: docker/setup-buildx-action@v3 + # TODO(youtalk): Remove obsolete "cache-" restore-keys - name: Restore ccache uses: actions/cache/restore@v4 with: @@ -53,8 +54,8 @@ runs: restore-keys: | ccache-${{ inputs.platform }}-${{ inputs.name }}- ccache-${{ inputs.platform }}- - cache-${{ inputs.platform }}-${{ inputs.name }}- # TODO(youtalk): Remove obsolete cache key - cache-${{ inputs.platform }}- # TODO(youtalk): Remove obsolete cache key + cache-${{ inputs.platform }}-${{ inputs.name }}- + cache-${{ inputs.platform }}- - name: Restore apt-get uses: actions/cache/restore@v4 diff --git a/.github/actions/docker-build/action.yaml b/.github/actions/docker-build/action.yaml index 966a9bbe879..2f0849fb0ce 100644 --- a/.github/actions/docker-build/action.yaml +++ b/.github/actions/docker-build/action.yaml @@ -34,6 +34,7 @@ runs: vcs import src < autoware.repos shell: bash + # TODO(youtalk): Remove obsolete "cache-" restore-keys - name: Cache ccache uses: actions/cache@v4 if: ${{ inputs.name == 'no-cuda' }} @@ -45,8 +46,8 @@ runs: restore-keys: | ccache-${{ inputs.platform }}-${{ inputs.name }}- ccache-${{ inputs.platform }}- - cache-${{ inputs.platform }}-${{ inputs.name }}- # TODO(youtalk): Remove obsolete cache key - cache-${{ inputs.platform }}- # TODO(youtalk): Remove obsolete cache key + cache-${{ inputs.platform }}-${{ inputs.name }}- + cache-${{ inputs.platform }}- - name: Cache apt-get uses: actions/cache@v4 @@ -61,6 +62,7 @@ runs: apt-get-${{ inputs.platform }}-${{ inputs.name }}- apt-get-${{ inputs.platform }}- + # TODO(youtalk): Remove obsolete "cache-" restore-keys - name: Restore ccache uses: actions/cache/restore@v4 if: ${{ inputs.name != 'no-cuda' }} @@ -71,8 +73,8 @@ runs: restore-keys: | ccache-${{ inputs.platform }}-${{ inputs.name }}- ccache-${{ inputs.platform }}- - cache-${{ inputs.platform }}-${{ inputs.name }}- # TODO(youtalk): Remove obsolete cache key - cache-${{ inputs.platform }}- # TODO(youtalk): Remove obsolete cache key + cache-${{ inputs.platform }}-${{ inputs.name }}- + cache-${{ inputs.platform }}- - name: Restore apt-get uses: actions/cache/restore@v4