Hi, what would be the way to use env variable for ...
# general
r
Hi, what would be the way to use env variable for generating docker repository name? During our CI/CD on AWS we fetch the region and the account id to push the image to different deployment env (staging/production) ECR repository. So it can’t be a static name. https://www.pantsbuild.org/docs/tagging-docker-images#setting-a-repository-name
1
c
If you go with a
build_arg
you can provide the value for that arg as an ENV variable..
Does that make sense to you? otherwise I can elaborate 😉
r
yeah I was guessing that would be the case. It’s just setting all these build_arg means I need to set them everywhere i.e. even locally. Otherwise pants will complain. I guess I should write a plugin where I check for the
build_arg
specific ENV variable and use default values when running locally. Do you think it’s possible to do that using plugin for
docker_image
?
I am talking about this suggestion for adding extra tags https://www.pantsbuild.org/docs/tagging-docker-images#providing-additional-image-tags-with-a-plugin Can this be modified to read these env vars passed using
build_arg
?
c
The tags plugin example will only be able to provide custom tags, not affect the build_args or repository name..
for posterity (at least a few months) this test case may be illustrative of using build args in tandem with env vars to customize the repository name: https://github.com/pantsbuild/pants/blob/11b4fd412631c6315b474e49fe482dec1767cf29/src/python/pants/backend/docker/goals/package_image_test.py#L[…]22
It’s just setting all these build_arg means I need to set them everywhere i.e. even locally. Otherwise pants will complain.
yea, well, using a bootstrap script, this may not be as painful as it sounds.
Copy code
# .pants.bootstrap
: ${CUSTOM_REPO:="local"}
https://github.com/pantsbuild/setup/blob/db310991388e3903b8b1356ed1a4e8747adfc925/pants#L20
(sorry pasted wrong link at first..)
with that bootstrap script in place, you can have the ENV var automatically populated for all local devs, while when provided by the CI system will take precedence when running the pipeline..
r
ok thanks! Will give this a try