Hey all, I'm encountering an issue publishing a Do...
# general
i
Hey all, I'm encountering an issue publishing a Docker image to
<http://gcr.io|gcr.io>
. I've tracked this down pretty far but I can't seem to determine the cause without a lot more digging and wanted to check if anyone had a solution to the problem first. Specifically it seems that
docker-credential-gcloud
freezes on execution within Pants requiring the tools and envvars recommended in the docs. I can however push directly using docker without issue. I'll put more details in the thread to save everyone the glut of information. SOLVED, see thread for details.
First the Pants config files: `pants.toml`:
Copy code
[GLOBAL]
pants_version = "2.21.0"

...

[docker]
env_vars = ["DOCKER_CONFIG=%(env.HOME)s/.docker"]
build_args = ["GIT_COMMIT"]
default_repository = "myorg/{directory}"
tools = [
  "docker-credential-gcloud",
  "gcloud",
  "dirname",
  "readlink",
  "python3",
  "cut",
  "sed",
  "bash",
]

[docker.registries.gcr-io]
address = "gcr.io"
default = true

...
`BUILD`:
Copy code
pex_binary(
  name='app',
  environment='linux',
  ...
)

docker_image(
  name='docker',
  image_tags=['{build_args.GIT_COMMIT}'],
  instructions=[
    'FROM python:3.12-slim',
    'EXPOSE 8080',
    'COPY project/app.pex /bin/app',
    'ENTRYPOINT ["/usr/local/bin/python3.12", "/bin/app"]',
  ],
  source=None,
  dependencies=['project:app'],
  build_platform=['linux/amd64'],
)
From here I took the advice in the docs under "How to Troubleshoot Authentication" and ran the following with the tools in
pants.toml
symlinked into the directory on `PATH`:
Copy code
echo "<http://gcr.io|gcr.io>" | env -i PATH=/Users/nik/tmp/testing/docker-creds HOME=/Users/nik CLOUDSDK_PYTHON=/Users/nik/.pyenv/shims/python3 /bin/sh -x docker-credential-gcloud get
Which also freezes. I dug a little deeper and got to:
Copy code
env -i PATH=/Users/nik/tmp/testing/docker-creds HOME=/Users/nik /Users/nik/.pyenv/shims/python3 -S /opt/homebrew/Caskroom/google-cloud-sdk/484.0.0/google-cloud-sdk/lib/gcloud.py auth docker-helper get
And again this also freezes. At this point I'm not sure I can get to the bottom of it without really digging into the
gcloud
source code, as I've already loaded this into my IDE and I can't manage to reproduce there.
I'd really appreciate any insight into this anyone has, and thanks in advance!
SOLUTION: Well apparently posting here did the trick as I figured it out immediately after posting. For reference to anyone coming to find the answer: I believe Pants was using the python virtualenv shim, but the shim couldn't determine the python version and froze (purely speculation). Adding this to `.pants.bootstrap`:
Copy code
export CLOUDSDK_PYTHON="$(python3 -c 'import sys; print(sys.executable)')"
and putting
CLOUDSDK_PYTHON
in
[docker].env_vars
seemed to do the trick.
👌 1
h
Thanks for the update! Would you be open to writing this in a GitHub Discussion under the Tips and Tricks label? That way we can preserve it for posterity
i
Sure thing, I’ll try to get it in this week.
b
thank you for this @incalculable-toothbrush-17758 🙏