Hi folks, I’m trying to publish a python `pex` bin...
# general
b
Hi folks, I’m trying to publish a python
pex
binary using CircleCI and getting the following error:
Copy code
Engine traceback:
  in `package` goal

IntrinsicError: Failed to obtain version from local Docker: error trying to connect: No such file or directory (os error 2)
The command I’m running:
Copy code
REGISTRY=$ECR_REGISTRY_ID REGION=$ECR_REGION  REPOSITORY=$ECR_REPOSITORY  TAG=$CIRCLE_SHA1 pants package src/services/classifier/Dockerfile
I’ve looked through the slack here but couldn’t find much on this topic. Could use some help! 🙇‍♂️
I’ve checked in the CI machine that each of the env variables are set correctly. E.g.:
echo $ECR_REGION
works
my pants.toml:
Copy code
[GLOBAL]
pants_version = "2.17.0"
backend_packages = [
  "pants.backend.python",
  "pants.backend.python.lint.black",
  "pants.backend.python.lint.isort",
  "pants.backend.build_files.fmt.black",
  "pants.backend.experimental.visibility",
  "pants.backend.docker",
  "pants.backend.docker.lint.hadolint",
]
# Custom macros
build_file_prelude_globs = ["pants-plugins/visibility_macro.py"]
pants_ignore = [
  ".*/",
  "/dist/",
  "__pycache__",
  "pants-sandbox*",
]

[python]
interpreter_constraints = ['==3.11.*']
enable_resolves = true

[environments-preview.names]
python_bullseye = "//:python_bullseye"

[docker]
build_args = ["REPOSITORY", "REGISTRY", "REGION", "TAG"]
my BUILD:
Copy code
# Default target of `<directory_name>`
python_sources()

# TODO config file for gunicorn so that staging & prod are diff
# README INSTALL PEX AND PANTS

pex_binary(
    # This determines the output of the binary.
    name="classifier-api",
    # The command to run.
    script="gunicorn",
    args=["<http://services.classifier.app:app|services.classifier.app:app>", "-w=1", "-b=0.0.0.0", "--log-level=debug"],
    # Essentially specifying the requirements.txt file.
    dependencies=[
        "//:shared_reqs#gunicorn",  # need to explicitly add gunicorn because it's not part of imports.
        ":classifier",  # need to add the "self" package so that it's included in the pex.
    ],
    environment="python_bullseye",
)

# TODO this docker image stuff works local
# but not in CI; how to make it work with CI + ECR?
docker_image(
    context_root="",
    name="docker-classifier",
    repository="{build_args.REPOSITORY}",
    image_tags=["{build_args.TAG}"],
)

use_visibility_service(
    name="classifier",
)
c
Copy code
IntrinsicError: Failed to obtain version from local Docker
this error message is about a
docker_environment
about pants not being able to connect to the docker daemon.
👀 1
b
okay I ended up getting rid of the
environment
part in the
pex_binary
and I’ve progressed further… but now hitting:
Copy code
stderr:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Following a previous thread I found, I’ve: • removed
[environments-preview.names]
from
pants.toml
• added
env_vars = ["DOCKER_HOST"]
under
docker
in
pants.toml
And I’m still getting this error…
This is the output in the __run.sh:
Copy code
#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /tmp/pants-sandbox-tj3l7i
env -i REPOSITORY=api-classifier TAG=e8c6c0721f0c61a4607a1e5f859210a868076f92 __UPSTREAM_IMAGE_IDS= /usr/bin/docker build $'--pull=False' --tag $'<redacted>.<http://dkr.ecr.us-west-1.amazonaws.com/api-classifier:e8c6c0721f0c61a4607a1e5f859210a868076f92|dkr.ecr.us-west-1.amazonaws.com/api-classifier:e8c6c0721f0c61a4607a1e5f859210a868076f92>' --build-arg REPOSITORY --build-arg TAG --file src/services/classifier/Dockerfile .
c
does a bare
docker version
report the server version? Seems like the docker daemon is either not running or not creating the
/var/run/docker.sock
unix socket.
b
it does give this:
Copy code
Client: Docker Engine - Community
 Version:           20.10.22                                                                                                                                                                                                                                                                                                                                                                                                               API version:       1.41
 Go version:        go1.18.9
 Git commit:        3a2c30b
 Built:             Thu Dec 15 22:28:04 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I wonder if it’s something to do with the circleci image?
c
so, it’ll be easier to get that working without pants in the picture first.. I’ve no circleci experience so don’t have any hints for what to check for there unfortunately..
🫡 1
l
it may be that circleci uses tcp sockets instead? i don’t think pants supports yet anything else other than unix sockets https://github.com/pantsbuild/pants/issues/18889
c
For building images using the
docker_image
target, anything goes (only requires a workding
docker
client) — for environments however, it may be that unix socket is the only way (depending on what support we have from the
bollard
rust crate, and what we’re using of it)
b
just to close the loop here—it was indeed something on CircleCI; I needed to add a
setup_remote_docker
step in the config
👍 1
c
Thanks for the info :)