1
+ name : Build and Release Container
2
+ on :
3
+ release :
4
+ types : [released]
5
+ push :
6
+ branches :
7
+ - ' *'
8
+
9
+ env :
10
+ REGISTRY : ghcr.io
11
+
12
+ jobs :
13
+ build :
14
+ name : Build Containers
15
+ runs-on : ubuntu-latest
16
+ strategy :
17
+ fail-fast : false
18
+ matrix :
19
+ platform :
20
+ - linux/386
21
+ - linux/amd64
22
+ - linux/arm/v6
23
+ - linux/arm/v7
24
+ - linux/arm64/v8
25
+ - linux/ppc64le
26
+ - linux/s390x
27
+
28
+ permissions :
29
+ contents : read
30
+ packages : write
31
+
32
+ steps :
33
+
34
+ - name : Set IMAGE_NAME
35
+ run : |
36
+ echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
37
+
38
+ # Checkout code
39
+ # https://github.com/actions/checkout
40
+ - name : Checkout code
41
+ uses : actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
42
+
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.
45
+ # https://github.com/docker/metadata-action
46
+ - name : Extract Docker metadata
47
+ uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
48
+ with :
49
+ images : |
50
+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
51
+ tags : |
52
+ type=semver,pattern=v{{version}}
53
+ type=sha
54
+
55
+ # Set up QEMU
56
+ # https://github.com/docker/setup-qemu-action
57
+ - name : Set up QEMU
58
+ uses : docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
59
+
60
+ # Set up BuildKit Docker container builder to be able to build
61
+ # multi-platform images and export cache
62
+ # https://github.com/docker/setup-buildx-action
63
+ - name : Set up Docker Buildx
64
+ uses : docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
65
+
66
+ # Login to Docker registry
67
+ # https://github.com/docker/login-action
68
+ - name : Log into registry ${{ env.REGISTRY }}
69
+ uses : docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
70
+ with :
71
+ registry : ${{ env.REGISTRY }}
72
+ username : ${{ github.actor }}
73
+ password : ${{ secrets.GITHUB_TOKEN }}
74
+
75
+ # Build and push Docker image with Buildx
76
+ # https://github.com/docker/build-push-action
77
+ - name : Build and push Docker image
78
+ id : build
79
+ uses : docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
80
+ with :
81
+ context : .
82
+ platforms : ${{ matrix.platform }}
83
+ labels : ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}
84
+ push : true
85
+ outputs : type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true
86
+
87
+ # Export digest
88
+ - name : Export digest
89
+ run : |
90
+ mkdir -p /tmp/digests
91
+ digest="${{ steps.build.outputs.digest }}"
92
+ touch "/tmp/digests/${digest#sha256:}"
93
+
94
+ # Upload digest
95
+ - name : Upload digest
96
+ uses : actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
97
+ with :
98
+ name : digests
99
+ path : /tmp/digests/*
100
+ if-no-files-found : error
101
+ retention-days : 1
102
+
103
+ merge :
104
+ name : Merge Container Manifests
105
+ runs-on : ubuntu-latest
106
+ needs :
107
+ - build
108
+ steps :
109
+ - name : Set IMAGE_NAME
110
+ run : |
111
+ echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
112
+
113
+ # Download digests
114
+ # https://github.com/actions/download-artifact
115
+ - name : Download digests
116
+ uses : actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
117
+ with :
118
+ name : digests
119
+ path : /tmp/digests
120
+
121
+ # Set up BuildKit Docker container builder to be able to build
122
+ # multi-platform images and export cache
123
+ # https://github.com/docker/setup-buildx-action
124
+ - name : Set up Docker Buildx
125
+ uses : docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
126
+
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.
129
+ # https://github.com/docker/metadata-action
130
+ - name : Extract Docker metadata
131
+ uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
132
+ with :
133
+ images : |
134
+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
135
+ tags : |
136
+ type=semver,pattern=v{{version}}
137
+ type=sha
138
+
139
+ # Login to Docker registry
140
+ # https://github.com/docker/login-action
141
+ - name : Log into registry ${{ env.REGISTRY }}
142
+ uses : docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
143
+ with :
144
+ registry : ${{ env.REGISTRY }}
145
+ username : ${{ github.actor }}
146
+ password : ${{ secrets.GITHUB_TOKEN }}
147
+
148
+ # Create manifest list and push
149
+ - name : Create manifest list and push
150
+ working-directory : /tmp/digests
151
+ run : |
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"
163
+
164
+ - name : Inspect image
165
+ run : |
166
+ docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_METADATA_OUTPUT_VERSION }}
0 commit comments