Skip to content

Commit

Permalink
Use GitHub Actions gha cache for Docker builds
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Seigner <[email protected]>
  • Loading branch information
siggy committed Nov 12, 2023
1 parent 4018b2f commit 1c8dc21
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
15 changes: 2 additions & 13 deletions .github/actions/docker-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@ inputs:
runs:
using: composite
steps:
- name: Configure cache
shell: bash
run: echo "DOCKER_BUILDKIT_CACHE=${{ runner.temp }}/.buildx-cache" >> $GITHUB_ENV
- uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: ${{ env.DOCKER_BUILDKIT_CACHE }}
key: ${{ runner.os }}-buildx-${{ inputs.component }}-${{ inputs.tag }}
restore-keys: ${{ runner.os }}-buildx-${{ inputs.component }}-

# populate ACTIONS_CACHE_URL, ACTIONS_RUNTIME_TOKEN
- uses: crazy-max/ghaction-github-runtime@b3a9207c0e1ef41f4cf215303c976869d0c2c1c4
- uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3
- uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226
- name: Run bin/docker-build-${{ inputs.component }}
Expand All @@ -62,10 +55,6 @@ runs:
echo "${image_digest}"
echo "DIGEST=${{ inputs.docker-registry }}/${{ inputs.component }}@${image_digest}" >> "$GITHUB_OUTPUT"
# Delete older docker images to prevent cache bloat.
- run: bin/docker-cache-prune
shell: bash

outputs:
image:
description: The image that was built
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- '!.devcontainer/**'
- rust-toolchain.toml
- bin/rust-toolchain-version
- bin/_docker.sh

permissions:
contents: read
Expand Down Expand Up @@ -391,4 +392,3 @@ jobs:
just linkerd-tag='${{ needs.tag.outputs.tag }}' \
k3d-k8s='${{ matrix.k8s }}' \
mc-test-run
5 changes: 5 additions & 0 deletions bin/_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export DOCKER_REGISTRY=${DOCKER_REGISTRY:-cr.l5d.io/linkerd}
# buildx cache directory
export DOCKER_BUILDKIT_CACHE=${DOCKER_BUILDKIT_CACHE:-}

# populated in GitHub Actions
export ACTIONS_CACHE_URL=${ACTIONS_CACHE_URL:-}

export DOCKER_TARGET=${DOCKER_TARGET:-$(os)}

# When set together with DOCKER_TARGET=multi-arch, it will push the multi-arch images to the registry
Expand Down Expand Up @@ -69,6 +72,8 @@ docker_build() {

if [ "$DOCKER_BUILDKIT_CACHE" ]; then
cache_params="--cache-from type=local,src=${DOCKER_BUILDKIT_CACHE} --cache-to type=local,dest=${DOCKER_BUILDKIT_CACHE},mode=max"
elif [ "$ACTIONS_CACHE_URL" ]; then
cache_params="--cache-from type=gha,scope=$name-$DOCKER_TARGET --cache-to type=gha,scope=$name-$DOCKER_TARGET,mode=max"
fi

output_params="--load"
Expand Down

0 comments on commit 1c8dc21

Please sign in to comment.