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

helpful-ambulance-53940

11/24/2021, 9:20 AM
Hi, all 🙂 I am pretty new to pants. Currently we use pretty ugly shell scripts to build our python-images and tag them with a git-hash. Is there a way to do the same think with pants? Therefor, dynamically tagging docker_image-targets with some git/content state? Sry might be a very silly question..I already looked in the plugins section but I did not really know where to start.
c

curved-television-6568

11/24/2021, 9:38 AM
Hi! Currently you can provide build args to docker when building your images, which can be used for your
image_tags
or in a
LABEL
instruction for your image meta data. See https://www.pantsbuild.org/docs/tagging-docker-images#tagging-images As I fetch that link, I notice we need to update the docs for how you can incorporate build args for the image tags field as well.
🙌 1
What it could look like is basically:
Copy code
docker_image(name="my-image", image_tags=["{build_args.COMMIT_SHA}"])
And then when invoke pants with an extra build arg from the environment, for instance..
Copy code
export PANTS_DOCKER_BUILD_ARGS=COMMIT_SHA=12345
./pants package ...
Or directly on the command line
Copy code
export COMMIT_SHA=12314345
./pants --docker-build-args=COMMIT_SHA package ...
Or put the docker build args config in
pants.toml
.. See
./pants help docker
and
./pants help docker_image
for help on those parts.
h

helpful-ambulance-53940

11/24/2021, 10:53 AM
Thank you very much 🙂
👍 1
c

clean-night-52582

11/24/2021, 12:27 PM
Is there a good way to tag docker images to current git tag? similar to how it's done with
python_distribution
Can write another plugin
c

curved-television-6568

11/24/2021, 1:17 PM
There’s currently no additional magic more than described above.. For
python_distribution
are you referring to the use of
SetupPythonKwargs
in a plugin?
c

clean-night-52582

11/25/2021, 6:27 PM
Yes
c

curved-television-6568

11/26/2021, 9:16 AM
I notice we need to update the docs for how you can incorporate build args for the image tags field as well.
Done, for the 2.9 version of the docs. https://www.pantsbuild.org/v2.9/docs/tagging-docker-images#tagging-images
3 Views