9
9
# schedule:
10
10
# - cron: '18 10 * * *'
11
11
push :
12
- branches : [ "main" ]
12
+ branches : ["main"]
13
13
# Publish semver tags as releases.
14
- tags : [ ' v*.*.*' ]
14
+ tags : [" v*.*.*" ]
15
15
pull_request :
16
- branches : [ "main" ]
16
+ branches : ["main"]
17
17
18
18
env :
19
19
# Use docker.io for Docker Hub if empty
20
- REGISTRY : ghcr.io
21
- IMAGE_NAME : ${{ github.repository }}
22
-
20
+ REGISTRY_IMAGE : ghcr.io/sourcebot
23
21
24
22
jobs :
25
23
build :
@@ -32,53 +30,73 @@ jobs:
32
30
id-token : write
33
31
strategy :
34
32
matrix :
35
- architecture : [amd64, arm64]
33
+ platform :
34
+ - linux/amd64
35
+ - linux/arm64
36
36
37
37
steps :
38
+ - name : Prepare
39
+ run : |
40
+ platform=${{ matrix.platform }}
41
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
42
+
38
43
- name : Checkout repository
39
44
uses : actions/checkout@v4
40
45
with :
41
- submodules : ' true'
42
-
46
+ submodules : " true"
47
+
43
48
# Extract metadata (tags, labels) for Docker
44
49
# https://github.com/docker/metadata-action
45
50
- name : Extract Docker metadata
46
51
id : meta
47
52
uses : docker/metadata-action@v5
48
53
with :
49
- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
54
+ images : ${{ env.REGISTRY_IMAGE }}
50
55
51
56
# Install the cosign tool except on PR
52
57
# https://github.com/sigstore/cosign-installer
53
58
- name : Install cosign
54
59
if : github.event_name != 'pull_request'
55
60
56
61
with :
57
- cosign-release : ' v2.2.4'
62
+ cosign-release : " v2.2.4"
58
63
59
64
- name : Set up Docker Buildx
60
- uses : docker/setup-buildx-action@v1
61
-
65
+ uses : docker/setup-buildx-action@v3
66
+
62
67
- name : Login to GitHub Packages Docker Registry
63
68
uses : docker/login-action@v1
64
69
if : github.event_name != 'pull_request'
65
70
with :
66
- registry : ${{ env.REGISTRY }}
71
+ registry : ghcr.io
67
72
username : ${{ github.actor }}
68
73
password : ${{ secrets.GITHUB_TOKEN }}
69
74
70
75
- name : Build and push Docker image
71
- id : build-and-push
72
- uses : docker/build-push-action@v5
76
+ id : build
77
+ uses : docker/build-push-action@v6
73
78
with :
74
79
context : .
75
- push : ${{ github.event_name != 'pull_request' }}
76
80
tags : ${{ steps.meta.outputs.tags }}
77
81
labels : ${{ steps.meta.outputs.labels }}
78
82
cache-from : type=gha
79
83
cache-to : type=gha,mode=max
80
- platforms : linux/${{ matrix.architecture }}
81
-
84
+ platforms : ${{ matrix.platform }}
85
+
86
+ - name : Export digest
87
+ run : |
88
+ mkdir -p /tmp/digests
89
+ digest="${{ steps.build.outputs.digest }}"
90
+ touch "/tmp/digests/${digest#sha256:}"
91
+
92
+ - name : Upload digest
93
+ uses : actions/upload-artifact@v4
94
+ with :
95
+ name : digests-${{ env.PLATFORM_PAIR }}
96
+ path : /tmp/digests/*
97
+ if-no-files-found : error
98
+ retention-days : 1
99
+
82
100
# Sign the resulting Docker image digest except on PRs.
83
101
# This will only write to the public Rekor transparency log when the Docker
84
102
# repository is public to avoid leaking data. If you would like to publish
@@ -89,7 +107,46 @@ jobs:
89
107
env :
90
108
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
91
109
TAGS : ${{ steps.meta.outputs.tags }}
92
- DIGEST : ${{ steps.build-and-push .outputs.digest }}
110
+ DIGEST : ${{ steps.build.outputs.digest }}
93
111
# This step uses the identity token to provision an ephemeral certificate
94
112
# against the sigstore community Fulcio instance.
95
- run : echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
113
+ run : echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
114
+
115
+ merge :
116
+ runs-on : ubuntu-latest
117
+ if : github.event_name != 'pull_request'
118
+ needs :
119
+ - build
120
+ steps :
121
+ - name : Download digests
122
+ uses : actions/download-artifact@v4
123
+ with :
124
+ path : /tmp/digests
125
+ pattern : digests-*
126
+ merge-multiple : true
127
+
128
+ - name : Set up Docker Buildx
129
+ uses : docker/setup-buildx-action@v3
130
+
131
+ - name : Extract Docker metadata
132
+ id : meta
133
+ uses : docker/metadata-action@v5
134
+ with :
135
+ images : ${{ env.REGISTRY_IMAGE }}
136
+
137
+ - name : Login to GitHub Packages Docker Registry
138
+ uses : docker/login-action@v1
139
+ with :
140
+ registry : ghcr.io
141
+ username : ${{ github.actor }}
142
+ password : ${{ secrets.GITHUB_TOKEN }}
143
+
144
+ - name : Create manifest list and push
145
+ working-directory : /tmp/digests
146
+ run : |
147
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
148
+ $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
149
+
150
+ - name : Inspect image
151
+ run : |
152
+ docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
0 commit comments