What’s the correct path for copying a `pex_binary`...
# general
r
What’s the correct path for copying a
pex_binary
inside docker? I tried the
<http://path.to|path.to>.target/target.pex
but doesn’t work 🧵
1
• BUILD
Copy code
pex_binary(
    name="charge_plan_binary",
    entry_point="pyfleet_charge_plan/restapi/main.py",
    layout="packed",
    execution_mode="venv",
    resolve="charge_plan",
)

docker_image(
    name="charge_plan_image",
    description="Charge planning docker image",
    source="Dockerfile",
)
• Dockerfile
Copy code
FROM public.ecr.aws/docker/library/python:3.9.13-slim-bullseye

RUN groupadd --gid 1000 pyfleet \
  && useradd --uid 1000 --gid pyfleet --shell /bin/bash --create-home pyfleet

WORKDIR /bin/app

COPY --chown=pyfleet:pyfleet src.pyfleet-charge-plan/charge_plan_binary.pex .

EXPOSE 8080

USER pyfleet

ENTRYPOINT ["/usr/local/bin/python3.9", "/bin/app"]
Screenshot 2022-08-29 at 20.28.52.png
e
This is the claim: https://www.pantsbuild.org/v2.13/docs/docker#adding-dependencies-to-your-docker_image-targets Perhaps try setting the `pex_binary.output_path`to a simple value, seeing if that works and work backwards from there to the default setting?
c
Given that the pex target is built and included in the Docker build context, pants should log the file paths present in the build context so you can see what it actually is (on Docker build errors).
r
This is the log I see
Copy code
20:52:49.10 [INFO] Completed: Building docker image charge_plan_image:latest
20:52:49.10 [WARN] Docker build failed for `docker_image` src/pyfleet-charge-plan:charge_plan_image. The src/pyfleet-charge-plan/Dockerfile have `COPY` instructions where the source files may not have been found in the Docker build context.

The following files were not found in the Docker build context:

  * src.pyfleet-charge-plan/charge_plan_binary.pex


20:52:49.10 [ERROR] 1 Exception encountered:

  ProcessExecutionFailure: Process 'Building docker image charge_plan_image:latest' failed with exit code 1.
stdout:

stderr:
#1 [internal] load build definition from Dockerfile
#1 sha256:f62b52c4c989cd8e4b75c6759b6c8047d3ecfe009db3c27f61edf8b9043e9dee
#1 transferring dockerfile: 397B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:45c9a015e3987bb6d76fb6bf56b84c38c3d5571e142260e06983540d643d57ec
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for public.ecr.aws/docker/library/python:3.9.13-slim-bullseye
#3 sha256:0537c6650dc36477a7033a5d825ffc5f73b10466fccbfe7702d634493ee01410
#3 DONE 0.3s

#4 [1/4] FROM public.ecr.aws/docker/library/python:3.9.13-slim-bullseye@sha256:dcf2eafca55558d8b1aa73edd6aa41b7187c5bcb63e533a7b04a0673f81f37fe
#4 sha256:eaccf9bc487cd811e9bc9111fc890251b84efe7e087e7cb9d0e0be38506a5d07
#4 DONE 0.0s

#5 [2/4] RUN groupadd --gid 1000 pyfleet   && useradd --uid 1000 --gid pyfleet --shell /bin/bash --create-home pyfleet
#5 sha256:1b4330d9fa30f9ca2fd148e0f1ae449fbbdd55bfbb4ee12f1ae9560eec8ba8d0
#5 CACHED

#6 [3/4] WORKDIR /bin/app
#6 sha256:13b73ab0e52e1b512ab122d3dc5ee0ac3c6721a91af1ed520c5c2efe1c220027
#6 CACHED

#7 [internal] load build context
#7 sha256:c47cb04f4b5abf2f28f26c19d0c66c53b1aa9120874e08377cdcd72c785644ac
#7 transferring context: 2B done
#7 DONE 0.0s

#8 [4/4] COPY --chown=pyfleet:pyfleet src.pyfleet-charge-plan/charge_plan_binary.pex .
#8 sha256:71571ba8d07ac12ae7714d24ec8a3cd319fde13019aecdd522dd1c492090272f
#8 ERROR: "/src.pyfleet-charge-plan/charge_plan_binary.pex" not found: not found
------
 > [4/4] COPY --chown=pyfleet:pyfleet src.pyfleet-charge-plan/charge_plan_binary.pex .:
------
failed to compute cache key: "/src.pyfleet-charge-plan/charge_plan_binary.pex" not found: not found



Use `--no-process-cleanup` to preserve process chroots for inspection.
One thing which is bit mislead is the 1st line
205249.10 [INFO] Completed: Building docker image charge_plan_image:latest
I didn’t add explicit dependency on the pex target. I somehow imagined
COPY ..
is enough to infer dependency. That might be too much to expect from pants 🙂
c
It should infer a dependency on
COPY
pex target files..
this boils down to where the Docker build context root is perhaps. What is your context root set to? https://www.pantsbuild.org/docs/reference-docker#section-default-context-root
r
My context_root is default. So I assume the root where pants is
👍 1
c
all seems ok from what I can see, so that’s weird.