Skip to content

Commit

Permalink
feat(ci,docker): save RUN --mount=type=cache ccache on GitHub Actio…
Browse files Browse the repository at this point in the history
…ns cache (autowarefoundation#4854)

Signed-off-by: Yutaka Kondo <[email protected]>
  • Loading branch information
youtalk authored Jun 12, 2024
1 parent 443d364 commit 23a0f14
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 13 deletions.
13 changes: 5 additions & 8 deletions .github/actions/docker-build-and-push/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ inputs:
runs:
using: composite
steps:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Install jq and vcstool
run: |
sudo apt-get -y update
Expand Down Expand Up @@ -59,7 +56,7 @@ runs:

- name: Docker meta for prebuilt
id: meta-prebuilt
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }}
tags: ${{ steps.set-docker-tags.outputs.tags }}
Expand All @@ -70,7 +67,7 @@ runs:
- name: Docker meta for devel
id: meta-devel
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }}
tags: ${{ steps.set-docker-tags.outputs.tags }}
Expand All @@ -82,7 +79,7 @@ runs:
- name: Docker meta for runtime
if: ${{ github.event_name == 'workflow_dispatch' }} || ${{ (github.event_name == 'push' && github.ref_type == 'tag') }}
id: meta-runtime
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }}
tags: ${{ steps.set-docker-tags.outputs.tags }}
Expand All @@ -101,7 +98,7 @@ runs:

- name: Build and Push to GitHub Container Registry
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || ( github.event_name == 'workflow_dispatch' && github.event.inputs.artifacts-destination == 'registry') }}
uses: docker/bake-action@v3
uses: docker/bake-action@v4
with:
push: ${{ inputs.allow-push == 'true' }}
files: |
Expand All @@ -115,7 +112,7 @@ runs:
- name: Build only
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.artifacts-destination == 'tarball' }}
uses: docker/bake-action@v3
uses: docker/bake-action@v4
with:
push: false
files: |
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/build-main-self-hosted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set git config
uses: autowarefoundation/autoware-github-actions/set-git-config@v1
with:
Expand All @@ -54,6 +57,25 @@ jobs:
- name: Free disk space
uses: ./.github/actions/free-disk-space

- name: Cache
uses: actions/cache@v3
id: cache
with:
path: |
root-ccache
key: cache-${{ matrix.platform }}-${{ matrix.name }}-${{ hashFiles('autoware.repos') }}
restore-keys: |
cache-${{ matrix.platform }}-${{ matrix.name }}-
cache-${{ matrix.platform }}-
- name: inject cache into docker
uses: reproducible-containers/[email protected]
with:
cache-map: |
{
"root-ccache": "/root/.ccache"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}

- name: Build 'Autoware'
uses: ./.github/actions/docker-build-and-push
with:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/build-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set git config
uses: autowarefoundation/autoware-github-actions/set-git-config@v1
with:
Expand All @@ -49,6 +52,25 @@ jobs:
- name: Free disk space
uses: ./.github/actions/free-disk-space

- name: Cache
uses: actions/cache@v3
id: cache
with:
path: |
root-ccache
key: cache-${{ matrix.platform }}-${{ matrix.name }}-${{ hashFiles('autoware.repos') }}
restore-keys: |
cache-${{ matrix.platform }}-${{ matrix.name }}-
cache-${{ matrix.platform }}-
- name: inject cache into docker
uses: reproducible-containers/[email protected]
with:
cache-map: |
{
"root-ccache": "/root/.ccache"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}

- name: Build 'Autoware'
uses: ./.github/actions/docker-build-and-push
with:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/docker-build-and-push-main-self-hosted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set git config
uses: autowarefoundation/autoware-github-actions/set-git-config@v1
with:
Expand All @@ -66,6 +69,25 @@ jobs:
- name: Free disk space
uses: ./.github/actions/free-disk-space

- name: Cache
uses: actions/cache@v3
id: cache
with:
path: |
root-ccache
key: cache-${{ matrix.platform }}-${{ matrix.name }}-${{ hashFiles('autoware.repos') }}
restore-keys: |
cache-${{ matrix.platform }}-${{ matrix.name }}-
cache-${{ matrix.platform }}-
- name: inject cache into docker
uses: reproducible-containers/[email protected]
with:
cache-map: |
{
"root-ccache": "/root/.ccache"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}

- name: Build 'Autoware'
uses: ./.github/actions/docker-build-and-push
with:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/docker-build-and-push-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set git config
uses: autowarefoundation/autoware-github-actions/set-git-config@v1
with:
Expand All @@ -61,6 +64,25 @@ jobs:
- name: Free disk space
uses: ./.github/actions/free-disk-space

- name: Cache
uses: actions/cache@v3
id: cache
with:
path: |
root-ccache
key: cache-${{ matrix.platform }}-${{ matrix.name }}-${{ hashFiles('autoware.repos') }}
restore-keys: |
cache-${{ matrix.platform }}-${{ matrix.name }}-
cache-${{ matrix.platform }}-
- name: inject cache into docker
uses: reproducible-containers/[email protected]
with:
cache-map: |
{
"root-ccache": "/root/.ccache"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}

- name: Build 'Autoware'
uses: ./.github/actions/docker-build-and-push
with:
Expand Down
8 changes: 3 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO
ARG SETUP_ARGS
ENV CCACHE_DIR="/var/tmp/ccache"
ENV CC="/usr/lib/ccache/gcc"
ENV CXX="/usr/lib/ccache/g++"

# cspell: ignore libcu libnv
# Set up development environment
Expand All @@ -90,13 +88,13 @@ RUN --mount=type=ssh \
COPY --from=src-imported /autoware/src /autoware/src
RUN --mount=type=cache,target=${CCACHE_DIR} \
source /opt/ros/"$ROS_DISTRO"/setup.bash \
&& du -sh ${CCACHE_DIR} && ccache -s \
&& colcon build --cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
" -Wno-dev" \
" --no-warn-unused-cli" \
--mixin release compile-commands ccache \
&& du -sh ${CCACHE_DIR} && ccache -s \
&& find /autoware/install -type d -exec chmod 777 {} \; \
&& chmod -R 777 /var/tmp/ccache \
&& rm -rf /autoware/build /autoware/src

CMD ["/bin/bash"]
Expand Down

0 comments on commit 23a0f14

Please sign in to comment.