I am using pants in my ci and seeing the following...
# general
b
I am using pants in my ci and seeing the following error. I am using
docker_environment
to build pex binaries, copy those binaries to docker image (
Dockerfile
has COPY command), build this new image and publish this image to ECR Repository using
pants publish
command. The build and docker files are in the thread. If anyone has any pointers on why this error might be happening, would love your help.
Copy code
| ProcessExecutionFailure: Process 'Extract environment variables from the Docker image python:3.11.9-slim' failed with exit code 126.
| stdout:
| OCI runtime exec failed: exec failed: unable to start container process: chdir to cwd ("/pants-sandbox/pants-sandbox-PRbWVL") set in config.json failed: no such file or directory: unknown
|
| stderr:
|
|
|
| Use `--keep-sandboxes=on_failure` to preserve the process chroot for inspection.
|
Docker environment target build file. This file is placed at the root of the directory, the environment mentioned here is added to
pants.toml
, under the section:
Copy code
[environments-preview.names]
linux = "//:linux"
Copy code
docker_environment(
    name="linux",
    platform="linux_x86_64",
    image="python:3.11.9-slim",
    python_bootstrap_search_path=(
        "<PATH>",
        "/opt/hostedtoolcache/Python/3.11.9/x64",
        "/usr/local/bin",
    ),
)
The pex binary target which is building the binaries and projects docker_image target. This BUILD file is placed in projects directory
Copy code
python_sources()

python_requirements(
    name="reqs",
)

if env("GITHUB_ACTIONS"):
    platform = ["hunch:ci-platform"]
else:
    platform = ["hunch:linux-platform"]

kwargs = dict(         entry_point="hunch.projects.followed_users_post.src.forecast:main",
    layout="packed",
    environment="linux",
    execution_mode="venv",
)

pex_binary(name="pex-dependencies", include_sources=False, **kwargs)

pex_binary(name="pex-sources", include_requirements=False, **kwargs)

docker_image(
    name="followed_users_post_img",
    repository="followed_users_post",
    registries=[
        env("ECR_REGISTRY", "ECR Registry name e.g. `47474747.dkr.ecr.amazonaws.com`")
    ],
    image_tags=["{build_args.IMAGE_LATEST_TAG}", "{build_args.IMAGE_VERSION_TAG}"],
    extra_build_args=("IMAGE_LATEST_TAG", "IMAGE_VERSION_TAG", "--provenance=false"),
)
The dockerfile for the projets image
Copy code
FROM --platform=linux/amd64 python:3.11.9-slim as deps
# FROM python:3.11.9-slim as deps

COPY hunch.projects.followed_users_post/pex-dependencies.pex /libs_binary.pex
RUN PEX_TOOLS=1 /usr/local/bin/python /libs_binary.pex venv --scope=deps --compile /bin/app

FROM --platform=linux/amd64 python:3.11.9-slim as srcs
# FROM python:3.11.9-slim as srcs
COPY hunch.projects.followed_users_post/pex-sources.pex /fp_binary.pex
RUN PEX_TOOLS=1 /usr/local/bin/python /fp_binary.pex venv --scope=srcs --compile /bin/app

FROM --platform=linux/amd64 python:3.11.9-slim
# FROM python:3.11.9-slim
COPY --from=deps /bin/app /bin/app
COPY --from=srcs /bin/app /bin/app
c
are you using the
env(..)
construct in the same BUILD file as your
docker_environment
target? (I think that could be the issue.. thought it was called out in the docs, but seems not)
b
In my
docker_environment
target, I am not using
env()
construct, however I am using it inside
docker_image()
target and in the
BUILD
file . Both of these are in separate
BUILD
files.
docker_environment()
target is in the
BUILD
file which is in the root directory of monorepo, while
docker_image()
target is in the
BUILD
file which is in the project directory e.g.
monorepo/projects/projectA/BUILD
c
Ok, that should be fine. Something else isn’t, but I’m not sure what..