Is there an example of custom docker tag plugin?
# general
m
Is there an example of custom docker tag plugin?
c
No, and that part is not easily plugged into, as-is.
For custom tags, the by far easiest is if it is possible to set the desired tag (or part of the tag) as an environment variable when invoking pants, then you can define that as a build arg and use it in the tag.
Copy code
docker_image(image_tags=["{build_args.MY_VAR}"])
then either in
pants.toml
or as extra build arg on the image itself:
Copy code
[docker]
build_args = ["MY_VAR"]
Copy code
docker_image(extra_build_args=["MY_VAR"])
Using a plugin, I think “easiest” would be to define a custom target, with a derived
image_tags
field, with custom logic applied to it.
m
the double
docker_image
confused me, wait
c
What’s your use case you’re trying to solve?
m
custom tag using pipeline unique id
ur solution is what I want
the easy one
c
great 🙂
m
ah
if I just use
docker_image(image_tags=["{<http://build_args.MY|build_args.MY>_VAR}"], extra_build_args=["MY_VAR"])
then it will work?
c
I have stuff like this (to attach the BUILD_NUMBER from jenkins to the image version)
Copy code
# pants.toml
[docker]
build_args=["BUILD_NUMBER"]
And then
Copy code
docker_image(image_tags=["1.0-{build_args.BUILD_NUMBER}"])
🙌 1
m
I have the exact same case
💯 2
and if I want to build locally, I need to have the env variable, right?
c
Copy code
BUILD_NUMBER=0 ./pants ... # does the trick
m
I guess the work to create a plugin is not worth it, so I'll do the same
👍 1
subscribed to that issue 🎉
thanks again @curved-television-6568 🙏
❤️ 1
g
thanks for this thread! similar use-case here
💯 3
c
OK, so we should consider adding a section about this to the docker docs, perhaps.. 🙂
2
💯 3
Added section with example for how to include dynamic data in the image tag when building a Docker image here: https://www.pantsbuild.org/v2.9/docs/tagging-docker-images#including-dynamic-data-in-the-image-tag-using-environment-variables cc @happy-kitchen-89482 you may want to review, thanks 😉
h
Nice! Does this mean that the "Dynamically generated tags" callout beneath it is no longer accurate?
c
Kind of, I changed the wording in it, to include the possibility for using env vars in combination with build args. But perhaps could be removed altogether..
h
LG I'll tweak the phrasing a little if that's OK, for consistency with the tone of the docs
👍 1
❤️ 1
c
Absolutely
h
Done
Thanks!
c
✍️
Nice 🙂