refined-addition-53644
08/31/2022, 2:28 PMbuild_arg
to have some default value. The use case is we set such env vars only in our CI/CD but for local run it can be any random value.
https://www.pantsbuild.org/docs/tagging-docker-images#using-env-vars-to-include-dynamic-data-in-tagsrefined-addition-53644
08/31/2022, 2:29 PMcurved-television-6568
08/31/2022, 2:49 PMcurved-television-6568
08/31/2022, 2:51 PMrefined-addition-53644
08/31/2022, 2:51 PMbuild_args
in pants. Pants will complain currently
16:50:37.01 [ERROR] 1 Exception encountered:
DockerBuildContextError: Undefined value for build arg on the src/pyfleet-charge-plan:charge_plan_image target: The Docker environment variable 'ECR_REPO_URI' is undefined. You may provide a value for this variable either in `[docker].env_vars` or in Pants's own environment.
If you did not intend to inherit the value for this build arg from the environment, provide a default value with the option `[docker].build_args` or in the `extra_build_args` field on the target definition. Alternatively, you may also provide a default value on the `ARG` instruction directly in the `Dockerfile`.
curved-television-6568
08/31/2022, 2:52 PMcurved-television-6568
08/31/2022, 2:53 PMcurved-television-6568
08/31/2022, 2:53 PMrefined-addition-53644
08/31/2022, 2:54 PMcurved-television-6568
08/31/2022, 2:54 PMcurved-television-6568
08/31/2022, 2:55 PMbuild_args
or extra_build_args
(if without value, it will default to the default given in the Dockerfile, if any)refined-addition-53644
08/31/2022, 2:58 PMFROM public.ecr.aws/docker/library/python:3.9.13-slim-bullseye
ARG GIT_COMMIT '123'
ARG ECR_REPO_URI 'test.repo'
• pants.toml
[docker]
build_args = ["GIT_COMMIT", "ECR_REPO_URI"]
nutritious-hair-72580
11/24/2022, 12:44 PMcurved-television-6568
11/24/2022, 12:48 PMpants
script there’s an option to provide a .pants.bootstrap
script that can setup local env vars for you before invoking pants (name is customizable): https://github.com/pantsbuild/setup/blob/ab8581bb52d92fcb3fda1b1dfb20204ae8888a90/pants#L19-L23
so you can have:
# .pants.bootstrap
: ${GIT_COMMIT:=$(git rev-parse HEAD)}
to set GIT_COMMIT if not already set.nutritious-hair-72580
11/24/2022, 12:48 PMcurved-television-6568
11/24/2022, 12:48 PMcurved-television-6568
11/24/2022, 1:00 PM