Is there a way to set a default value for docker b...
# general
a
Is there a way to set a default value for docker build arguments with fallback to environment variables, e.g. for CI?
Copy code
docker_image(
    name="my-service",
    registries=["@my_registry"],
    image_tags=["{build_args.EXPECTED_TAG}"]
)
When I build this image locally I would prefer to fallback to
latest
, e.g. only type
pants package /path/to/service/Dockerfile
but in CI I might provide it as
EXPECTED_TAG=1.0.2 pants package /path/to/service/Dockerfile
. I've tried setting it in the docker_env_vars, but subsequently exposing it in the shell does not seem to have precedence over this. If I don't provide the EXPECTED_TAG the build errors out about missing variables.
r
c
you can also provide the builld arg with a value in your
Dockerfile
that way you have a very low prio default value that pants will replace with anything else you provide.
a
I didn't think about using
.pants.rc
. I'm not sure it fits the bill here since it can't be overridden using a command line env-var, but it could have other uses, so I appreciate the suggestion. I think you're right @curved-television-6568. This does serve as a nice fallback that can be easily overridden on the command line!
👍 1