Hi all, is this the best practice for building and...
# general
f
Hi all, is this the best practice for building and running Docker images using Pants on both mac and linux? What we tried: • Create BUILD files and Dockerfile for multi-stage build leveraging 2 PEXs • Generate a
complete_platforms
file on linux following this guide
Copy code
docker run --entrypoint='/bin/sh' -it --platform linux/amd64 --rm python:3.10-slim -c "python -m pip install pex >/dev/null 2>&1 && pex3 interpreter inspect --markers --tags --indent=2" > linux_amd64_py310.json
• Add
file
target to BUILD file for PEX binaries like
Copy code
file(
    name="linux_amd64_py310",
    source="linux_amd64_py310.json",
)
• Add
complete_platforms=[":linux_amd64_py310"]
to
pex_binary
target args • Add
build_platform=["linux/amd64"]
to
docker_image
target args Note: We only need to create the image for a single platform (eg
linux/amd64
) but we would like to be able build the image and run the container locally on both mac and linux. We will also build the image as part of CI.
b
that's basically what we do, although we build the PEX for both amd64 and arm64 so that the docker image can run natively on apple silicon macs (https://github.com/pantsbuild/pants/discussions/18756 is an old description of that)
f
Great, thank you! Appreciate the reply.