@@ -40,6 +40,10 @@ def run_cmd(command: str) -> str:
40
40
output += line
41
41
42
42
process .wait () # Wait for the subprocess to finish
43
+
44
+ if process .returncode != 0 :
45
+ raise subprocess .CalledProcessError (process .returncode , command , output )
46
+
43
47
return output
44
48
45
49
@@ -79,7 +83,7 @@ def make_docker_tag(l: list[str]) -> str:
79
83
80
84
def get_docker_tags (
81
85
build_preset : str ,
82
- build_platform : str ,
86
+ build_platforms : list [ str ] ,
83
87
sha : str ,
84
88
build_context : str ,
85
89
build_context_ref : str ,
@@ -91,17 +95,18 @@ def get_docker_tags(
91
95
tags : set [str ] = set ()
92
96
tag_chunks : list [str ] = []
93
97
94
- short_build_platform = build_platform .replace ("linux/" , "" ).replace ("64" , "" )
95
-
96
98
is_latest = is_latest_release (build_context_ref )
97
99
98
100
if build_preset != "lean" :
99
101
# Always add the preset_build name if different from default (lean)
100
102
tag_chunks += [build_preset ]
101
103
102
- if short_build_platform != "amd" :
103
- # Always a platform indicator if different from default (amd)
104
- tag_chunks += [short_build_platform ]
104
+ if len (build_platforms ) == 1 :
105
+ build_platform = build_platforms [0 ]
106
+ short_build_platform = build_platform .replace ("linux/" , "" ).replace ("64" , "" )
107
+ if short_build_platform != "amd" :
108
+ # Always a platform indicator if different from default (amd)
109
+ tag_chunks += [short_build_platform ]
105
110
106
111
# Always craft a tag for the SHA
107
112
tags .add (make_docker_tag ([sha ] + tag_chunks ))
@@ -123,7 +128,7 @@ def get_docker_tags(
123
128
124
129
def get_docker_command (
125
130
build_preset : str ,
126
- build_platform : str ,
131
+ build_platforms : list [ str ] ,
127
132
is_authenticated : bool ,
128
133
sha : str ,
129
134
build_context : str ,
@@ -160,7 +165,7 @@ def get_docker_command(
160
165
161
166
tags = get_docker_tags (
162
167
build_preset ,
163
- build_platform ,
168
+ build_platforms ,
164
169
sha ,
165
170
build_context ,
166
171
build_context_ref ,
@@ -170,8 +175,14 @@ def get_docker_command(
170
175
171
176
docker_args = "--load" if not is_authenticated else "--push"
172
177
target_argument = f"--target { build_target } " if build_target else ""
173
- short_build_platform = build_platform .replace ("linux/" , "" ).replace ("64" , "" )
174
- cache_ref = f"{ CACHE_REPO } :{ py_ver } -{ short_build_platform } "
178
+
179
+ cache_ref = f"{ CACHE_REPO } :{ py_ver } "
180
+ if len (build_platforms ) == 1 :
181
+ build_platform = build_platforms [0 ]
182
+ short_build_platform = build_platform .replace ("linux/" , "" ).replace ("64" , "" )
183
+ cache_ref = f"{ CACHE_REPO } :{ py_ver } -{ short_build_platform } "
184
+ platform_arg = "--platform " + "," .join (build_platforms )
185
+
175
186
cache_from_arg = f"--cache-from=type=registry,ref={ cache_ref } "
176
187
cache_to_arg = (
177
188
f"--cache-to=type=registry,mode=max,ref={ cache_ref } " if is_authenticated else ""
@@ -187,7 +198,7 @@ def get_docker_command(
187
198
{ cache_from_arg } \\
188
199
{ cache_to_arg } \\
189
200
{ build_arg } \\
190
- --platform { build_platform } \\
201
+ { platform_arg } \\
191
202
--label sha={ sha } \\
192
203
--label target={ build_target } \\
193
204
--label build_trigger={ build_context } \\
@@ -206,20 +217,23 @@ def get_docker_command(
206
217
@click .option (
207
218
"--platform" ,
208
219
type = click .Choice (["linux/arm64" , "linux/amd64" ]),
209
- default = "linux/amd64" ,
220
+ default = ["linux/amd64" ],
221
+ multiple = True ,
210
222
)
211
223
@click .option ("--build_context_ref" , help = "a reference to the pr, release or branch" )
212
224
@click .option ("--dry-run" , is_flag = True , help = "Run the command in dry-run mode." )
225
+ @click .option ("--verbose" , is_flag = True , help = "Print more info" )
213
226
@click .option (
214
227
"--force-latest" , is_flag = True , help = "Force the 'latest' tag on the release"
215
228
)
216
229
def main (
217
230
build_preset : str ,
218
231
build_context : str ,
219
232
build_context_ref : str ,
220
- platform : str ,
233
+ platform : list [ str ] ,
221
234
dry_run : bool ,
222
235
force_latest : bool ,
236
+ verbose : bool ,
223
237
) -> None :
224
238
"""
225
239
This script executes docker build and push commands based on given arguments.
@@ -262,6 +276,8 @@ def main(
262
276
"""
263
277
)
264
278
script = script + docker_build_command
279
+ if verbose :
280
+ run_cmd ("cat Dockerfile" )
265
281
stdout = run_cmd (script )
266
282
else :
267
283
print ("Dry Run - Docker Build Command:" )
0 commit comments