Skip to content

Commit f2881a2

Browse files
committed
Use GHA to cache Docker builds
1 parent 78b47a3 commit f2881a2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

.github/workflows/ci.yaml

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
- '[2-9][0-9].[0-1][0-9].?[0-3]?[0-9]?'
1111

1212
env:
13-
IMAGE_NAME: erhhung/al2023-devops
1413
IMAGE_LABELS: |
1514
org.opencontainers.image.authors=Erhhung Yuan <[email protected]>
1615
@@ -125,8 +124,8 @@ jobs:
125124
uses: docker/metadata-action@v5
126125
with:
127126
images: |
128-
docker.io/${{ env.IMAGE_NAME }}
129-
ghcr.io/${{ env.IMAGE_NAME }}
127+
docker.io/${{ github.repository }}
128+
ghcr.io/${{ github.repository }}
130129
labels: ${{ env.IMAGE_LABELS }}
131130

132131
# https://github.com/aws-actions/configure-aws-credentials
@@ -173,7 +172,9 @@ jobs:
173172
platforms: ${{ matrix.platform }}
174173
tags: ${{ steps.metadata.outputs.tags }}
175174
labels: ${{ steps.metadata.outputs.labels }}
176-
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
175+
cache-from: type=gha,scope=${{ github.repository }}-${{ github.ref_name }}-${{ matrix.platform }}
176+
cache-to: type=gha,scope=${{ github.repository }}-${{ github.ref_name }}-${{ matrix.platform }}
177+
outputs: type=image,name=${{ github.repository }},push-by-digest=true,name-canonical=true,push=true
177178

178179
# create 0-byte file named /tmp/digests/<digest>
179180
- name: Export Digest
@@ -223,8 +224,8 @@ jobs:
223224
uses: docker/metadata-action@v5
224225
with:
225226
images: |
226-
docker.io/${{ env.IMAGE_NAME }}
227-
ghcr.io/${{ env.IMAGE_NAME }}
227+
docker.io/${{ github.repository }}
228+
ghcr.io/${{ github.repository }}
228229
labels: ${{ env.IMAGE_LABELS }}
229230

230231
# https://github.com/docker/login-action
@@ -250,14 +251,14 @@ jobs:
250251
working-directory: /tmp/digests
251252
run: |
252253
tags=($(jq -cr '[.tags[] | "-t \(.)"] | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON"))
253-
images=($(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *))
254+
images=($(printf '${{ github.repository }}@sha256:%s ' *))
254255
docker buildx imagetools create "${tags[@]}" "${images[@]}"
255256
256257
# confirm merged image manifests
257258
- name: Inspect Image
258259
id: inspect
259260
run: |
260-
tag="${{ env.IMAGE_NAME }}:$DOCKER_METADATA_OUTPUT_VERSION"
261+
tag="${{ github.repository }}:$DOCKER_METADATA_OUTPUT_VERSION"
261262
docker buildx imagetools inspect $tag
262263
263264
terminate-runner:

0 commit comments

Comments
 (0)