Skip to content

Commit 2973c56

Browse files
adamus1redqdm12
authored andcommitted
chore(ci): Docker base image layers caching
- 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)
1 parent 336bf05 commit 2973c56

1 file changed

Lines changed: 43 additions & 4 deletions

File tree

.github/workflows/build.yml

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,48 @@ jobs:
4444
locale: "US"
4545
level: error
4646

47+
- uses: docker/setup-buildx-action@v2
48+
49+
- uses: actions/cache@v2
50+
with:
51+
path: /tmp/.buildx-cache
52+
key: ${{ runner.os }}-buildx-${{ github.sha }}
53+
restore-keys: |
54+
${{ runner.os }}-buildx-
55+
56+
- name: Build and cache base image layers
57+
uses: docker/build-push-action@v4
58+
with:
59+
target: base
60+
cache-from: type=local,src=/tmp/.buildx-cache
61+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
62+
63+
# Temp fix
64+
# https://github.com/docker/build-push-action/issues/252
65+
# https://github.com/moby/buildkit/issues/1896
66+
- name: Move cache
67+
run: |
68+
rm -rf /tmp/.buildx-cache
69+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
70+
4771
- name: Linting
48-
run: docker build --target lint .
72+
uses: docker/build-push-action@v4
73+
with:
74+
target: lint
75+
cache-from: type=local,src=/tmp/.buildx-cache
4976

5077
- name: Mocks check
51-
run: docker build --target mocks .
78+
uses: docker/build-push-action@v4
79+
with:
80+
target: mocks
81+
cache-from: type=local,src=/tmp/.buildx-cache
5282

5383
- name: Build test image
54-
run: docker build --target test -t test-container .
84+
uses: docker/build-push-action@v4
85+
with:
86+
target: test
87+
tags: test-container
88+
cache-from: type=local,src=/tmp/.buildx-cache
5589

5690
- name: Run tests in test container
5791
run: |
@@ -61,7 +95,12 @@ jobs:
6195
test-container
6296
6397
- name: Build final image
64-
run: docker build -t final-image .
98+
uses: docker/build-push-action@v4
99+
with:
100+
target: tests
101+
tags: final-image
102+
push: false
103+
cache-from: type=local,src=/tmp/.buildx-cache
65104

66105
codeql:
67106
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)