proud-appointment-36730
06/22/2022, 10:09 PMpants publish
to work for docker images being published to an AWS ECR repo. I think I got all the environment variables and $PATH
components wired in correctly, but no dice. I following the recommendation about using env -i
and actually got that to work, but it's not working through pants publish
for some reason. I set --level=trace
in my command, and it seems like I'm missing a ton of info about how docker push
is getting executed (i.e no indication of the sandbox directory, command args, etc in the log output). Any ideas?proud-appointment-36730
06/22/2022, 10:19 PMno basic auth credentials
, image builds fine. SO for some reason it seems like an auth issue but I'm stumped as to why my config file setup isn't wiring in the required environment variablesproud-appointment-36730
06/22/2022, 10:20 PM[docker]
default_repository = "build-system-demo-pants"
env_vars = [
# "DOCKER_CONFIG=build_support/docker/config",
"AWS_ACCESS_KEY_ID=<REDACTED>",
"AWS_SECRET_ACCESS_KEY=<REDACTED>",
"AWS_ECR_CACHE_DIR=/Users/me/code/build-system-demo/ecr-cache",
"DOCKER_CONFIG=/Users/me/code/build-system-demo/build_support/docker/config"
]
tools = [
"docker-credential-ecr-login",
"sh",
]
fast-nail-55400
06/22/2022, 10:44 PM--no-process-cleanup
to preserve the execution sandboxproud-appointment-36730
06/22/2022, 10:48 PMproud-appointment-36730
06/22/2022, 10:50 PM18:49:11.34 [INFO] Preserving local process execution dir /private/var/folders/1r/ndd87ylx3097l5pjbj1pgsch0000gp/T/process-executioniMMn2k for "Building docker image <http://137296740171.dkr.ecr.us-west-2.amazonaws.com/build-system-demo-pants:latest|137296740171.dkr.ecr.us-west-2.amazonaws.com/build-system-demo-pants:latest>"
And if I got there the __run.sh
script just has the build commands. No similar output or script for the push operationfast-nail-55400
06/22/2022, 11:06 PMInteractiveProcess
in Pants code) which means it runs differently than normal execution sandbox processesfast-nail-55400
06/22/2022, 11:08 PMproud-appointment-36730
06/23/2022, 1:38 AM{
"credHelpers": {
"<account-id>.<http://dkr.ecr.us-west-2.amazonaws.com|dkr.ecr.us-west-2.amazonaws.com>": "ecr-login"
}
}
happy-kitchen-89482
06/23/2022, 6:23 AMcurved-television-6568
06/23/2022, 8:13 AMenv -i
So my question then would be, what env vars was used in that case? The exact same set of env vars as listed in the pants.toml
file?
What did you provide as PATH
?
I think a key component here may be a mistake to provide the path directly to a binary where there also are other binaries, so those are āleakedā into the sandboxed environment.
To test this properly, you need a temporary bin
folder, from which you can link all your binaries/tools and then point your PATH
to that temp bin
so all that is visible on the path are explicitly only those linked files and nothing else.curved-television-6568
06/23/2022, 8:16 AMproud-appointment-36730
06/23/2022, 1:37 PMproud-appointment-36730
06/23/2022, 1:41 PM#!/bin/bash
echo "<account-id>.<http://dkr.ecr.us-west-2.amazonaws.com|dkr.ecr.us-west-2.amazonaws.com>" | env -i \
PATH=/tmp/path-isolated \
AWS_ECR_CACHE_DIR=/Users/kyle/kairos/build-system-demo/ecr-cache \
AWS_ACCESS_KEY_ID=<REDACTED> \
AWS_SECRET_ACCESS_KEY=<REDACTED> \
DOCKER_CONFIG=/Users/kyle/kairos/build-system-demo/build_support/docker/config \
docker-credential-ecr-login get
proud-appointment-36730
06/23/2022, 1:42 PM/tmp/path-isolated
:
$ l /tmp/path-isolated
total 0
lrwxr-xr-x 1 kyle wheel 42B Jun 22 17:59 docker-credential-ecr-login@ -> /usr/local/bin/docker-credential-ecr-login
lrwxr-xr-x 1 kyle wheel 7B Jun 22 17:59 sh@ -> /bin/sh
proud-appointment-36730
06/23/2022, 1:43 PMPATH
environment variable in my pants.toml
file thoughcurved-television-6568
06/23/2022, 1:44 PMOh, I didnāt provide aThat you should get from theenvironment variable in myPATH
file thoughpants.toml
tools
section for you, so not the issue..curved-television-6568
06/23/2022, 1:44 PMPATH
to the env vars would blow a big whole but ought to work, as workaround for now, if nothing else.curved-television-6568
06/23/2022, 1:45 PMcurved-television-6568
06/23/2022, 1:49 PMproud-appointment-36730
06/23/2022, 1:55 PMdocker push
command is running in and interactively debug? Or could I run some one-off shell commands in the environment the docker push
command is running in to inspect it? I took a look at the pants code, what's the reasoning for using an InteractiveProcess
to run the docker push
? The fact that I can't use --no-process-cleanup
to drop into the environment and figure out what's going on is making this a little trickycurved-television-6568
06/23/2022, 2:56 PMInteractiveProcess
for this atm, perhaps @witty-crayon-22786 has an answer for that.curved-television-6568
06/23/2022, 2:58 PMcurved-television-6568
06/23/2022, 2:59 PMPATH
to the [docker].env_vars
ought to punch through any obstacles though⦠to get unblocked for now, if acceptable.fast-nail-55400
06/23/2022, 3:05 PMIs there any way to hook into the environment that theIt will be more convoluted, but you can by modifying Pants source for the rules to add what options you need. So maybe increase `docker`ās log level for the push to get more info. Checkout a copy of Pants in a sibling directory to your repo and add acommand is running in and interactively debug?docker push
pants_from_sources
script from one of the pantsbuild/example-* repos on GitHub.
Then modify https://github.com/pantsbuild/pants/blob/adc76b4dd0b85feb6fbfcb6ed735e292244fe3ff/src/python/pants/backend/docker/util_rules/docker_binary.py#L96 to add --log-level=debug
option to the push command line. Then run ./pants_from_sources
in your repo instead of ./pants
.fast-nail-55400
06/23/2022, 3:07 PMdocker push
command line used. But for now, the above procedure will at least get you more information.)curved-television-6568
06/23/2022, 3:08 PMdocker
shim, put that on your path so Pants picks it up instead of the real docker binary. That way you can debug everything via that shim.curved-television-6568
06/23/2022, 3:08 PMPANTS_DOCKER_EXECUTABLE_SEARCH_PATHS
.fast-nail-55400
06/23/2022, 3:09 PMfast-nail-55400
06/23/2022, 3:09 PMproud-appointment-36730
06/23/2022, 3:11 PMpants publish
is actually using the environment variables in my config file. If it were, it would be writing to the log file in /Users/kyle/kairos/build-system-demo/ecr-cache
. When using the env -i
approach, I can see logs get streamed in if I tail -f
the log file. When using pants, no logs arrivecurved-television-6568
06/23/2022, 3:12 PMproud-appointment-36730
06/23/2022, 3:13 PMcurved-television-6568
06/23/2022, 3:14 PMcurved-television-6568
06/23/2022, 3:23 PMenv_vars
seems to be picked up, verified using the docker shims technique..
$ PANTS_DOCKER_EXECUTABLE_SEARCH_PATHS='["/Users/x/src/tmp/shims"]' PANTS_DOCKER_ENV_VARS='["foo=bar", "LOGNAME"]' ./pants publish testprojects/src/python/docker:test-example
17:21:58.70 [INFO] Starting: Building docker image test-example:1.2.5
17:21:58.71 [INFO] Canceled: Building docker image test-example:1.2.5
17:21:59.10 [INFO] Starting: Building docker image test-example:1.2.5
17:21:59.12 [INFO] Completed: Building docker image test-example:1.2.5
17:21:59.13 [INFO] Built docker image: test-example:1.2.5
DOCKER SHIM!!
Env:
PWD=/private/tmp/.tmpBzbEdb
foo=bar
SHLVL=1
LOGNAME=x
_=/usr/bin/env
exec: docker push test-example:1.2.5
ā test-example:1.2.5 published.
And in `ā¦/shims/docker`:
#!/bin/bash
echo "DOCKER SHIM!!"
echo "Env:"
/usr/bin/env
echo "exec: docker $@"
proud-appointment-36730
06/23/2022, 3:38 PMcurved-television-6568
06/23/2022, 3:39 PMproud-appointment-36730
06/23/2022, 3:45 PMproud-appointment-36730
06/23/2022, 4:06 PM[docker].tools
entirely from my configcurved-television-6568
06/23/2022, 4:17 PMproud-appointment-36730
06/23/2022, 4:18 PM$ ./pants --version
12:17:53.96 [INFO] Initializing scheduler...
12:17:54.28 [INFO] Scheduler initialized.
2.11.0
proud-appointment-36730
06/23/2022, 4:29 PM[docker]
default_repository = "build-system-demo-pants"
env_vars = [
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"DOCKER_CONFIG='%(buildroot)s/build_support/docker/config'",
"AWS_ECR_CACHE_DIR='%(buildroot)s/build_support/docker/ecr-cache'",
]
tools = [
"sh",
]
I gotcha that I think is very interesting to note is that doing the following does not work:
[docker]
default_repository = "build-system-demo-pants"
env_vars = [
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"DOCKER_CONFIG='%(buildroot)s/build_support/docker/config'",
"AWS_ECR_CACHE_DIR='%(buildroot)s/build_support/docker/ecr-cache'",
]
tools = [
"sh",
"docker-credential-ecr-login",
]
So for some reason shimming in the credential helper in the case of ECR breaks things, and docker can't find the credentials it needproud-appointment-36730
06/23/2022, 4:35 PMPANTS_DOCKER_EXECUTABLE_SEARCH_PATHS="['/Users/kyle/shims/']"
, then the code will look for all the values in the [docker].tools
part of the config in /Users/kyle/shims
. Not sure if this is intended behavior or not, just wanted to point it out for anyone else who is trying to get ECR stood up and/or debug docker commands and stumbles on this threadcurved-television-6568
06/23/2022, 4:42 PM"<PATH>"
at the end there, to have it do a wider search, only looking in the shims dir first)hundreds-father-404
06/23/2022, 6:20 PMcurved-television-6568
06/23/2022, 6:42 PM[docker].tools
, but started working without.hundreds-father-404
06/23/2022, 6:43 PMcurved-television-6568
06/23/2022, 6:44 PMproud-appointment-36730
06/23/2022, 7:14 PM[docker].tools
because the docs (which have the google credential helper as an example) have it in there. Maybe explaining the edge case for ECR, or recommending to start with it empty and only add things in as needed, would be a helpful addition?fast-nail-55400
06/23/2022, 7:39 PMdocs/markdown/Docker/
proud-appointment-36730
06/23/2022, 7:39 PMproud-appointment-36730
06/23/2022, 8:34 PMflat-summer-8204
06/28/2022, 2:46 PMfast-nail-55400
06/28/2022, 2:56 PMecr-login.log
under the logs
directory in the ECR cache dir. (As suggested by the source code at https://github.com/awslabs/amazon-ecr-credential-helper/blob/main/ecr-login/config/log.go.)proud-appointment-36730
06/28/2022, 2:58 PMfast-nail-55400
06/28/2022, 4:34 PMAWS_ECR_CACHE_DIR
in [docker].env_vars
. Then the log should go in the logs
subdirectory of that directory.fast-nail-55400
06/28/2022, 4:35 PM~/.ecr/logs
but would require HOME
to be passed into the execution sandbox so the code can expand the path. https://github.com/awslabs/amazon-ecr-credential-helper/blob/e6f29200ae0450ba6584aee3041e2527e4ce1873/ecr-login/config/cache_dir.go#L22proud-appointment-36730
07/01/2022, 6:14 PM