Skip to content

Commit b921500

Browse files
authored
Merge branch 'main' into renovate/docker-metadata-action-5.x
2 parents 612f544 + 1696612 commit b921500

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ jobs:
3333
password: ${{ secrets.DOCKERHUB_PASSWORD }}
3434
platforms: linux/amd64,linux/arm64
3535

36+
- name: Inspect Image
37+
id: inspect
38+
run: |
39+
json=$(docker buildx imagetools inspect ${{ steps.current.outputs.image }}:${{ steps.current.outputs.tag }} --raw )
40+
archs=$(echo $json | jq '[.manifests[] | .platform | select(.os != "unknown") | "\(.os)/\(.architecture)"] | join(",")')
41+
echo "archs=$archs" >> $GITHUB_ENV
42+
43+
3644
- uses: nick-fields/assert-action@v1
3745
with:
3846
expected: 'registry.hub.docker.com/cloudposse/github-action-docker-build-push'
@@ -45,14 +53,14 @@ jobs:
4553

4654
- uses: nick-fields/assert-action@v1
4755
with:
48-
expected: 'containerimage.buildinfo/linux/amd64'
49-
actual: ${{ steps.current.outputs.metadata }}
56+
expected: 'linux/amd64'
57+
actual: ${{ env.archs }}
5058
comparison: contains
5159

5260
- uses: nick-fields/assert-action@v1
5361
with:
54-
expected: 'containerimage.buildinfo/linux/arm64'
55-
actual: ${{ steps.current.outputs.metadata }}
62+
expected: 'linux/arm64'
63+
actual: ${{ env.archs }}
5664
comparison: contains
5765

5866
teardown:

action.yml

+16-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ inputs:
5656
description: "List of cache export destinations for buildx (e.g., user/app:cache, type=local,dest=path/to/dir)"
5757
required: false
5858
default: type=gha,mode=max
59+
no-cache:
60+
description: "Send the --no-cache flag to the docker build process"
61+
required: false
62+
default: "false"
5963
ssh:
6064
description: "List of SSH agent socket or keys to expose to the build"
6165
required: false
@@ -111,6 +115,7 @@ runs:
111115
images: |
112116
${{ inputs.registry }}/${{ steps.image_name.outputs.image_name }}
113117
# generate Docker tags based on the following events/attributes
118+
# we set sha as higher priority than the defaults, so that it is the first tag
114119
tags: |
115120
type=sha
116121
type=schedule
@@ -120,7 +125,7 @@ runs:
120125
type=semver,pattern={{major}}.{{minor}}
121126
type=semver,pattern={{major}}
122127
type=raw,value=latest,enable={{is_default_branch}}
123-
type=sha,format=long
128+
type=sha,format=long,priority=1001
124129
${{ inputs.tags }}
125130
labels: |
126131
org.opencontainers.image.source=https://github.com/${{ inputs.organization }}/${{ inputs.repository }}
@@ -131,13 +136,18 @@ runs:
131136
version: 1.6
132137
force: 'true'
133138

139+
# here we set the first tag in the output as the output of this step
140+
# this order is determined by the priority, we set the sha as 1001, as that is 1 above the defaults
141+
# If a custom tag is added we can add a priority higher than that to set that as the output.
142+
# https://github.com/docker/metadata-action#priority-attribute
143+
# this formula is, of the tags, grab the first (highest priority), then split by : for the tag, grab the tag (last element)
134144
- uses: edwardgeorge/jq-action@main
135145
id: tag
136146
with:
137147
compact: true
138148
raw-output: true
139149
input: ${{ steps.meta.outputs.json }}
140-
script: '.tags | map(select(test("sha-\\w{8,}"))) | first | match("sha-\\w{8,}") | .string'
150+
script: '.tags | ( first / ":") | .[length -1]'
141151

142152
# docker context must be created prior to setting up Docker Buildx
143153
# https://github.com/actions-runner-controller/actions-runner-controller/issues/893
@@ -148,10 +158,10 @@ runs:
148158
docker context create buildx-context || true
149159
150160
- name: Set up QEMU
151-
uses: docker/setup-qemu-action@v2
161+
uses: docker/setup-qemu-action@v3
152162

153163
- name: Set up Docker Buildx
154-
uses: docker/setup-buildx-action@v2
164+
uses: docker/setup-buildx-action@v3
155165
with:
156166
endpoint: buildx-context
157167

@@ -164,7 +174,7 @@ runs:
164174
password: ${{ inputs.password }}
165175

166176
- name: Build and push Docker images
167-
uses: docker/build-push-action@v4
177+
uses: docker/build-push-action@v5
168178
id: docker-build-push-action
169179
with:
170180
context: ${{ inputs.workdir }}
@@ -175,6 +185,7 @@ runs:
175185
build-args: ${{ inputs.build-args }}
176186
cache-from: ${{ inputs.cache-from }}
177187
cache-to: ${{ inputs.cache-to }}
188+
no-cache: ${{ inputs.no-cache }}
178189
tags: ${{ steps.meta.outputs.tags }}
179190
target: ${{ inputs.target }}
180191
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)