Hello, just joined the community and looking for s...
# general
b
Hello, just joined the community and looking for some help. I am evaluating Pants for use with docker builds. I am having an issue setting the correct build context. The COPY command is not copying the correct files. To share some context, my folder structure is root/<project_name>/BUILD. I am running
pants package ::
from the root folder. What should the correct context_root be set to, if I want it to be the <project_name> folder.. I feel like I have tried all variations but no success. Variations tried • context_root=“./” • context_root=“.” • context_root=“<project_name>/”
1
c
Hi and welcome. 👋 what error message do you get? If you have a
root/<proj>/Dockerfile
with a
COPY my_file /some/where
and a
root/<proj>/BUILD
with a
docker_image(context_root=".")
target defined that depends on
root/<proj>/my_file
that should work.
b
This is my docker file, it complains that it cannot find the requirements.txt file, which is in the project_name
Copy code
FROM public.ecr.aws/docker/library/python:3.10
WORKDIR /app
COPY ./ ./
RUN pip install --no-cache-dir -r requirements.txt
c
And what does your BUILD file look like?
I guess there is no dependency from your
docker_image
target to the requirements.txt file, only files that the target depends upon will be present in the build context.
b
Copy code
docker_image(
    name="docker",
    context_root="./"
)
c
ok, yea, so with no dependencies, the context will be empty, besides the
Dockerfile
.
b
Thank you, I think that addresses my concerns
c
Great. And do come back if you get more questions 😉
1
b
@curved-television-6568 - I think I need some more help on this. I am attempting to copy all the files in the project directory to the build dependency using
dependecies
and
files
but am not getting anywhere. I am assuming if I do this, then I dont need
COPY . .
in my Dockerfile?
In short, I am trying to copy entire project folder to docker image, how would I go about doing that
c
yes, you still need the
COPY
in the
Dockerfile
. There’s four layers to this cake. (A) the source repository, (B) the pants execution sandbox, (C) the docker build context and (D) the docker image. Your files start out their lives in A, you need a dependency on them from your
docker_image
target in order for them to be included into B, the docker build context is always rooted somewhere in the pants execution sandbox and any files in there (except any ignored by a
.dockerignore
file) will be sent to the docker daemon as the build context, C. Then during your docker build process, when the instructions in your
Dockerfile
is executed any files you want in your image D from the context C needs to be `COPY`’d over as usual.
something like
files(sources=["*/**"], name="files")
and then
docker_image(…, dependencies=[":files"])
and finally
COPY . /files
or something along those lines.
b
Makes sense. When I run with option
--keep-sandboxes=always
- where on my local system do I find the sandbox. I would like to take a peek
c
those paths will be logged to stdout during the run
b
Seen it.. Thanks
👍 1