1
- name : Build and Release
1
+ name : Build and Release Container
2
2
on :
3
+ release :
4
+ types : [released]
3
5
push :
4
6
branches :
5
7
- ' *'
6
- pull_request :
7
- branches :
8
- - ' release-*'
9
- types :
10
- # action should run when the pull request is closed
11
- # (regardless of whether it was merged or just closed)
12
- - closed
13
- # Make sure the action runs every time new commits are
14
- # pushed to the pull request's branch
15
- - synchronize
16
8
17
9
env :
18
10
REGISTRY : ghcr.io
@@ -25,10 +17,13 @@ jobs:
25
17
fail-fast : false
26
18
matrix :
27
19
platform :
28
- - linux/arm64
20
+ - linux/386
29
21
- linux/amd64
30
- - linux/s390x
22
+ - linux/arm/v6
23
+ - linux/arm/v7
24
+ - linux/arm64/v8
31
25
- linux/ppc64le
26
+ - linux/s390x
32
27
33
28
permissions :
34
29
contents : read
@@ -46,12 +41,16 @@ jobs:
46
41
uses : actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
47
42
48
43
# Extract metadata (tags, labels) for Docker
44
+ # If the pull request is not merged, do not include the edge tag and only include the sha tag.
49
45
# https://github.com/docker/metadata-action
50
46
- name : Extract Docker metadata
51
- id : meta
52
47
uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
53
48
with :
54
- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49
+ images : |
50
+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
51
+ tags : |
52
+ type=semver,pattern=v{{version}}
53
+ type=sha
55
54
56
55
# Set up QEMU
57
56
# https://github.com/docker/setup-qemu-action
@@ -81,21 +80,19 @@ jobs:
81
80
with :
82
81
context : .
83
82
platforms : ${{ matrix.platform }}
84
- labels : ${{ steps.meta.outputs.labels }}
85
- push : ${{ github.event.pull_request.merged == true }}
83
+ labels : ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}
84
+ push : true
86
85
outputs : type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true
87
86
88
87
# Export digest
89
88
- name : Export digest
90
- if : github.event.pull_request.merged == true
91
89
run : |
92
90
mkdir -p /tmp/digests
93
91
digest="${{ steps.build.outputs.digest }}"
94
92
touch "/tmp/digests/${digest#sha256:}"
95
93
96
94
# Upload digest
97
95
- name : Upload digest
98
- if : github.event.pull_request.merged == true
99
96
uses : actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
100
97
with :
101
98
name : digests
@@ -104,8 +101,8 @@ jobs:
104
101
retention-days : 1
105
102
106
103
merge :
104
+ name : Merge Container Manifests
107
105
runs-on : ubuntu-latest
108
- if : github.event.pull_request.merged == true
109
106
needs :
110
107
- build
111
108
steps :
@@ -128,12 +125,16 @@ jobs:
128
125
uses : docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
129
126
130
127
# Extract metadata (tags, labels) for Docker
128
+ # If the pull request is not merged, do not include the edge tag and only include the sha tag.
131
129
# https://github.com/docker/metadata-action
132
130
- name : Extract Docker metadata
133
- id : meta
134
131
uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
135
132
with :
136
- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
133
+ images : |
134
+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
135
+ tags : |
136
+ type=semver,pattern=v{{version}}
137
+ type=sha
137
138
138
139
# Login to Docker registry
139
140
# https://github.com/docker/login-action
@@ -148,9 +149,18 @@ jobs:
148
149
- name : Create manifest list and push
149
150
working-directory : /tmp/digests
150
151
run : |
151
- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
152
- $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
152
+ # Base command to create a manifest list with the selected tag(s) and push
153
+ CMD="docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
154
+ $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)"
155
+
156
+ # If the branch is 'release-*', add the 'edge' tag
157
+ if [[ "${{ github.ref }}" == refs/heads/release-* ]]; then
158
+ CMD="$CMD -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:edge"
159
+ fi
160
+
161
+ # Execute the command
162
+ eval "$CMD"
153
163
154
164
- name : Inspect image
155
165
run : |
156
- docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
166
+ docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_METADATA_OUTPUT_VERSION }}
0 commit comments