Skip to content

Commit

Permalink
Attempt to speed up PR image builds by sharing a cache
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
imjasonh committed Dec 17, 2021
1 parent 49f0154 commit a3f7bcd
Showing 1 changed file with 40 additions and 150 deletions.
190 changes: 40 additions & 150 deletions .github/workflows/pr_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,165 +7,55 @@ concurrency:
cancel-in-progress: true

jobs:
build-executor-slim:
build-images:
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
PLATFORMS: "linux/amd64,linux/arm64,linux/s390x,linux/ppc64le"
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_slim
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
tags: |
gcr.io/kaniko-project/executor:${{ env.GITHUB_SHA }}-slim
build-debug:
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

strategy:
fail-fast: false
matrix:
image:
- executor
- executor-debug
- executor-slim
- warmer

include:
- image: executor
dockerfile: ./deploy/Dockerfile
platforms: linux/amd64,linux/arm64
name: gcr.io/kaniko-project/executor:${{ github.sha }}

- image: executor-debug
dockerfile: ./deploy/Dockerfile_debug
platforms: linux/amd64,linux/arm64
name: gcr.io/kaniko-project/executor:${{ github.sha }}-debug

- image: executor-slim
dockerfile: ./deploy/Dockerfile_slim
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
name: gcr.io/kaniko-project/executor:${{ github.sha }}-slim

- image: warmer
dockerfile: ./deploy/Dockerfile_warmer
name: gcr.io/kaniko-project/warmer:${{ github.sha }}
platforms: linux/amd64,linux/arm64

- uses: docker/build-push-action@v2
with:
context: .
file: ./deploy/Dockerfile_debug
platforms: linux/amd64,linux/arm64
tags: |
gcr.io/kaniko-project/executor:${{ env.GITHUB_SHA }}-debug
build-warmer:
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\//}
- uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- uses: docker/setup-qemu-action@v1
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
with:
context: .
file: ./deploy/Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
gcr.io/kaniko-project/executor:${{ env.GITHUB_SHA }}
file: ${{ matrix.dockerfile }}
platforms: ${{ matrix.platforms }}
tags: ${{ matrix.name }}
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit a3f7bcd

Please sign in to comment.