I am trying to run pants on bitbucket-pipelines. W...
# general
b
I am trying to run pants on bitbucket-pipelines. When I run "pants lint package ::", it manages to build all the binaries (pex), but fails to build the docker images, giving me the error`Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?` . In the same script I however can build a normal Dockerfile with
docker build -t hello_docker .
. Any ideas why this might be happening?
e
Stack Overflow is a cesspool of bad advice generally, but without my hands in a bitbucket pipeline, this seems plausible - you may want to confirm: https://stackoverflow.com/a/73487393
b
This is my test script. Note that the first docker build which runs outside pants works (just a hello world docker image); but fails when executed through pants.
Copy code
image: python:3.10.10-slim-bullseye
pipelines:
  default:
    - step:
          services:
            - docker
          script:
            - docker build -t my_project .
            - export PATH=/root/bin:$PATH
            - ./get-pants.sh
            - docker --version
            - "pants lint package ::"
e
Sorry - I should have been clearer. That SO implies the env has DOCKER_HOST. Pants is hermetic and you'd need to punch that through.
And punch through DOCKER_HOST.
Again - iff that SO is on-base. No clue about that.
b
I have not got it working yet, in the bitbucket logs I get the following error "time="2023-03-07T170339.328682185Z" level=warning msg="could not change group /var/run/docker.sock to docker: group docker not found""
So at least we expect issues with /var_run_docker.sock.
e
Ok, you'll have to play. HOME is not punched through either, etc. I don't imagine that would affect chgrp , but.
b
I added this to pants.toml:
Copy code
[docker]
env_vars = [
'DOCKER_HOST="<tcp://0.0.0.0:2375>"'
]
e
You might start by adding a CI step that just dumps
env
🙌 1
Instead of guessing and praying here. That would give a solid foundation.
On the env vars - don't guess the value, just pass-though:
Copy code
[docker]
env_vars = ["DOCKER_HOST"]
Even if you guess the right value today - it will change tomorrow.
👍 1
b
True that. I dumped all the environmental variables, and one of them is DOCKER_HOST=tcp://localhost:2375 And pants is still failing with the error message "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
I also see the BITBUCKET_DOCKER_HOST_INTERNAL=10.37.86.123 variable.
e
Yeah, you're squarely out of Pants land (save for hermeticity) fwict and need to just keep digging on what exactly is needed to get
docker foo
to work. If you can get ssh access to their instances,
env -i SET=this ALSO=that docker ...
until you get everything needed is how I'd figure this out locally.
b
I have now basically passed every environmental variable available on the host; without any success. But does the way I am using to pass the --add_host flag look correct?
Copy code
[docker]
build_args = ['--add-host=host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL']
env_vars = ["QA_API_GATEWAY_KEY",
    "KUBERNETES_SERVICE_PORT_HTTPS",
    "KUBERNETES_SERVICE_PORT",
    "BITBUCKET_PROJECT_UUID",
    "BITBUCKET_BUILD_NUMBER",
    "BITBUCKET_REPO_SLUG",
    "HOSTNAME",
    "PYTHON_VERSION",
    "BITBUCKET_DOCKER_HOST_INTERNAL",
    "BITBUCKET_STEP_UUID",
    "PIPELINES_JWT_TOKEN",
    "PWD",
    "BITBUCKET_COMMIT",
    "PYTHON_SETUPTOOLS_VERSION",
    "BITBUCKET_PROJECT_KEY",
    "HOME",
    "LANG",
    "KUBERNETES_PORT_443_TCP",
    "BITBUCKET_GIT_HTTP_ORIGIN",
    "BITBUCKET_REPO_UUID",
    "CB_USER",
    "GPG_KEY",
    "BITBUCKET_REPO_OWNER",
    "BITBUCKET_PIPELINE_UUID",
    "BITBUCKET_GIT_SSH_ORIGIN",
    "CB_PASS",
    "BITBUCKET_WORKSPACE",
    "DEV_API_GATEWAY_KEY",
    "BITBUCKET_REPO_FULL_NAME",
    "BITBUCKET_STEP_TRIGGERER_UUID",
    "BITBUCKET_REPO_IS_PRIVATE",
    "SHLVL",
    "BITBUCKET_REPO_OWNER_UUID",
    "KUBERNETES_PORT_443_TCP_PROTO",
    "PYTHON_PIP_VERSION",
    "KUBERNETES_PORT_443_TCP_ADDR",
    "PYTHON_GET_PIP_SHA256",
    "DOCKER_HOST",
    "BITBUCKET_CLONE_DIR",
    "KUBERNETES_SERVICE_HOST",
    "KUBERNETES_PORT",
    "KUBERNETES_PORT_443_TCP_PORT",
    "PYTHON_GET_PIP_URL",
    "PATH",
    "CI",
    "PROD_API_GATEWAY_KEY",
    "BITBUCKET_BRANCH",
    "BITBUCKET_STEP_RUN_NUMBER",
    "BITBUCKET_SSH_KEY_FILE",]
The issue here was that pants was not passing down the DOCKER_HOST env variable. This was happening because the docker_environment target was overriding the env_vars definition. See the follow up thread: https://pantsbuild.slack.com/archives/C046T6T9U/p1678275259417769