clever-father-91273
02/28/2023, 10:22 AMdocker_image
in such a way that the build root / context is at the repository's root?
I have the following directory structure:
/
utils
project
sub_dir
Dockerfile
BUILD (with docker_image target)
In the Dockerfiles, I want to be able to COPY utils utils
and COPY project project
and execute code in the container from the root direcotry (e.g. python files might from utils import ...
)
I tried to set dependencies=["project", "utils"]
in docker_image
, but when trying to pants package
I keep getting the error stating that project and utils were not found in Docker build context. What am I doing wrong?cold-branch-54016
02/28/2023, 10:25 AMcontext_root
option of the docker_image
target should do what you want https://www.pantsbuild.org/docs/reference-docker_image#codecontext_rootcodeclever-father-91273
02/28/2023, 10:26 AM../..
(two levels above the BUILD file) which should do it, but still the same errorrefined-addition-53644
02/28/2023, 10:27 AMclever-father-91273
02/28/2023, 10:27 AM"."
should work, but it doesn't eitherrefined-addition-53644
02/28/2023, 10:29 AMSpecify the context_root path as files for relative to build root, or as ./files for relative to the BUILD file.
Are making sure this is the case ?
clever-father-91273
02/28/2023, 10:31 AMcontext_root="."
should work, right? But it doesn't.clever-father-91273
02/28/2023, 10:31 AM"./"
nor ""
clever-father-91273
02/28/2023, 10:35 AMclever-father-91273
02/28/2023, 11:01 AMrefined-addition-53644
02/28/2023, 11:02 AMclever-father-91273
02/28/2023, 11:03 AMrefined-addition-53644
02/28/2023, 11:05 AMclever-father-91273
02/28/2023, 11:06 AMrefined-addition-53644
02/28/2023, 11:13 AM:projects
or :utils
and since they live above the BUILD file, you need to provide the path relative to the pants.toml
. So in your case, I would imagine projects:projects
and utils:utils
clever-father-91273
02/28/2023, 11:14 AMrefined-addition-53644
02/28/2023, 11:15 AMpex_binary
and I just to copy the pex binary which figures out all the implicit dependencies. I haven’t had to deal with this manual copying. Not that it shouldn’t work.clever-father-91273
02/28/2023, 11:16 AMpants dependencies project/sub_dir/Dockerfile
I get:
project/__init__.py
utils/__init__.py@resolve=project
clever-father-91273
02/28/2023, 11:17 AMrefined-addition-53644
02/28/2023, 11:19 AMclever-father-91273
02/28/2023, 11:39 AMpex_binary(
name="project_binary",
dependencies=[":project", "utils:utils"],
resolve="project",
layout="packed",
execution_mode="venv",
)
docker_image(
name="project_image",
repository="project",
instructions=[
"FROM tensorflow/tensorflow:2.9.1-gpu",
"COPY project/project_binary.pex /bin/project",
"RUN pip3 install -r project/requirements.txt",
]
)
And it fails on not finding the requirements file, which should have been included in the pex as part of the ;project dependencyrefined-addition-53644
02/28/2023, 11:43 AMclever-father-91273
02/28/2023, 11:45 AMrefined-addition-53644
02/28/2023, 11:48 AMbitter-ability-32190
02/28/2023, 12:08 PMkeep-sandboxes
option, it'll leak the sandbox pants used to run in. You'll see what's on disk when your process is runningclever-father-91273
02/28/2023, 12:11 PMpants dependencies
on my dockerfile or pex binary target yields:
project/__init__.py
utils/__init__.py@resolve=project
and this turns out to be true, inside the container, in both project and utils directories, there are only init files, no other files are includedclever-father-91273
02/28/2023, 12:35 PMclever-father-91273
02/28/2023, 1:31 PMFROM alpine
WORKDIR /app
COPY . .
Also at the root, I have the following BUILD file:
docker_image(
name="root_image",
)
Then, I run:
pants package :root_image
docker run -it root_image:latest
Inside the container:
ls
This only shows a Dockerfile, no other files or directories are included in the image.
I try adding different dependencies
to docker_image
, but whatever I pass there, no other files or directories are included in the docker image.clever-father-91273
02/28/2023, 1:38 PMdocker build . -f Dockerfile -t root_image:latest
from the repo's root, I obtain an image that has all the repo content in it. I would like to recreate this with Pants.bitter-ability-32190
02/28/2023, 2:01 PMbitter-ability-32190
02/28/2023, 2:04 PMclever-father-91273
02/28/2023, 2:11 PMbitter-ability-32190
02/28/2023, 2:12 PM