Trying to package my project’s Docker image but I ...
# general
q
Trying to package my project’s Docker image but I get this error about
--test-extra-env-var
, which seems completely unrelated
Copy code
% pants --no-pantsd package src/my-project:docker-base-image
01:51:15.56 [ERROR] 1 Exception encountered:

Engine traceback:
  in `package` goal

ValueError: An invalid variable was requested via the --test-extra-env-var mechanism: {PIP_EXTRA_INDEX_URL:
Relevant sections from the
pants.toml
file:
Copy code
[docker]
build_verbose = "True"
env_vars = [
  "HOME",
  "DOCKER_CONFIG=%(homedir)s/.docker",
  "DOCKER_CONTEXT=default",
  "NEXUS_USER",
  "NEXUS_PWD",
]
tools = ["docker-credential-ecr-login", "sh"]

[docker.registries.my-company-aws]
address = "<AWS ECR URL>"

[docker.build_args]
PIP_EXTRA_INDEX_URL = "<INTERNAL NEXUS REPO URL>"
1
b
Sorry for the trouble. That does seem unrelated... Have you configured anything in the
[test]
subsection? And/or are there any other search results for
PIP_EXTRA_INDEX_URL
in your configuration/repository?
q
The
test
subsections in
pants.toml
looks like this
Copy code
[test]
output = "all"
use_coverage = true

[coverage-py]
report = ["console", "xml", "html"]
and
PIP_EXTRA_INDEX_URL
appears in my project’s BUILD file as
Copy code
docker_image(
    name="docker-base-image",
    repository="my-project-base",
    source="docker/base/Dockerfile",
    context_root="./",
    dependencies=[
        ":files",
    ],
    extra_build_args=["PIP_EXTRA_INDEX_URL"],
    registries=[
        "@my-company-aws",
    ],
    image_tags=["latest"],
)
and in the
Dockerfile
as
Copy code
...
ARG PIP_EXTRA_INDEX_URL
...
b
Ah hm. This definitely sounds peculiar. Can you create a standalone reduced reproduction that you can share?
q
b
Thanks, I can reproduce with
NEXUS_USER=a NEXUS_PWD=b pants package src/my-project:docker-base-image
. If you have time, reducing it even further would be useful, to remove everything except what is required to reproduce the problem (e.g. it seems like a bunch of the env var configuration in
pants.toml
could be removed or simplified). Also, it'd be good to try it with the latest versions of pants (
2.21.0
is the latest stable, and
2.22.0a0
is the latest dev release): maybe they have fixed the problem or improved the error message!
q
I’ve tried with 2.21 and get the same result. I’ll try to further cleanup but I doubt I’ll get a different result because it doesn’t look like they contribute to the issue, for or otherwise (I might be wrong, I hope I am wrong 😛 because I’m stuck with this for days now 😞 ).
b
Yeah, the goal is to keep the error as it is, but get to a minimal reproducer with no "distracting"/"irrelevant" elements. That is, focus on exactly the problem, so we can help you debug more easily. (Btw, did you try 2.22.0a0 too?)
q
Haven’t tried 2.22.0a0. I’ll give that a shot too.
Pushed a slightly more reduced pants.toml. Also tried 2.22.0a0 and the error message is a bit different
Copy code
% pants package src/my-project:docker-base-image
11:18:55.26 [ERROR] Expected build_args to contain an 'add' element, a 'remove' element or both but found: {"PIP_EXTRA_INDEX_URL": String("<SOME_URL_HERE>")}


Use --print-stacktrace for more error details and/or -ldebug for more logs. 
See <https://www.pantsbuild.org/2.22/docs/using-pants/troubleshooting-common-issues> for common issues.
Consider reaching out for help: <https://www.pantsbuild.org/community/getting-help>
b
Ah, I think
[docker].build_args
expects a list, not key/value pairs. https://www.pantsbuild.org/2.21/reference/subsystems/docker#build_args So, the error message was very bad, and is now merely just quite bad. Does this work?
Copy code
[docker]
...
build_args = ["PIP_EXTRA_INDEX_URL=<SOME_URL_HERE>"]
q
Yes, this works! (in the example repo at least) Let me try this in my actual project and report back 🙂
Update, this issue has been resolved. Thanks Huon! Should we file a ticket to update the not-so-useful error message?
b
Nice one. Yeah, an issue about "list" options having bad error messages when used like a "dict" would be good, with this as a motivating example
q
b
Thank you!