1
1
name : Publish Docker Image
2
- on :
2
+ on :
3
3
push :
4
- branches : [master]
4
+ branches : [ master ]
5
+ tags :
6
+ - ' **'
5
7
6
- concurrency :
8
+ concurrency :
7
9
group : ${{ github.ref }}-${{ github.workflow }}
8
10
cancel-in-progress : true
9
11
12
+ env :
13
+ REGISTRY_IMAGE : ghcr.io/metacubex/subconverter
14
+
10
15
jobs :
11
- amd64_build :
12
- name : Build AMD64 Image
13
- runs-on : ubuntu-latest
16
+ build :
17
+ strategy :
18
+ matrix :
19
+ include :
20
+ - platform : linux/amd64
21
+ os : ubuntu-latest
22
+ - platform : linux/386
23
+ os : ubuntu-latest
24
+ - platform : linux/arm/v7
25
+ os : ubuntu-latest
26
+ - platform : linux/arm64
27
+ os : ubuntu-latest
28
+ runs-on : ${{ matrix.os }}
29
+ name : Build ${{ matrix.platform }} Image
14
30
steps :
31
+ - name : Prepare
32
+ run : |
33
+ platform=${{ matrix.platform }}
34
+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
35
+
15
36
- name : Checkout base
16
- uses : actions/checkout@v3
37
+ uses : actions/checkout@v4
17
38
with :
18
39
fetch-depth : 0
19
40
20
41
- name : Set up Docker Buildx
21
- uses : docker/setup-buildx-action@v2
22
-
23
- - name : login to ghcr.io
24
- uses : docker/login-action@v3
25
- with :
26
- registry : ghcr.io
27
- username : ${{ github.actor }}
28
- password : ${{ secrets.GITHUB_TOKEN }}
29
-
30
- - name : Get commit SHA
31
- id : vars
32
- run : echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
33
-
34
- - name : Build and export
35
- id : build
36
- if : github.ref == 'refs/heads/master'
37
- uses : docker/build-push-action@v3
38
- with :
39
- platforms : linux/amd64
40
- context : scripts/
41
- tags : ghcr.io/metacubex/subconverter:latest
42
- build-args : |
43
- SHA=${{ steps.vars.outputs.sha_short }}
44
- outputs : type=image,push=true
45
-
46
- - name : Save digest
47
- if : github.ref == 'refs/heads/master'
48
- run : echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
42
+ uses : docker/setup-buildx-action@v3
49
43
50
- - name : Upload artifact
51
- uses : actions/upload-artifact@v3
52
- with :
53
- name : digest_amd64
54
- path : /tmp/digest.txt
55
-
56
- x86_build :
57
- name : Build x86 Image
58
- runs-on : ubuntu-latest
59
- steps :
60
- - name : Checkout base
61
- uses : actions/checkout@v3
44
+ - name : Docker meta
45
+ id : meta
46
+ uses : docker/metadata-action@v5
62
47
with :
63
- fetch-depth : 0
64
-
65
- - name : Set up Docker Buildx
66
- uses : docker/setup-buildx-action@v2
48
+ images : ${{ env.REGISTRY_IMAGE }}
49
+ tags : |
50
+ type=semver,pattern={{version}}
51
+ type=raw,value=latest,enable={{is_default_branch}}
67
52
68
53
- name : login to ghcr.io
69
54
uses : docker/login-action@v3
@@ -73,105 +58,59 @@ jobs:
73
58
password : ${{ secrets.GITHUB_TOKEN }}
74
59
75
60
- name : Get commit SHA
76
- id : vars
77
- run : echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
78
-
79
- - name : Build and export
80
- id : build
81
61
if : github.ref == 'refs/heads/master'
82
- uses : docker/build-push-action@v3
83
- with :
84
- platforms : linux/386
85
- context : scripts/
86
- tags : ghcr.io/metacubex/subconverter:latest
87
- build-args : |
88
- SHA=${{ steps.vars.outputs.sha_short }}
89
- outputs : type=image,push=true
90
-
91
- - name : Save digest
92
- if : github.ref == 'refs/heads/master'
93
- run : echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
94
-
95
- - name : Upload artifact
96
- uses : actions/upload-artifact@v3
97
- with :
98
- name : digest_386
99
- path : /tmp/digest.txt
100
-
101
- arm64_build :
102
- name : Build ARM64 Image
103
- runs-on : ubuntu-latest
104
- steps :
105
- - name : Checkout base
106
- uses : actions/checkout@v3
107
- with :
108
- fetch-depth : 0
109
-
110
- - name : Set up QEMU
111
- uses : docker/setup-qemu-action@v2
112
-
113
- - name : Set up Docker Buildx
114
- uses : docker/setup-buildx-action@v2
115
-
116
- - name : login to ghcr.io
117
- uses : docker/login-action@v3
118
- with :
119
- registry : ghcr.io
120
- username : ${{ github.actor }}
121
- password : ${{ secrets.GITHUB_TOKEN }}
122
-
123
- - name : Get commit SHA
124
62
id : vars
125
- run : echo "::set-output name= sha_short:: $(git rev-parse --short HEAD)"
63
+ run : echo "sha_short= $(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
126
64
127
65
- name : Build and export
128
66
id : build
129
- if : github.ref == 'refs/heads/master'
130
- uses : docker/build-push-action@v3
67
+ uses : docker/build-push-action@v5
131
68
with :
132
- platforms : linux/arm64
69
+ platforms : ${{ matrix.platform }}
133
70
context : scripts/
134
- tags : ghcr.io/metacubex/subconverter:latest
71
+ labels : ${{ steps.meta.outputs.labels }}
135
72
build-args : |
136
73
SHA=${{ steps.vars.outputs.sha_short }}
137
- THREADS=2
138
- outputs : type=image,push=true
74
+ outputs : type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
139
75
140
- - name : Save digest
141
- if : github.ref == 'refs/heads/master'
142
- run : echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
76
+ - name : Export digest
77
+ run : |
78
+ rm -rf /tmp/digests
79
+ mkdir -p /tmp/digests
80
+ digest="${{ steps.build.outputs.digest }}"
81
+ touch "/tmp/digests/${digest#sha256:}"
143
82
144
83
- name : Upload artifact
145
- uses : actions/upload-artifact@v3
84
+ uses : actions/upload-artifact@v4
146
85
with :
147
- name : digest_arm64
148
- path : /tmp/digest.txt
149
- build :
150
- name : Build
151
- needs : [amd64_build, x86_build, arm64_build]
86
+ name : digest-${{ env.PLATFORM_PAIR }}
87
+ path : /tmp/digests/*
88
+ if-no-files-found : error
89
+ retention-days : 1
90
+
91
+ merge :
92
+ name : Merge
93
+ needs : build
152
94
runs-on : ubuntu-latest
153
95
steps :
154
- - name : Checkout base
155
- uses : actions/checkout@v3
96
+ - name : Download digests
97
+ uses : actions/download-artifact@v4
156
98
with :
157
- fetch-depth : 0
158
-
159
- # https://github.com/docker/setup-qemu-action
160
- - name : Set up QEMU
161
- uses : docker/setup-qemu-action@v2
99
+ path : /tmp/digests
100
+ pattern : digest-*
101
+ merge-multiple : true
162
102
163
- # https://github.com/docker/setup-buildx-action
164
103
- name : Set up Docker Buildx
165
- uses : docker/setup-buildx-action@v2
166
- with :
167
- config-inline : |
168
- [worker.oci]
169
- max-parallelism = 1
104
+ uses : docker/setup-buildx-action@v3
170
105
171
- - name : Download artifact
172
- uses : actions/download-artifact@v3
106
+ - name : Docker meta
107
+ id : meta
108
+ uses : docker/metadata-action@v5
173
109
with :
174
- path : /tmp/images/
110
+ images : ${{ env.REGISTRY_IMAGE }}
111
+ tags : |
112
+ type=semver,pattern={{version}}
113
+ type=raw,value=latest,enable={{is_default_branch}}
175
114
176
115
- name : login to ghcr.io
177
116
uses : docker/login-action@v3
@@ -180,6 +119,12 @@ jobs:
180
119
username : ${{ github.actor }}
181
120
password : ${{ secrets.GITHUB_TOKEN }}
182
121
183
- - name : Merge and push manifest on master branch
184
- if : github.ref == 'refs/heads/master'
185
- run : python scripts/merge_manifest.py
122
+ - name : Create manifest list and push
123
+ working-directory : /tmp/digests
124
+ run : |
125
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
126
+ $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
127
+
128
+ - name : Inspect image
129
+ run : |
130
+ docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
0 commit comments