Skip to content

Commit 93fb7fb

Browse files
authored
Github actions docker build cache (#15)
1 parent ee18d7a commit 93fb7fb

1 file changed

Lines changed: 29 additions & 14 deletions

File tree

.github/workflows/docker-multi-platform.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,31 @@ env:
1212
IMAGE_VERSION: ${{ github.ref_name }}
1313

1414
jobs:
15+
set-matrix:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
matrix: ${{ steps.set-matrix.outputs.matrix }}
19+
steps:
20+
# Only run the arm64 (mac m1) build on tagged releases, since it takes so long to run
21+
- id: set-matrix
22+
run: |
23+
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
24+
echo 'matrix=["linux/amd64","linux/arm64"]' >> $GITHUB_OUTPUT
25+
elif [[ "${GITHUB_REF_TYPE}" == "branch" && "${GITHUB_REF_NAME}" == "master" ]]; then
26+
echo 'matrix=["linux/amd64"]' >> $GITHUB_OUTPUT
27+
else
28+
echo "ERROR: Unrecognized ref type or branch. Ref type: ${GITHUB_REF_TYPE}, Ref name: ${GITHUB_REF_NAME}" >&2
29+
exit 1
30+
fi
31+
1532
build:
33+
needs: set-matrix
1634
runs-on: ubuntu-latest
1735
permissions:
1836
packages: write
1937
strategy:
20-
fail-fast: false
2138
matrix:
22-
platform:
23-
- linux/amd64
24-
- linux/arm64
39+
platform: ${{ fromJson(needs.set-matrix.outputs.matrix) }}
2540
steps:
2641
- name: Prepare
2742
run: |
@@ -69,8 +84,8 @@ jobs:
6984
file: web-app/pontoon/Dockerfile
7085
platforms: ${{ matrix.platform }}
7186
labels: ${{ steps.meta.outputs.labels }}
72-
cache-from: type=gha
73-
cache-to: type=gha,mode=max
87+
cache-from: type=gha,scope=pontoon-frontend
88+
cache-to: type=gha,mode=max,scope=pontoon-frontend
7489
outputs: type=image,name=${{ env.REGISTRY }}/pontoon-frontend,push-by-digest=true,name-canonical=true,push=true
7590

7691
# Build and push api
@@ -82,8 +97,8 @@ jobs:
8297
file: api/Dockerfile
8398
platforms: ${{ matrix.platform }}
8499
labels: ${{ steps.meta.outputs.labels }}
85-
cache-from: type=gha
86-
cache-to: type=gha,mode=max
100+
cache-from: type=gha,scope=pontoon-api
101+
cache-to: type=gha,mode=max,scope=pontoon-api
87102
outputs: type=image,name=${{ env.REGISTRY }}/pontoon-api,push-by-digest=true,name-canonical=true,push=true
88103

89104
# Build and push worker
@@ -95,8 +110,8 @@ jobs:
95110
file: data-transfer/pontoon/Dockerfile
96111
platforms: ${{ matrix.platform }}
97112
labels: ${{ steps.meta.outputs.labels }}
98-
cache-from: type=gha
99-
cache-to: type=gha,mode=max
113+
cache-from: type=gha,scope=pontoon-worker
114+
cache-to: type=gha,mode=max,scope=pontoon-worker
100115
outputs: type=image,name=${{ env.REGISTRY }}/pontoon-worker,push-by-digest=true,name-canonical=true,push=true
101116

102117
# Build and push beat
@@ -108,8 +123,8 @@ jobs:
108123
file: data-transfer/pontoon/Dockerfile
109124
platforms: ${{ matrix.platform }}
110125
labels: ${{ steps.meta.outputs.labels }}
111-
cache-from: type=gha
112-
cache-to: type=gha,mode=max
126+
cache-from: type=gha,scope=pontoon-beat
127+
cache-to: type=gha,mode=max,scope=pontoon-beat
113128
outputs: type=image,name=${{ env.REGISTRY }}/pontoon-beat,push-by-digest=true,name-canonical=true,push=true
114129

115130
# Build and push unified image
@@ -121,8 +136,8 @@ jobs:
121136
file: Dockerfile
122137
platforms: ${{ matrix.platform }}
123138
labels: ${{ steps.meta.outputs.labels }}
124-
cache-from: type=gha
125-
cache-to: type=gha,mode=max
139+
cache-from: type=gha,scope=pontoon-unified
140+
cache-to: type=gha,mode=max,scope=pontoon-unified
126141
outputs: type=image,name=${{ env.REGISTRY }}/pontoon-unified,push-by-digest=true,name-canonical=true,push=true
127142
build-args: |
128143
API_IMAGE=${{ env.REGISTRY }}/pontoon-api@${{ steps.build-api.outputs.digest }}

0 commit comments

Comments
 (0)