melodic-airport-53682
03/25/2025, 4:27 PMARG BUILD_IMAGE=//apps/ingress-nginx/build:docker-amd64
ARG BASE_IMAGE=//base-images/alpine:docker-amd64
I’m trying to make this support arm64 as well and we dont have the capability for multi arch manifests (yet) so I need to explicitly specify the arch. I tried this and it doesnt work
ARG BUILD_IMAGE=//apps/ingress-nginx/build:docker-${TARGET_ARCH}
ARG BASE_IMAGE=//base-images/alpine:docker-${TARGET_ARCH}
Any guidance on how to effectively do this?broad-processor-92400
03/28/2025, 3:51 AMmelodic-airport-53682
03/28/2025, 2:30 PMTARGET_ARCH argument into the build or base images
Heres an example I just ran:
ARG TARGETARCH
ARG BASE_IMAGE=//base-images/alpine:docker-${TARGETARCH}
results in
f"{arg_name}={address_to_built_image_tag[addr]}"
KeyError: Address(base-images/alpine:docker-${TARGETARCH})broad-processor-92400
03/28/2025, 8:29 PMKeyError is definitely a bug. Could you file an issue? Thanks.
In terms of making this work… where does TARGET_ARCH get set? Is it provided as an environment variable to the pants invocation?melodic-airport-53682
03/28/2025, 10:06 PMbroad-processor-92400
03/30/2025, 11:27 PMBUILD file rather than as a separate Dockerfile (using https://www.pantsbuild.org/stable/reference/targets/docker_image#instructions), then one can likely format the spec earlier so that Pants' dep inference gets the fully formatted value, rather than rely on docker's env-var substitution that only happens when actually building:
• If you're willing to provide an env-var (not necessarily TARGETARCH) externally, then instructions=[...., f"ARG BASE_IMAGE=//base-images/alpine:docker-{env('YOUR_VARIABLE_NAME_HERE')}", ....] (env also accepts an optional default value for if the var isn't set: https://www.pantsbuild.org/stable/docs/using-pants/key-concepts/targets-and-build-files#environment-variables)
• Alternatively, one could have duplicate docker_image targets via a loop (or a python function) e.g.
for arch in ...:
docker_image(..., instructions=[..., f"ARG BASE_IMAGE=//base-images/alpine:docker-{arch}", ...], ...)broad-processor-92400
03/30/2025, 11:29 PMDockerfile s, then I think one will just need to step away from ARG-based dep inference, and provide the dependencies manually, e.g. FROM name-of-image in the dockerfile, and then dependencies=["//base-images/alpine:docker-..."] in the build file (this might require duplicating the targets, too)