@@ -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,18 @@ 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 = [eng , "buildx" , "build" , f"--builder={ _BUILDX_BUILDER_NAME } " , f"--platform=linux/{ target .arch } " ]
214
+ # Docker's default builder only supports the host architecture.
215
+ # Therefore, we need to create a new builder to support other
216
+ # architectures. Errors are suppressed to prevent issues when
217
+ # the builder is already available - this can be improved later.
218
+ run (cli , [eng , "buildx" , "create" , f"--name={ _BUILDX_BUILDER_NAME } " ], check = False )
214
219
elif target .arch != host_arch () or FORCE_ARCH_FLAG :
215
220
# We've noticed a few small quirks when using podman with the --arch
216
221
# option. The main issue is that building the client image works
@@ -219,6 +224,11 @@ def container_build(cli, target):
219
224
# --arch is not provided. So if the target arch and the host_arch
220
225
# are the same, skip passing the extra argument.
221
226
args .append (f"--arch={ target .arch } " )
227
+
228
+ pkgs_from = PACKAGES_FROM [target .pkg_source ]
229
+ if pkgs_from :
230
+ args .append (f"--build-arg=INSTALL_PACKAGES_FROM={ pkgs_from } " )
231
+
222
232
if cli .extra_build_arg :
223
233
args .extend (cli .extra_build_arg )
224
234
for tname in target .all_names (baseless = cli .without_repo_bases ):
0 commit comments