https://pantsbuild.org/ logo
b

bitter-orange-16997

02/28/2022, 3:28 PM
hey, anybody got a sample plugin to fill docker_image tags depending on environment variables at hand?
βœ… 1
e

enough-analyst-54434

02/28/2022, 3:36 PM
I think the feature you need is built in. See the "Tagging Images" docs here: https://www.pantsbuild.org/v2.10/docs/tagging-docker-images
h

happy-kitchen-89482

02/28/2022, 3:37 PM
Unfortunately it looks like the Docker example repo doesn't have examples of this
@curved-television-6568 when you return, something to add perhaps?
πŸ‘ 1
b

bitter-orange-16997

02/28/2022, 3:44 PM
well, right now the setup that works for me is with environment variables and mix of semver and pre-release plus a build number
says
1.0.1{buildargs.PRE_RELEASE_BUILD}
which gives
1.0.1-dev.1234
on develop and
1.0.1
on main
the whole issue is developper experience
h

happy-kitchen-89482

02/28/2022, 3:52 PM
Ah then I'm not understanding the question. Can you explain a little more about what the feature you'd like is, and how it's different from the built-in ability to tag via an env var?
b

bitter-orange-16997

02/28/2022, 3:57 PM
so, currently, we use
1.0.1{buildargs.PRE_RELEASE_BUILD}
as mentionned
to be precise,
{buildargs.COMPONENT_X_VERSION}{buildargs.PRE_RELEASE_BUILD}
we have a script that will populate
PRE_RELEASE_BUILD
as needed depending on the branch
but for all of this to work, we use a script that performs the branch-build mapping and we'd like that logic to be transparent
because right now this forces use to populate the environment before running any pants command
h

happy-kitchen-89482

02/28/2022, 4:07 PM
What is
buildargs
?
b

bitter-orange-16997

02/28/2022, 4:12 PM
sorry, I meant
build_args
as explained here
h

happy-kitchen-89482

02/28/2022, 4:19 PM
Oh I see, sorry, I thought this was some in-house construct. Right, makes sense.
So you want a plugin to compute the value of
PRE_RELEASE_BUILD
instead of having to set it outside of Pants?
b

bitter-orange-16997

02/28/2022, 4:21 PM
exactly, yes
or basically any pointer to something similar
it looks like something similar is fairly straight-forward for Python packages but I haven't had much success with Docker images
c

curved-television-6568

02/28/2022, 4:36 PM
What I've done is to source a β€œci-vars.sh” file from the β€œ./pants” bootstrap script. That way it is transparent both in dev and on ci pipeline run.
b

bitter-orange-16997

02/28/2022, 4:41 PM
that idea crossed my mind but thought I'd go for a cleaner approach
πŸ‘ 1
I think I'll do that as well unless I find a better way along the way
thanks
c

curved-television-6568

02/28/2022, 5:13 PM
If you find a cleaner way, please share ;)
h

happy-kitchen-89482

02/28/2022, 5:51 PM
A cleaner way might involve adding a plugin hook there
But TBH modifying the ./pants script seems pretty clean to me
You just have to remember to copy over the updates if you update
./pants
We could add an env-var setting hook in the standard
./pants
@bitter-orange-16997 that script lives in https://github.com/pantsbuild/setup/ if you want to send a pull request
So that future adopters of Pants can enjoy your work πŸ™‚
h

hundreds-father-404

02/28/2022, 5:54 PM
A concern I have there is it makes it harder to consume updates to the
./pants
script, you have to deal with merge conflicts now. Not the end of the world and seems viable for Benoit to work around this today, but I'm curious how else we could solve this before we memorialize changing
./pants
script
b

bitter-orange-16997

02/28/2022, 6:08 PM
well, yes. another issue is that that sort of versioning scheme affects all artifacts published (in most projects they follow a similar scheme, perhaps Docker images less so than other artifacts) and an ideal solution would integrate easily with all artifacts, including those handled by plugins
but well, this is good enough for now
h

happy-kitchen-89482

02/28/2022, 9:37 PM
We can add a hook into
./pants
that brings in env vars from a sidecar script, if it exists
c

curved-television-6568

03/08/2022, 9:26 AM
3 Views