@@ -125,6 +125,7 @@ QUAL_FQIN = 'fqin'
125
125
126
126
127
127
_DISCOVERED_CONTAINER_ENGINES = []
128
+ _BUILDX_BUILDER_NAME = "samba-in-kubernetes"
128
129
129
130
130
131
def check_kind (kind ):
@@ -203,14 +204,25 @@ def container_engine(cli):
203
204
204
205
def container_build (cli , target ):
205
206
"""Construct and execute a command to build the target container image."""
206
- args = [container_engine (cli ), "build" ]
207
- pkgs_from = PACKAGES_FROM [target .pkg_source ]
208
- if pkgs_from :
209
- args .append (f"--build-arg=INSTALL_PACKAGES_FROM={ pkgs_from } " )
210
- # docker doesn't currently support alt. architectures
207
+ eng = container_engine (cli )
208
+ args = [eng , "build" ]
209
+
211
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
212
if target .arch != host_arch ():
213
- raise RuntimeError ("Docker does not support --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 )
214
226
elif target .arch != host_arch () or FORCE_ARCH_FLAG :
215
227
# We've noticed a few small quirks when using podman with the --arch
216
228
# option. The main issue is that building the client image works
@@ -219,6 +231,11 @@ def container_build(cli, target):
219
231
# --arch is not provided. So if the target arch and the host_arch
220
232
# are the same, skip passing the extra argument.
221
233
args .append (f"--arch={ target .arch } " )
234
+
235
+ pkgs_from = PACKAGES_FROM [target .pkg_source ]
236
+ if pkgs_from :
237
+ args .append (f"--build-arg=INSTALL_PACKAGES_FROM={ pkgs_from } " )
238
+
222
239
if cli .extra_build_arg :
223
240
args .extend (cli .extra_build_arg )
224
241
for tname in target .all_names (baseless = cli .without_repo_bases ):
0 commit comments