Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List typed config values can not be merged between multiple config files (PANTS_CONFIG_FILES) #14679

Closed
mpcusack-color opened this issue Mar 2, 2022 · 18 comments · Fixed by #14850
Labels

Comments

@mpcusack-color
Copy link

Describe the bug
Originally asked in https://pantsbuild.slack.com/archives/C046T6T9U/p1646199988870439

No matter the syntax I am unable to get docker build args list merging to work.

Pants version
2.9.0

OS
Linux

Additional info

pants.toml:

...
[docker]
build_args.add = [
    "BASE_PYTHON_IMAGE=foo",
]

pants.ci.toml:

...
[docker]
# Expose aws auth to docker.
build_args.add = [
    "AWS_DEFAULT_REGION",
    "AWS_ACCESS_KEY_ID",
    "AWS_SECRET_ACCESS_KEY",
    "AWS_SESSION_TOKEN",
]

Dockerfile:

ARG BASE_PYTHON_IMAGE
FROM ${BASE_PYTHON_IMAGE}
...

Running in CI:

$ 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
...
@mpcusack-color
Copy link
Author

Some more examples:

$ 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)

$ 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`

@mpcusack-color
Copy link
Author

Merging from env seems to work:

PANTS_DOCKER_BUILD_ARGS="+['aaa=bbb']" ./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",
          "aaa=bbb"

@benjyw
Copy link
Contributor

benjyw commented Mar 3, 2022

FWIW this also works:

pants.toml
-----------
[docker]
build_args.add = ["foo=bar"]


$ ./pants help docker --build-args="baz=qux"
<snip>
--docker-build-args="[<shell_str>, <shell_str>, ...]"
  PANTS_DOCKER_BUILD_ARGS
  build_args
      default: []
      current value: [
          "foo=bar",
          "baz=qux"
      ] (from pants.toml, from command-line flag)
</snip>

@benjyw
Copy link
Contributor

benjyw commented Mar 3, 2022

OK, I can reproduce this at HEAD, and it's definitely a bug.

@benjyw
Copy link
Contributor

benjyw commented Mar 3, 2022

It appears to be a bug in the options system (!) not specifically in the docker subsystem.

@mpcusack-color
Copy link
Author

Yes, I experience the same thing with [GLOBAL] plugins. Glad it's not just me :-).

@benjyw
Copy link
Contributor

benjyw commented Mar 3, 2022

This appears to be working as intended in some sense, but only because we didn't think of this case, apparently.

@mpcusack-color
Copy link
Author

As intended? I thought the point of foo.add = [...] was to support this? It seems like that's being ignored currently.

@benjyw
Copy link
Contributor

benjyw commented Mar 3, 2022

That works across defaults/env vars/config/flags, but the current semantics of multiple config files is that later files override the values in earlier files, so that only one value per set of config files is presented to the options system.

But the fact that you expected it to work differently, and I did too (and I wrote the options system back in the day) tells me that the existing logic is not good.

@benjyw
Copy link
Contributor

benjyw commented Mar 3, 2022

The complication is that we parse config files before we know the type of the option, going to have to think about what to do here.

@mpcusack-color
Copy link
Author

Thanks for the explanation. Makes sense.

Another use case/motivation:
Enabling certain plugins just for your local setup.

pants.toml:

[GLOBAL]
backend_packages.add = [
    "pants.backend.python",
    "pants.backend.python.lint.black",
    "pants.backend.python.lint.isort",
    "pants.backend.python.lint.pylint",
    "pants.backend.codegen.protobuf.python",
    "pants.backend.python.mixed_interpreter_constraints",
    "pants.backend.python.typecheck.mypy",
    "pants.backend.shell",
    "pants.backend.shell.lint.shfmt",
    "pants.backend.shell.lint.shellcheck",
    "pants.backend.docker",
    "pants.backend.docker.lint.hadolint",
]

~/.config/pants.toml (enabled via PANTS_CONFIG_FILES in .bashrc):

backend_packages.add = [
    "pants.backend.experimental.python.lint.autoflake",
    "pants.backend.experimental.python.lint.pyupgrade",
]

@mpcusack-color
Copy link
Author

I guess one potential short term workaround is to move away from PANTS_CONFIG_FILES pointing to a secondary toml in these situations, and instead just set the overrides using all env vars. e,g, PANTS_BACKEND_PACKAGES="+['pants.backend.experimental.python.lint.autoflake', 'pants.backend.experimental.python.lint.pyupgrade']".

@mpcusack-color mpcusack-color changed the title Can not merge docker build_args List typed config values can not be merged between multiple config files (PANTS_CONFIG_FILES) Mar 3, 2022
@Eric-Arellano
Copy link
Contributor

@benjyw possibly a duplicate of #14679 btw, re: what to close once this is fixed.

@kaos kaos removed their assignment Mar 8, 2022
@kaos
Copy link
Member

kaos commented Mar 8, 2022

Unassigning myself, due to

It appears to be a bug in the options system (!) not specifically in the docker subsystem.

benjyw added a commit to benjyw/pants that referenced this issue Mar 18, 2022
Fixes pantsbuild#14679

[ci skip-rust]

[ci skip-build-wheels]
benjyw added a commit to benjyw/pants that referenced this issue Mar 19, 2022
Fixes pantsbuild#14679

[ci skip-rust]

[ci skip-build-wheels]
benjyw added a commit to benjyw/pants that referenced this issue Mar 20, 2022
Fixes pantsbuild#14679

[ci skip-rust]

[ci skip-build-wheels]
benjyw added a commit to benjyw/pants that referenced this issue Mar 27, 2022
Fixes pantsbuild#14679

[ci skip-rust]

[ci skip-build-wheels]
benjyw added a commit to benjyw/pants that referenced this issue Mar 28, 2022
Fixes pantsbuild#14679

[ci skip-rust]

[ci skip-build-wheels]
benjyw added a commit to benjyw/pants that referenced this issue Mar 28, 2022
Fixes pantsbuild#14679

[ci skip-rust]

[ci skip-build-wheels]
@benjyw
Copy link
Contributor

benjyw commented Mar 28, 2022

@mpcusack-color thanks for reporting this! It's now fixed in #14850 which will go into Pants 2.12.0.

Note that with the fix, putting just the add/remove values in a @fromfile works as you'd expect.

@stuhood
Copy link
Member

stuhood commented Mar 29, 2022

We could probably also cherry-pick it to 2.11.x if needed?

@benjyw
Copy link
Contributor

benjyw commented Mar 29, 2022

It builds on a bunch of other changes, so it might be complicated to cherry-pick

@stuhood
Copy link
Member

stuhood commented Mar 29, 2022

It builds on a bunch of other changes, so it might be complicated to cherry-pick

Yea, I guess that more has landed since 2.11.x was cut than I realized. Thanks!

@benjyw benjyw reopened this Apr 1, 2022
@benjyw benjyw closed this as completed Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants