Hi I have a pants docker question. I would like to...
# general
c
Hi I have a pants docker question. I would like to be able to decide at run time (when I run ./pants publish ::) which docker registry to push to. My use case is that on CI I want it to push to prod registry, and on dev machines to push to some staging registry. Is this something that is supported? It seems like the registry is statically defined in pants.toml and I don’t see any mention in the docs on how to switch default registry via env var at run time.
One idea that might solve this is to be able to set conditionals based on runtime value. Something like
Copy code
[docker.registries.prod]
address = "prod-registry"
default = (if %{env_var.prod} then true else false)

[docker.registries.staging]
address = "staging-registry"
default = (if %{env_var.prod} then false else true)
But I don’t think conditionals are supported at the moment
e
h
You can set any pants option via flag, env var or config
If you want to do different things in CI then having a pants.ci.toml that augments the standard pants.toml, and pointing to it via PANTS_CONFIG_FILES, is the idiomatic way to do this
c
I see. Thanks for that answer, that makes sense. From the above, I should have 2 config, one for ci, which pushes to prod registry, and one staging config, which pushes to a staging registry. I have a follow up which might really be specific to how my org do testing, and is a slightly different situation from the original question: The problem is we don’t have one staging registry, but every dev will have their own AWS ECR registry that they build and push to do their testing. This means I can’t check in one staging pants.ci.toml and have this work for every dev. A wishful thinking would be for the registry address to be overwrite-able based on an env var. So the logic at runtime for evaluating the registry address would be: If an env var is not set, use the registry address in pants.ci.toml If it is defined, then use what is define and overwrite the specific registry address. Maybe the latter is possible?
e
You can stick to the CI approach theme if that works: https://www.pantsbuild.org/docs/options#pantsrc-file
c
Oh nice. This looks very promising. I’ll give it a go. Thank you so much for both your help @enough-analyst-54434 @happy-kitchen-89482