Skip to content

Commit

Permalink
chore(ci): Docker base image layers caching
Browse files Browse the repository at this point in the history
- Cache base image layers only
- Cache for verify job only
- Do not cache for publish job since:
  - most of the work is cross compiling
  - go.mod often change between publish jobs
  - prevent bugs introduced due to the cache (unlikely)
  • Loading branch information
adamus1red authored and qdm12 committed Jun 17, 2023
1 parent 336bf05 commit b813db9
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,48 @@ jobs:
locale: "US"
level: error

- uses: docker/setup-buildx-action@v2

- uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and cache base image layers
uses: docker/build-push-action@v4
with:
target: base
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Linting
run: docker build --target lint .
uses: docker/build-push-action@v4
with:
target: lint
cache-from: type=local,src=/tmp/.buildx-cache

- name: Mocks check
run: docker build --target mocks .
uses: docker/build-push-action@v4
with:
target: mocks
cache-from: type=local,src=/tmp/.buildx-cache

- name: Build test image
run: docker build --target test -t test-container .
uses: docker/build-push-action@v4
with:
target: tests
tags: test-container
cache-from: type=local,src=/tmp/.buildx-cache

- name: Run tests in test container
run: |
Expand All @@ -61,7 +95,12 @@ jobs:
test-container
- name: Build final image
run: docker build -t final-image .
uses: docker/build-push-action@v4
with:
target: tests
tags: final-image
push: false
cache-from: type=local,src=/tmp/.buildx-cache

codeql:
runs-on: ubuntu-latest
Expand Down

0 comments on commit b813db9

Please sign in to comment.