Does anyone have an example where `docker_image` i...
# general
s
Does anyone have an example where
docker_image
is an dependency? Meaning that some other targets depend on a docker image. e.g. running tests using that image, building another image using it as a base image, etc.
b
Have you tried something and it’s not working as you expect?
In https://www.pantsbuild.org/docs/python-test-goal “Testing your packaging pipeline” there’s an example of using a packaged artefact. And towards the end of https://blog.pantsbuild.org/optimizing-python-docker-deploys-using-pants/ I think there’s examples of images depending on each other
s
Thank you, I saw this and its previous post, but both example have very simple Dockerfile just adding PEX. What is the good practice if docker build is slow (e.g. with many
apt-get install
)? I only want to rerun when necessary. A few options I can think of are 1. Single Dockerfile with separate layer and rely on docker build cache -> difficult to reuse cache in CI/CD and sometimes save/load are still slow when the final image is big. 2. Use pants caching: Two dockerfile,
Dockerfile-base
adds some specific tag (e.g.
-t apt-installs-latest
) and the next
Dockerfile-main
uses it (
FROM apt-installs-latest
). Pants dependency could be set so that building
Dockerfile-main
depends on
Dockerfile-base
. With
--change-from
, it could skip building
Dockerfile-base
if not changed. -> relying on tag seems brittle Any thoughts?
b
Pants doesn’t directly cache docker image layers at the moment, so relying on docker build cache is required either way, unfortunately. Some relevant issues if you want to track them: https://github.com/pantsbuild/pants/issues/18287 https://github.com/pantsbuild/pants/issues/15199
👀 1
(With pants 2.16, potentially one could use the new `adhoc_tool`/`shell_command` to export the docker layers to something pants can cache, but getting them back into docker reliably seems hard… maybe combined with the new experimental environments feature too… but that seems very fiddly)
s
Thank you so much! The issues are very relevant. I’ll look into them more.