Attempt to speed up PR image builds by sharing a cache (#1844)

docker/setup-buildx-action actually provides first-class support for
the GitHub Actions cache (though experimental). This should make builds
much faster. Previous configuration wasn't properly configuring caching,
as far as I can tell.

This also takes advantage of GitHub Actions matrix support to more
concisely express the build parameters then execute the same steps on
them, which makes it clearer that the builds are all fundamentally doing
the same thing.
This commit is contained in:
Jason Hall 2021-12-17 22:17:05 -05:00 committed by GitHub
parent c87f8efd07
commit 0fd1058782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 41 additions and 151 deletions

View File

@ -7,165 +7,55 @@ concurrency:
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
build-executor-slim: build-images:
env: env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
PLATFORMS: "linux/amd64,linux/arm64,linux/s390x,linux/ppc64le" PLATFORMS: "linux/amd64,linux/arm64,linux/s390x,linux/ppc64le"
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: strategy:
- name: Clone source code fail-fast: false
uses: actions/checkout@v2 matrix:
image:
- executor
- executor-debug
- executor-slim
- warmer
- name: Get the tags include:
id: vars - image: executor
run: echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//} dockerfile: ./deploy/Dockerfile
platforms: linux/amd64,linux/arm64
name: gcr.io/kaniko-project/executor:${{ github.sha }}
- name: Set up QEMU - image: executor-debug
uses: docker/setup-qemu-action@v1 dockerfile: ./deploy/Dockerfile_debug
with: platforms: linux/amd64,linux/arm64
platforms: ${{ env.PLATFORMS }} name: gcr.io/kaniko-project/executor:${{ github.sha }}-debug
- name: Cache Docker layers - image: executor-slim
uses: actions/cache@v2 dockerfile: ./deploy/Dockerfile_slim
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
- uses: docker/build-push-action@v2
with:
context: .
file: ./deploy/Dockerfile_slim
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
tags: | name: gcr.io/kaniko-project/executor:${{ github.sha }}-slim
gcr.io/kaniko-project/executor:${{ env.GITHUB_SHA }}-slim
- image: warmer
dockerfile: ./deploy/Dockerfile_warmer
name: gcr.io/kaniko-project/warmer:${{ github.sha }}
platforms: linux/amd64,linux/arm64
build-debug:
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
PLATFORMS: "linux/amd64,linux/arm64"
runs-on: ubuntu-latest
steps: steps:
- name: Clone source code - uses: actions/checkout@v2
uses: actions/checkout@v2
- name: Get the tags - uses: docker/setup-qemu-action@v1
id: vars
run: echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with: with:
platforms: ${{ env.PLATFORMS }} platforms: ${{ matrix.platforms }}
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
- uses: docker/setup-buildx-action@v1
- uses: docker/build-push-action@v2 - uses: docker/build-push-action@v2
with: with:
context: . context: .
file: ./deploy/Dockerfile_debug file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64 platforms: ${{ matrix.platforms }}
tags: | tags: ${{ matrix.name }}
gcr.io/kaniko-project/executor:${{ env.GITHUB_SHA }}-debug # https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
cache-from: type=gha
build-warmer: cache-to: type=gha,mode=max
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
PLATFORMS: "linux/amd64,linux/arm64"
runs-on: ubuntu-latest
steps:
- name: Clone source code
uses: actions/checkout@v2
- name: Get the tags
id: vars
run: echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: ${{ env.PLATFORMS }}
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
- uses: docker/build-push-action@v2
with:
context: .
file: ./deploy/Dockerfile_warmer
platforms: linux/amd64,linux/arm64
tags: |
gcr.io/kaniko-project/warmer:${{ env.GITHUB_SHA }}
build-executor:
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
PLATFORMS: "linux/amd64,linux/arm64"
runs-on: ubuntu-latest
steps:
- name: Clone source code
uses: actions/checkout@v2
- name: Get the tags
id: vars
run: echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: ${{ env.PLATFORMS }}
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
- uses: docker/build-push-action@v2
with:
context: .
file: ./deploy/Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
gcr.io/kaniko-project/executor:${{ env.GITHUB_SHA }}