6
6
jobs :
7
7
stage1 :
8
8
name : Stage 1
9
- runs-on : ubuntu-latest
9
+ runs-on : ${{ startsWith(matrix.platform, 'linux/arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
10
+ strategy :
11
+ matrix :
12
+ platform :
13
+ - linux/amd64
14
+ - linux/arm64
10
15
steps :
11
16
- name : Checkout the Git repository
12
17
uses : actions/checkout@v3
@@ -19,23 +24,84 @@ jobs:
19
24
- name : Set up version
20
25
run : |
21
26
VERSION="$(echo "${{ github.ref }}" | cut -d / -f 3)"
22
- echo "tag=ghcr.io/noahimesaka1873/toolchain:$VERSION" >> "$GITHUB_ENV"
27
+ platform=${{ matrix.platform }}
28
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
29
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
30
+ echo "tag=ghcr.io/noahimesaka1873/toolchain:$VERSION" >> $GITHUB_ENV
23
31
- name : Set up Docker Buildx
24
32
uses : docker/setup-buildx-action@v3
25
33
- name : Build and push toolchain
26
- uses : docker/build-push-action@v5
34
+ uses : docker/build-push-action@v6
27
35
with :
28
36
context : toolchain/
29
37
push : true
30
38
tags : ${{ env.tag }}
31
39
cache-from : type=gha
32
40
cache-to : type=gha,mode=max
41
+ outputs : type=image,"name=ghcr.io/noahimesaka1873/toolchain",push-by-digest=true,name-canonical=true,push=true
33
42
build-args : |
34
43
BUILDKIT_INLINE_CACHE=1
44
+ - name : Export digest
45
+ if : ${{ inputs.push_to_images != '' }}
46
+ run : |
47
+ mkdir -p "${{ runner.temp }}/digests"
48
+ digest="${{ steps.build.outputs.digest }}"
49
+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
50
+ - name : Upload digest
51
+ if : ${{ inputs.push_to_images != '' }}
52
+ uses : actions/upload-artifact@v4
53
+ with :
54
+ name : digests-toolchain-${{ env.PLATFORM_PAIR }}-${{ env.VERSION }}
55
+ path : ${{ runner.temp }}/digests/*
56
+ if-no-files-found : error
57
+ retention-days : 1
58
+ stage1-upload :
59
+ name : Stage 1 merge and push image
60
+ needs : stage1
61
+ runs-on : ubuntu-24.04
62
+ env :
63
+ PUSH_TO_IMAGES : ghcr.io/noahimesaka1873/toolchain
64
+ steps :
65
+ - uses : actions/checkout@v4
66
+ - name : Set up version
67
+ run : |
68
+ VERSION="$(echo "${{ github.ref }}" | cut -d / -f 3)"
69
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
70
+ - name : Download digests
71
+ uses : actions/download-artifact@v4
72
+ with :
73
+ path : ${{ runner.temp }}/digests
74
+ pattern : digests-toolchain-*-${{ env.VERSION }}
75
+ merge-multiple : true
76
+ - name : Log in to the GitHub Container registry
77
+ uses : docker/login-action@v3
78
+ with :
79
+ registry : ghcr.io
80
+ username : ${{ github.actor }}
81
+ password : ${{ secrets.GITHUB_TOKEN }}
82
+ - name : Set up Docker Buildx
83
+ uses : docker/setup-buildx-action@v3
84
+ - name : Docker meta
85
+ id : meta
86
+ uses : docker/metadata-action@v5
87
+ with :
88
+ images : ${{ env.PUSH_TO_IMAGES }}
89
+ tags : ${{ env.VERSION }}
90
+ - name : Create manifest list and push
91
+ working-directory : ${{ runner.temp }}/digests
92
+ run : |
93
+ echo "$PUSH_TO_IMAGES" | xargs -I{} \
94
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
95
+ $(printf '{}@sha256:%s ' *)
35
96
stage2 :
36
97
name : Stage 2
37
- runs-on : ubuntu-latest
38
- needs : stage1
98
+ needs : stage1-upload
99
+ runs-on : ${{ startsWith(matrix.platform, 'linux/arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
100
+ strategy :
101
+ matrix :
102
+ platform :
103
+ - linux/amd64
104
+ - linux/arm64
39
105
steps :
40
106
- name : Checkout the Git repository
41
107
uses : actions/checkout@v3
@@ -48,24 +114,80 @@ jobs:
48
114
- name : Set up version
49
115
run : |
50
116
VERSION="$(echo "${{ github.ref }}" | cut -d / -f 3)"
51
- echo "tag=ghcr.io/noahimesaka1873/base:$VERSION" >> "$GITHUB_ENV"
117
+ platform=${{ matrix.platform }}
118
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
119
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
120
+ echo "tag=ghcr.io/noahimesaka1873/base:$VERSION" >> $GITHUB_ENV
52
121
- name : Set up Docker Buildx
53
122
uses : docker/setup-buildx-action@v3
54
123
- name : Build and push toolchain
55
- uses : docker/build-push-action@v5
124
+ uses : docker/build-push-action@v6
56
125
with :
57
126
context : toolchain/
58
127
push : true
59
128
tags : ${{ env.tag }}
60
129
cache-from : type=gha
61
130
cache-to : type=gha,mode=max
131
+ outputs : type=image,"name=ghcr.io/noahimesaka1873/base",push-by-digest=true,name-canonical=true,push=true
62
132
build-args : |
63
133
BUILDKIT_INLINE_CACHE=1
64
134
FROM=ghcr.io/noahimesaka1873/toolchain
135
+ - name : Export digest
136
+ if : ${{ inputs.push_to_images != '' }}
137
+ run : |
138
+ mkdir -p "${{ runner.temp }}/digests"
139
+ digest="${{ steps.build.outputs.digest }}"
140
+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
141
+ - name : Upload digest
142
+ if : ${{ inputs.push_to_images != '' }}
143
+ uses : actions/upload-artifact@v4
144
+ with :
145
+ name : digests-base-${{ env.PLATFORM_PAIR }}-${{ env.VERSION }}
146
+ path : ${{ runner.temp }}/digests/*
147
+ if-no-files-found : error
148
+ retention-days : 1
149
+ stage2-upload :
150
+ name : Stage 2 merge and push image
151
+ needs : stage2
152
+ runs-on : ubuntu-24.04
153
+ env :
154
+ PUSH_TO_IMAGES : ghcr.io/noahimesaka1873/base
155
+ steps :
156
+ - uses : actions/checkout@v4
157
+ - name : Set up version
158
+ run : |
159
+ VERSION="$(echo "${{ github.ref }}" | cut -d / -f 3)"
160
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
161
+ - name : Download digests
162
+ uses : actions/download-artifact@v4
163
+ with :
164
+ path : ${{ runner.temp }}/digests
165
+ pattern : digests-base-*-${{ env.VERSION }}
166
+ merge-multiple : true
167
+ - name : Log in to the GitHub Container registry
168
+ uses : docker/login-action@v3
169
+ with :
170
+ registry : ghcr.io
171
+ username : ${{ github.actor }}
172
+ password : ${{ secrets.GITHUB_TOKEN }}
173
+ - name : Set up Docker Buildx
174
+ uses : docker/setup-buildx-action@v3
175
+ - name : Docker meta
176
+ id : meta
177
+ uses : docker/metadata-action@v5
178
+ with :
179
+ images : ${{ env.PUSH_TO_IMAGES }}
180
+ tags : ${{ env.VERSION }}
181
+ - name : Create manifest list and push
182
+ working-directory : ${{ runner.temp }}/digests
183
+ run : |
184
+ echo "$PUSH_TO_IMAGES" | xargs -I{} \
185
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
186
+ $(printf '{}@sha256:%s ' *)
65
187
stage3 :
66
188
name : Stage 3
67
189
runs-on : ubuntu-latest
68
- needs : stage2
190
+ needs : stage2-upload
69
191
strategy :
70
192
matrix :
71
193
from : [ghcr.io/noahimesaka1873/base]
85
207
- name : Set up version
86
208
run : |
87
209
VERSION="$(echo "${{ github.ref }}" | cut -d / -f 3)"
88
- echo "tag=ghcr.io/noahimesaka1873/${{ matrix.target }}:$VERSION" >> "$GITHUB_ENV"
210
+ echo "version=$VERSION" >> $GITHUB_ENV
211
+ echo "tag=ghcr.io/noahimesaka1873/${{ matrix.target }}:$VERSION" >> $GITHUB_ENV
89
212
- name : Set up Docker Buildx
90
213
uses : docker/setup-buildx-action@v3
91
214
- name : Build and push toolchain
98
221
cache-to : type=gha,mode=max
99
222
build-args : |
100
223
BUILDKIT_INLINE_CACHE=1
101
- FROM=${{ matrix.from }}:${{ env.tag }}
224
+ FROM=${{ matrix.from }}:${{ env.version }}
0 commit comments