@@ -16,21 +16,31 @@ name: Build CI Image
16
16
17
17
on :
18
18
workflow_dispatch : # Allow manual trigger
19
+ schedule :
20
+ - cron : " 15 16 * * 0" # At 16:15 UTC on Sunday
19
21
20
22
permissions :
21
23
contents : read
24
+ packages : write
22
25
23
26
concurrency :
24
27
group : ${{ github.ref || github.run_id }}
25
28
cancel-in-progress : true
26
29
27
30
jobs :
28
31
build :
29
- runs-on : ubuntu-24.04
32
+ strategy :
33
+ matrix :
34
+ include :
35
+ - platform : linux/amd64
36
+ cache_tag : linux-amd64
37
+ runner : ubuntu-24.04
38
+ - platform : linux/arm64
39
+ cache_tag : linux-arm64
40
+ runner : ubuntu-24.04-arm
30
41
31
- permissions :
32
- contents : read
33
- packages : write
42
+ runs-on : ${{ matrix.runner }}
43
+ name : Docker Build ${{ matrix.platform }}
34
44
35
45
steps :
36
46
- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0
@@ -42,11 +52,17 @@ jobs:
42
52
id : buildx
43
53
uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # 3.11.1
44
54
55
+ # Lowercase image name and append -ci
56
+ - name : Generate Image Name
57
+ id : image-name
58
+ run : |
59
+ echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}-ci" >>"${GITHUB_OUTPUT}"
60
+
45
61
- name : Generate Docker Metadata (Tags and Labels)
46
62
id : meta
47
63
uses : docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # 5.8.0
48
64
with :
49
- images : ghcr.io/${{ github.repository }}-ci
65
+ images : ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }}
50
66
flavor : |
51
67
prefix=
52
68
suffix=
@@ -65,11 +81,86 @@ jobs:
65
81
username : ${{ github.repository_owner }}
66
82
password : ${{ secrets.GITHUB_TOKEN }}
67
83
68
- - name : Build and Publish Image
84
+ - name : Build and Push Image by Digest
85
+ id : build
69
86
uses : docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # 6.18.0
70
87
with :
71
- push : ${{ github.event_name != 'pull_request' }}
72
88
context : .github/containers
73
- platforms : ${{ (format('refs/heads/{0}', github.event.repository.default_branch) == github.ref) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
74
- tags : ${{ steps.meta.outputs.tags }}
89
+ platforms : ${{ matrix.platform }}
75
90
labels : ${{ steps.meta.outputs.labels }}
91
+ outputs : type=image,name=ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
92
+ cache-from : type=gha,scope=build-${{ matrix.cache_tag }}
93
+ cache-to : type=gha,scope=build-${{ matrix.cache_tag }}
94
+
95
+ - name : Export Digest
96
+ run : |
97
+ mkdir -p ${{ runner.temp }}/digests
98
+ digest="${{ steps.build.outputs.digest }}"
99
+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
100
+
101
+ - name : Upload Digest
102
+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
103
+ with :
104
+ name : digests-${{ matrix.cache_tag }}
105
+ path : ${{ runner.temp }}/digests/*
106
+ if-no-files-found : error
107
+ retention-days : 1
108
+
109
+ merge :
110
+ runs-on : ubuntu-latest
111
+ if : github.event_name != 'pull_request'
112
+ needs :
113
+ - build
114
+
115
+ name : Docker Merge Image
116
+
117
+ steps :
118
+ - name : Download Digests
119
+ uses : actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # 5.0.0
120
+ with :
121
+ path : ${{ runner.temp }}/digests
122
+ pattern : digests-*
123
+ merge-multiple : true
124
+
125
+ - name : Login to GitHub Container Registry
126
+ if : github.event_name != 'pull_request'
127
+ uses : docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # 3.5.0
128
+ with :
129
+ registry : ghcr.io
130
+ username : ${{ github.repository_owner }}
131
+ password : ${{ secrets.GITHUB_TOKEN }}
132
+
133
+ - name : Set up Docker Buildx
134
+ uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # 3.11.1
135
+
136
+ # Lowercase image name and append -ci
137
+ - name : Generate Image Name
138
+ id : image-name
139
+ run : |
140
+ echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}-ci" >>"${GITHUB_OUTPUT}"
141
+
142
+ - name : Generate Docker Metadata (Tags and Labels)
143
+ id : meta
144
+ uses : docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # 5.8.0
145
+ with :
146
+ images : ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }}
147
+ flavor : |
148
+ prefix=
149
+ suffix=
150
+ latest=false
151
+ tags : |
152
+ type=raw,value=latest,enable={{is_default_branch}}
153
+ type=schedule,pattern={{date 'YYYY-MM-DD'}}
154
+ type=sha,format=short,prefix=sha-
155
+ type=sha,format=long,prefix=sha-
156
+
157
+ - name : Create Manifest List and Push
158
+ working-directory : ${{ runner.temp }}/digests
159
+ run : |
160
+ # shellcheck disable=SC2046
161
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
162
+ $(printf 'ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }}@sha256:%s ' *)
163
+
164
+ - name : Inspect Image
165
+ run : |
166
+ docker buildx imagetools inspect ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
0 commit comments