Hi, all :slightly_smiling_face: I am pretty new to...
# general
h
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
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
Thank you very much 🙂
👍 1
c
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
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
Yes
c
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