https://pantsbuild.org/ logo
#general
Title
# general
m

modern-wolf-36228

11/26/2021, 2:24 PM
Is there an example of custom docker tag plugin?
c

curved-television-6568

11/26/2021, 2:58 PM
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

modern-wolf-36228

11/26/2021, 3:02 PM
the double
docker_image
confused me, wait
c

curved-television-6568

11/26/2021, 3:02 PM
What’s your use case you’re trying to solve?
m

modern-wolf-36228

11/26/2021, 3:02 PM
custom tag using pipeline unique id
ur solution is what I want
the easy one
c

curved-television-6568

11/26/2021, 3:03 PM
great 🙂
m

modern-wolf-36228

11/26/2021, 3:03 PM
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

curved-television-6568

11/26/2021, 3:05 PM
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

modern-wolf-36228

11/26/2021, 3:05 PM
I have the exact same case
💯 2
and if I want to build locally, I need to have the env variable, right?
c

curved-television-6568

11/26/2021, 3:06 PM
Copy code
BUILD_NUMBER=0 ./pants ... # does the trick
m

modern-wolf-36228

11/26/2021, 3:08 PM
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

gifted-soccer-38559

12/01/2021, 5:12 PM
thanks for this thread! similar use-case here
💯 3
c

curved-television-6568

12/01/2021, 5:14 PM
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

happy-kitchen-89482

12/27/2021, 1:03 PM
Nice! Does this mean that the "Dynamically generated tags" callout beneath it is no longer accurate?
c

curved-television-6568

12/27/2021, 1:11 PM
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

happy-kitchen-89482

12/27/2021, 7:21 PM
LG I'll tweak the phrasing a little if that's OK, for consistency with the tone of the docs
👍 1
❤️ 1
c

curved-television-6568

12/27/2021, 7:24 PM
Absolutely
h

happy-kitchen-89482

12/27/2021, 7:39 PM
Done
Thanks!
c

curved-television-6568

12/27/2021, 7:40 PM
✍️
Nice 🙂
4 Views