clever-father-91273
03/10/2023, 12:53 PMpants publish in Google Cloud Build. I'm getting the following error:
unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials
However, this does not seem to be the case, since if I only use Pants to build the image (pants package), I can then push them with docker push, so the credentials seem to be in place. The ~/.docker/config.json also looks correct. What am I missing here?gorgeous-winter-99296
03/10/2023, 1:16 PMgorgeous-winter-99296
03/10/2023, 1:16 PMclever-father-91273
03/10/2023, 1:17 PMgorgeous-winter-99296
03/10/2023, 1:31 PMclever-father-91273
03/10/2023, 1:33 PMgorgeous-winter-99296
03/10/2023, 1:33 PMclever-father-91273
03/10/2023, 1:35 PMgorgeous-winter-99296
03/10/2023, 2:52 PMpackage + push works, is that using the same scripted flow? Does pants publish work locally?happy-kitchen-89482
03/10/2023, 3:03 PM~/.docker/config.json ?happy-kitchen-89482
03/10/2023, 3:04 PMcurved-television-6568
03/10/2023, 3:47 PMclever-father-91273
03/10/2023, 3:51 PMpackage + push work and publish doesn't, I run both in a Google Cloud Build pipeline
⢠The creds are in ~/.docker/config.json. I make sure this is the case by running gcloud --auth configure-docker <http://gcr.io|gcr.io>. This adds `gcr.io: glcoud`to credHelpers in the file.clever-father-91273
03/10/2023, 3:53 PMclever-father-91273
03/10/2023, 3:54 PMpublish works; I'm only having trouble on Cloud Build.gorgeous-winter-99296
03/10/2023, 4:05 PM/tmp/test-creds with the tools and eventually some external env variables (esp GOOGLE_APPLICATION_CREDENTIALS might be interesting) then that is the minimum set to make pants+docker work. The check is just that you get a credentials.
For example; if I just put docker-credential-gcr in /tmp/foobar I get a first step:
echo europe-north1-docker.pkg.dev | env -i PATH=/tmp/foobar/ docker-credential-gcr
/tmp/foobar//docker-credential-gcr: 59: readlink: not found
/tmp/foobar//docker-credential-gcr: 73: dirname: not found
/tmp/foobar//docker-credential-gcr: 59: readlink: not found
/bin/gcloud: 59: readlink: not found
/bin/gcloud: 73: dirname: not found
/bin/gcloud: 59: readlink: not found
/bin/gcloud: 182: exec: python: not found
So starting from that I can see I need dirname, readlink, and python. Adding those I get a credential. Knowing that, and having those in the pants configuration, the likely candidate is the ~/.docker/config.json file not being included.clever-father-91273
03/10/2023, 4:08 PM~/.docker/config.json file not being included? I mean, it is present in the Cloud Build container when the pipeline runs, I can cat it to see its contents.gorgeous-winter-99296
03/10/2023, 4:08 PMenv_vars = ["DOCKER_CONFIG=%(homedir)s/.docker"].clever-father-91273
03/10/2023, 4:09 PMgorgeous-winter-99296
03/10/2023, 4:13 PM-ldebug --keep-sandboxes=on_failure, you should see what commands Pants run and where it does so. Might be worthwhile to that there isn't some weird path or other funky thing happening there with variable expansions etc. It should (iirc) generate a run script in the sandbox too.clever-father-91273
03/10/2023, 4:15 PMkeep-sandboxes allows to analyze a failed Pants execution after it failed? If it does, the CloudBuild container is removed anyway, so I can't access these sandboxes I guessgorgeous-winter-99296
03/10/2023, 4:26 PM/tmp/pants-sandbox-RANDOM/) containing all files and tools used in a command run. -ldebug should still be helpful, at least. It definitely sounds like an environment/config mismatch, but I'm a bit at a loss for what it would be. Maybe doing an export and just forwarding anything that seems even remotely useful could work as a debugging step.clever-father-91273
03/10/2023, 5:19 PMDOCKER_CONFIG="/root/.docker". (I have set "DOCKER_CONFIG=%(homedir)s/.docker" in pants.toml). But I'm not sure whether /root/ is where my docker config is. During CloudBuild execution, the HOME env var is set to /builder/home and I think that my valid docker configuration sits in /builder/home/.docker.clever-father-91273
03/10/2023, 5:20 PM%(homedir)s, is it not $HOME?gorgeous-winter-99296
03/10/2023, 5:22 PM~ according to the docs. You could try %(env.HOME)s which should be $HOME.clever-father-91273
03/10/2023, 5:38 PMcurved-television-6568
03/10/2023, 5:41 PMgorgeous-winter-99296
03/10/2023, 5:43 PMclever-father-91273
03/10/2023, 5:45 PM/builder/home and this is where docker configuration is stored (e.g. config file that is created when one runs gcloud --auth configure-docker <http://gcr.io|gcr.io>
⢠"~" on the other hand seems to resolve to /root/ . Consequently, setting "DOCKER_CONFIG=%(homedir)s/.docker" in pants.toml made Pants look for the config in /root/.docker
⢠The solution: use %(env.HOME)s in pants.tomlhappy-kitchen-89482
03/10/2023, 7:48 PMsilly-queen-7197
05/26/2023, 5:10 PMdocker-credential-gcloud instead of docker-credential-gcr. I think Google is trying to move folks from container registry to artifact registry.