Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): save cache on build-main workflows and only restore cache on docker-build-and-push-main workflows #4865

Merged
merged 10 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/actions/docker-build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: docker-build
description: ""

inputs:
name:
description: ""
required: true
platform:
description: ""
required: true
cache-tag-suffix:
description: ""
required: true
build-args:
description: ""
required: true

runs:
using: composite
steps:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Install vcstool
run: |
sudo apt-get -y update
sudo apt-get -y install python3-pip
pip install --no-cache-dir vcstool
shell: bash

- name: Run vcs import
run: |
mkdir src
vcs import src < autoware.repos
shell: bash

- name: Cache
uses: actions/cache@v3
id: cache
with:
path: |
root-ccache
key: cache-${{ inputs.platform }}-${{ inputs.name }}-${{ hashFiles('autoware.repos') }}
restore-keys: |
cache-${{ inputs.platform }}-${{ inputs.name }}-
cache-${{ inputs.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: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Run docker build
uses: docker/build-push-action@v5
with:
file: docker/Dockerfile
context: .
push: false
build-args: ${{ inputs.build-args }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ inputs.name }}-${{ inputs.platform }}-${{ inputs.cache-tag-suffix }}
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ inputs.name }}-${{ inputs.platform }}-${{ inputs.cache-tag-suffix }},mode=max
49 changes: 8 additions & 41 deletions .github/workflows/build-main-self-hosted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ on:
schedule:
- cron: 0 12 * * *
workflow_dispatch:
inputs:
artifacts-destination:
type: choice
description: Built images will be saved as tarball
options:
- tarball
default: tarball

jobs:
load-env:
Expand Down Expand Up @@ -46,9 +39,6 @@ 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 @@ -57,40 +47,17 @@ 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
uses: ./.github/actions/docker-build
with:
bake-target: autoware
name: ${{ matrix.name }}
platform: ${{ matrix.platform }}
cache-tag-suffix: main
build-args: |
*.platform=linux/${{ matrix.platform }}
*.args.ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }}
*.args.BASE_IMAGE=${{ needs.load-env.outputs[format('{0}', matrix.base_image_env)] }}
*.args.SETUP_ARGS=${{ matrix.setup-args }}
*.args.LIB_DIR=${{ matrix.lib_dir }}
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ matrix.name }}-${{ matrix.platform }}-main
*.cache-to=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ matrix.name }}-${{ matrix.platform }}-main,mode=max
tag-suffix: ${{ matrix.additional-tag-suffix }}-${{ matrix.platform }}
tag-prefix: ${{ needs.load-env.outputs.rosdistro }}
allow-push: false
ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }}
BASE_IMAGE=${{ needs.load-env.outputs[format('{0}', matrix.base_image_env)] }}
SETUP_ARGS=${{ matrix.setup-args }}
LIB_DIR=${{ matrix.lib_dir }}

- name: Show disk space
run: |
Expand Down
49 changes: 8 additions & 41 deletions .github/workflows/build-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ on:
schedule:
- cron: 0 12 * * *
workflow_dispatch:
inputs:
artifacts-destination:
type: choice
description: Built images will be saved as tarball
options:
- tarball
default: tarball

jobs:
load-env:
Expand Down Expand Up @@ -41,9 +34,6 @@ 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 @@ -52,40 +42,17 @@ 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
uses: ./.github/actions/docker-build
with:
bake-target: autoware
name: ${{ matrix.name }}
platform: ${{ matrix.platform }}
cache-tag-suffix: main
build-args: |
*.platform=linux/${{ matrix.platform }}
*.args.ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }}
*.args.BASE_IMAGE=${{ needs.load-env.outputs[format('{0}', matrix.base_image_env)] }}
*.args.SETUP_ARGS=${{ matrix.setup-args }}
*.args.LIB_DIR=${{ matrix.lib_dir }}
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ matrix.name }}-${{ matrix.platform }}-main
*.cache-to=type=registry,ref=ghcr.io/${{ github.repository }}-buildcache:${{ matrix.name }}-${{ matrix.platform }}-main,mode=max
tag-suffix: ${{ matrix.additional-tag-suffix }}-${{ matrix.platform }}
tag-prefix: ${{ needs.load-env.outputs.rosdistro }}
allow-push: false
ROS_DISTRO=${{ needs.load-env.outputs.rosdistro }}
BASE_IMAGE=${{ needs.load-env.outputs[format('{0}', matrix.base_image_env)] }}
SETUP_ARGS=${{ matrix.setup-args }}
LIB_DIR=${{ matrix.lib_dir }}

- name: Show disk space
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/docker-build-and-push-main-self-hosted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@ jobs:
- name: Free disk space
uses: ./.github/actions/free-disk-space

- name: Cache
uses: actions/cache@v3
id: cache
- name: Restore cache
uses: actions/cache/restore@v4
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

- name: Inject cache into docker
uses: reproducible-containers/[email protected]
with:
cache-map: |
{
"root-ccache": "/root/.ccache"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
skip-extraction: true

- name: Build 'Autoware'
uses: ./.github/actions/docker-build-and-push
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/docker-build-and-push-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ jobs:
- cuda
include:
- name: no-cuda
base_image_env: base_image
platform: amd64
base_image_env: base_image
lib_dir: x86_64
setup-args: --no-nvidia
additional-tag-suffix: ""
- name: cuda
base_image_env: base_image
platform: amd64
base_image_env: base_image
lib_dir: x86_64
additional-tag-suffix: -cuda
steps:
Expand All @@ -64,24 +64,24 @@ jobs:
- name: Free disk space
uses: ./.github/actions/free-disk-space

- name: Cache
uses: actions/cache@v3
id: cache
- name: Restore cache
uses: actions/cache/restore@v4
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

- name: Inject cache into docker
uses: reproducible-containers/[email protected]
with:
cache-map: |
{
"root-ccache": "/root/.ccache"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
skip-extraction: true

- name: Build 'Autoware'
uses: ./.github/actions/docker-build-and-push
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ FROM base as prebuilt
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG ROS_DISTRO
ARG SETUP_ARGS
ENV CCACHE_DIR="/var/tmp/ccache"
ENV CCACHE_DIR="/root/.ccache"

# cspell: ignore libcu libnv
# Set up development environment
Expand Down
Loading