@@ -125,7 +125,6 @@ QUAL_FQIN = 'fqin'
125
125
126
126
127
127
_DISCOVERED_CONTAINER_ENGINES = []
128
- _BUILDX_BUILDER_NAME = "samba-in-kubernetes"
129
128
130
129
131
130
def check_kind (kind ):
@@ -205,34 +204,41 @@ def container_engine(cli):
205
204
def container_build (cli , target ):
206
205
"""Construct and execute a command to build the target container image."""
207
206
eng = container_engine (cli )
208
- args = [eng , "build" ]
209
-
210
- if "docker" in args [0 ]:
211
- # if the target arch and the host_arch are not the same, we need to use buildx
212
- if target .arch != host_arch ():
213
- args = [
214
- eng ,
215
- "buildx" ,
216
- "build" ,
217
- f"--builder={ _BUILDX_BUILDER_NAME } " ,
218
- f"--platform=linux/{ target .arch } " ,
219
- "--load"
220
- ]
221
- # Docker's default builder only supports the host architecture.
222
- # Therefore, we need to create a new builder to support other
223
- # architectures. Errors are suppressed to prevent issues when
224
- # the builder is already available - this can be improved later.
225
- run (cli , [eng , "buildx" , "create" , f"--name={ _BUILDX_BUILDER_NAME } " ], check = False )
226
- elif target .arch != host_arch () or FORCE_ARCH_FLAG :
227
- # We've noticed a few small quirks when using podman with the --arch
228
- # option. The main issue is that building the client image works
229
- # but then the toolbox image fails because it somehow doesn't see
230
- # the image we just built as usable. This doesn't happen when
231
- # --arch is not provided. So if the target arch and the host_arch
232
- # are the same, skip passing the extra argument.
233
- args .append (f"--arch={ target .arch } " )
234
-
235
- run (cli , args + create_common_container_engine_args (cli , target ), check = True )
207
+ tasks = []
208
+
209
+ # For docker cross-builds we need to use buildx
210
+ if "docker" in eng and target .arch != host_arch ():
211
+ args = [eng , "buildx" ]
212
+
213
+ # Docker's default builder only supports the host architecture.
214
+ # Therefore, we need to create a new builder to support other
215
+ # architectures, and we must ensure we start with a fresh builder
216
+ # that does not contain any images from previous builds.
217
+ tasks .append (lambda : run (cli , args + ["rm" , target .flat_name ()], check = False ))
218
+ tasks .append (lambda : run (cli , args + ["create" , f"--name={ target .flat_name ()} " ], check = True ))
219
+
220
+ tasks .append (lambda : run (cli , args + [
221
+ "build" ,
222
+ f"--builder={ target .flat_name ()} " ,
223
+ f"--platform=linux/{ target .arch } " ,
224
+ "--load" ] + create_common_container_engine_args (cli , target ), check = True ))
225
+
226
+ tasks .append (lambda : run (cli , args + ["rm" , target .flat_name ()], check = True ))
227
+ else :
228
+ args = [eng , "build" ]
229
+ if target .arch != host_arch () or FORCE_ARCH_FLAG :
230
+ # We've noticed a few small quirks when using podman with the --arch
231
+ # option. The main issue is that building the client image works
232
+ # but then the toolbox image fails because it somehow doesn't see
233
+ # the image we just built as usable. This doesn't happen when
234
+ # --arch is not provided. So if the target arch and the host_arch
235
+ # are the same, skip passing the extra argument.
236
+ args += [f"--arch={ target .arch } " ]
237
+
238
+ tasks .append (lambda : run (cli , args + create_common_container_engine_args (cli , target ), check = True ))
239
+
240
+ for task in tasks :
241
+ task ()
236
242
237
243
def create_common_container_engine_args (cli , target ):
238
244
args = []
0 commit comments