Should this work? `pants.toml`: ```... [docker] bu...
# general
e
Should this work? `pants.toml`:
Copy code
...
[docker]
build_args.add = [
    "BASE_PYTHON_IMAGE=foo",
]
`pants.ci.toml`:
Copy code
...
[docker]
# Expose aws auth to docker.
build_args.add = [
    "AWS_DEFAULT_REGION",
    "AWS_ACCESS_KEY_ID",
    "AWS_SECRET_ACCESS_KEY",
    "AWS_SESSION_TOKEN",
]
`Dockerfile`:
Copy code
ARG BASE_PYTHON_IMAGE
FROM ${BASE_PYTHON_IMAGE}
...
Running in CI:
Copy code
$ export PANTS_CONFIG_FILES=pants.ci.toml
$ ./pants package docker/image:target
...
  failed to solve with frontend dockerfile.v0: failed to create LLB definition: base name (${BASE_PYTHON_IMAGE}) should not be blank
...
I've tried the various combos of
build_args
and
build_args.add
I guess I've experienced a version of this problem before: https://pantsbuild.slack.com/archives/C046T6T9U/p1642632985126400
When I try this (
COMMIT_SHA
is defined in
pant.toml
) with a build arg that I'm using in an image tag I get this error:
Copy code
Traceback (most recent call last):
    File "/github/home/.cache/pants/setup/bootstrap-Linux-x86_64/2.9.0+git57344e8f_py38/lib/python3.8/site-packages/pants/engine/internals/selectors.py", line 705, in native_engine_generator_send
      res = func.send(arg)
    File "/github/home/.cache/pants/setup/bootstrap-Linux-x86_64/2.9.0+git57344e8f_py38/lib/python3.8/site-packages/pants/backend/docker/goals/package_image.py", line 227, in build_docker_image
      tags = field_set.image_refs(
    File "/github/home/.cache/pants/setup/bootstrap-Linux-x86_64/2.9.0+git57344e8f_py38/lib/python3.8/site-packages/pants/backend/docker/goals/package_image.py", line 158, in image_refs
      image_names = tuple(
    File "/github/home/.cache/pants/setup/bootstrap-Linux-x86_64/2.9.0+git57344e8f_py38/lib/python3.8/site-packages/pants/backend/docker/goals/package_image.py", line 159, in <genexpr>
      ":".join(s for s in [repository, self.format_tag(tag, version_context)] if s)
    File "/github/home/.cache/pants/setup/bootstrap-Linux-x86_64/2.9.0+git57344e8f_py38/lib/python3.8/site-packages/pants/backend/docker/goals/package_image.py", line 98, in format_tag
      raise DockerImageTagValueError(msg) from e
  pants.backend.docker.goals.package_image.DockerImageTagValueError: Invalid tag value for the `image_tags` field of the `docker_image` target at src/infra/pipeline/annotator:annotator: '{build_args.COMMIT_SHA}'.
  
  The build arg 'COMMIT_SHA' is undefined. Defined build args are: AWS_ACCESS_KEY_ID, AWS_DEFAULT_REGION, AWS_ROLE_ARN, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_WEB_IDENTITY_TOKEN_FILE.
  
  This build arg may be defined in `pants.toml` under `[docker].build_args`, on the command line with `--docker-build-args` or directly on the `docker_image` target using the `extra_build_args` field.
f
Let’s first check whether your options are taking effect as intended. What’s the output of the following command (specifically for
--docker-build-args
?
Copy code
$ export PANTS_CONFIG_FILES=pants.ci.toml
$ ./pants help docker
(Pants should display the current value of the options in that subsystem.)
w
shouldn’t the syntax of
PANTS_CONFIG_FILES
be something more like
PANTS_CONFIG_FILES="+[pants.ci.toml]"
if the plan is to still load the default
pants.toml
?
h
Worth trying just in case, but IIRC a scalar value has the same effect (of adding the scalar to the list)
e
The options are not being merged with either syntax:
Copy code
$ PANTS_CONFIG_FILES=pants.ci.toml ./pants help docker | grep -A 12 docker-build-args
  --docker-build-args="[<shell_str>, <shell_str>, ...]"
  PANTS_DOCKER_BUILD_ARGS
  build_args
      default: []
      current value: [
          "AWS_DEFAULT_REGION",
          "AWS_ACCESS_KEY_ID",
          "AWS_ROLE_ARN",
          "AWS_SECRET_ACCESS_KEY",
          "AWS_SESSION_TOKEN",
          "AWS_WEB_IDENTITY_TOKEN_FILE"
      ] (from pants.ci.toml)
      Global build arguments (for Docker `--build-arg` options) to use for all `docker build`
$ PANTS_CONFIG_FILES="+['pants.ci.toml']" ./pants help docker | grep -A 12 docker-build-args
  --docker-build-args="[<shell_str>, <shell_str>, ...]"
  PANTS_DOCKER_BUILD_ARGS
  build_args
      default: []
      current value: [
          "AWS_DEFAULT_REGION",
          "AWS_ACCESS_KEY_ID",
          "AWS_ROLE_ARN",
          "AWS_SECRET_ACCESS_KEY",
          "AWS_SESSION_TOKEN",
          "AWS_WEB_IDENTITY_TOKEN_FILE"
      ] (from pants.ci.toml)
      Global build arguments (for Docker `--build-arg` options) to use for all `docker build`
$ ./pants help docker | grep -A 7 docker-build-args
  --docker-build-args="[<shell_str>, <shell_str>, ...]"
  PANTS_DOCKER_BUILD_ARGS
  build_args
      default: []
      current value: [
          "COMMIT_SHA",
          "BASE_PYTHON_IMAGE=foo"
      ] (from pants.toml)
Explicitly listing both also doesn't work:
Copy code
$ PANTS_CONFIG_FILES="['pants.toml', 'pants.ci.toml']" ./pants help docker | grep -A 12 docker-build-args
  --docker-build-args="[<shell_str>, <shell_str>, ...]"
  PANTS_DOCKER_BUILD_ARGS
  build_args
      default: []
      current value: [
          "AWS_DEFAULT_REGION",
          "AWS_ACCESS_KEY_ID",
          "AWS_ROLE_ARN",
          "AWS_SECRET_ACCESS_KEY",
          "AWS_SESSION_TOKEN",
          "AWS_WEB_IDENTITY_TOKEN_FILE"
      ] (from pants.ci.toml)
      Global build arguments (for Docker `--build-arg` options) to use for all `docker build`

$ PANTS_CONFIG_FILES="['pants.ci.toml', 'pants.toml']" ./pants help docker | grep -A 7 docker-build-args
  --docker-build-args="[<shell_str>, <shell_str>, ...]"
  PANTS_DOCKER_BUILD_ARGS
  build_args
      default: []
      current value: [
          "COMMIT_SHA",
          "BASE_PYTHON_IMAGE=foo"
      ] (from pants.toml)
      Global build arguments (for Docker `--build-arg` options) to use for all `docker build`
Would it be better to file a github issue?
f
yes since Slack history will be lost at some point.
(and moreover, easier to allocate work that way)
e
Will do. Mostly wanted to confirm (which I think I have) that is is actually a bug and not just user error 🙂