In my pre-pants project I would build my docker im...
# general
c
In my pre-pants project I would build my docker image in my gitlab pipeline, tag it and push it to google's image repository. The image tags were created dynamically using a git commit ref. Now that im switching to pants package/publish for creating my image, is there a way to still dynamically tag my image? As far as I can tell the image_tag can only be set statically via the docker_image tag.
e
What I did, was to just build my images with a static, "well-defined" tag. ie.
docker_image(name="my_image", image_tags=["localtag"])
and then in CI, I just build the image with
pants package path/to:image
, and then run
docker image tag my_image:localtag $DYNAMIC_IMAGE_TAG
where
$DYNAMIC_IMAGE_TAG
is the full tag including
repo/image_name:tag
Other things you can do: •
image_tags=[env("LOCAL_TAG", "localtag")]
Now, your image will look for a
LOCAL_TAG
environment variable, and use that, with a default fallback of
"localtag"
• Use
.pants.bootstrap
to dynamically prepare environment variables, and then use those with
env
. See https://www.pantsbuild.org/blog/2024/04/27/simple-versioning-with-git-tags
c
sounds like a solid approach. Thanks again for the help Luke, I appreciate it!
e
No problem!