Is there a way to use docker's multi-stage inherit...
# general
p
Is there a way to use docker's multi-stage inheritance with Dockerfiles split across multiple dockerfiles with pants? The examples of multi-stage/file builds I found on the blog explicitly copy files rather than inheriting
c
I know of docker’s multi-stage build, where you define multiple images in a single Dockerfile. Do you have a reference to the inheritance thing?
p
I'm thinking of that same functionality, but it would be nice ergonomically if I could write separate docker files and have pants stitch it together somehow
the inheritance piece ius using the previous image name in the from directive: https://docs.docker.com/build/building/multi-stage/
though I may be misunderstanding the docs
c
ok, yea you can define multiple
docker_image
targets in pants, and refer to the upstream image using it’s pants target address in the
FROM
instruction using a build arg: https://www.pantsbuild.org/docs/docker#dependency-inference-support
so it won’t be a multi-stage build in docker’s terms.. but rather a chain of individual builds
i.e. pants doesn’t do the Dockerfile stitching here.
p
thanks, I'll try that!
👍 1
it was a bit confusing that the ARG part of that invocation was critical, but it seems to work!
c
it’s to help make it clear when your FROM value is not a regular image name but a target address (and also in order for pants to be able to change it without actually touching the Dockerfile)
happy it worked, tho 🙂
p
btw, do you know if there is a plan to migrate pants to using BuildKit for building images? I got some warnings while running the package commands
c
you can do that now, using env vars and config etc. Pants only relies on a
docker build ..
cli command, so what ever your docker client is setup to do, it will. Just remember that you need to explicitly tell pants which env vars to use, as it’s hermetic by default and will strip the env down to a bare minimum.
p
ah, I see, thanks!
is it possible to hardcode the env var in a pants config somewhere?
c
yes, you use either the bare name to inherit the value, or set the value explicitly overriding in case it existed already
NAME=VALUE
.