hundreds-carpet-28072
10/24/2023, 11:10 AMdocker_image
targets, would it be useful/are there any plans to include a version
property and for this to be available as a placeholder {version}
for tagging? This would be useful for more complex tag formats e.g. if I wanted to add build and commit info into version tags like so for every docker image that would be built: reg.address/docker/repo:v1.2-build5-fd6s82hr
It would also be useful to be able to set the image_tags
in pants.toml
if the format is consistent for an entire registry. This could then use the {version}
placeholder (+ env vars) to create tag formats like:
[docker.registries.reg0]
image_tags = ["{version}-build{BUILD_NUM}-{GIT_COMMIT}"]
Currently to do the above I’d have to set up a plugin or set that format for every docker_image
target AFAIK. Are there any plans for something close to this or should I look to just write a plugin for now? 🙂curved-manchester-66006
10/24/2023, 1:05 PMdocker_image
today. <https://www.pantsbuild.org/docs/macros>
snippet:
commit_sha = env("CI_COMMIT_SHA")
if commit_sha:
image_tags.append(commit_sha)
extra_build_args.append(f"COMMIT_SHA={commit_sha}")
if env("CI_COMMIT_SHORT_SHA"):
image_tags.append(env("CI_COMMIT_SHORT_SHA"))
if env("CI_COMMIT_REF_PROTECTED") == "true":
image_tags.append(f"protected-{env('CI_COMMIT_SHA')}")
if env("CI_COMMIT_BRANCH") == "main":
image_tags.append("latest")
curved-television-6568
10/24/2023, 1:39 PMimage_tags
in pants.toml
see extra_image_tags
here: https://www.pantsbuild.org/docs/tagging-docker-images#configuring-registrieshundreds-carpet-28072
10/24/2023, 1:42 PMdocker_image
target image_tags
. So I guess my second suggestion was more around best practice.hundreds-carpet-28072
10/24/2023, 1:44 PMI think you could do that with a macro aroundtoday. <https://www.pantsbuild.org/docs/macros>docker_image
snippet:
``` commit_sha = env("CI_COMMIT_SHA")
if commit_sha:
image_tags.append(commit_sha)
extra_build_args.append(f"COMMIT_SHA={commit_sha}")
if env("CI_COMMIT_SHORT_SHA"):
image_tags.append(env("CI_COMMIT_SHORT_SHA"))
if env("CI_COMMIT_REF_PROTECTED") == "true":
image_tags.append(f"protected-{env('CI_COMMIT_SHA')}")
if env("CI_COMMIT_BRANCH") == "main":
image_tags.append("latest")```Interesting, I’ll try that out. It would have to depend on registry selected which I’m not sure is possible but I’ll test it out, thanks.
curved-television-6568
10/24/2023, 1:45 PMextra
was meant to highlight the fact that it doesn’t replace any image tags on the docker_image
but adds to them. Perhaps additional_image_tags
would’ve been better, but that’s getting unwieldy.. 😛hundreds-carpet-28072
10/24/2023, 1:47 PM{name}
curved-television-6568
10/24/2023, 1:50 PMenv
) — so it is not clear to me what beyond that you are suggesting (besides easier to use syntax?)hundreds-carpet-28072
10/24/2023, 1:55 PMdocker_image
target, in the same way that {name}
does but for the version of the image. But currently docker_image
doesn’t have a version property, so 2 would be adding that version property.
I was wondering if this sounds like anything would be possible in future, basically. As I’m happy to write a plugin that does it for me for now if need be. :)hundreds-carpet-28072
10/24/2023, 1:56 PMcurved-television-6568
10/24/2023, 2:13 PMdocker_image(
extra_build_args=["VERSION=1.2"],
image_tags=["{build_args.VERSION]"],
)
so, it’s not in a dedicated field, but it is set on the target..