refined-addition-53644
12/07/2021, 2:39 PMsrc/pyfleet-vehicle-spec
with this target.
docker_image(
name="docker_dev",
source="Dockerfile_dev"
)
This is a dockerfile where I am adding a requirements.txt
FROM python:3.8.1-slim
COPY requirements.txt /usr/src/app
When I run ./pants package <path_to_docker_file>
, it can't find the file inside the src/pyfleet-vehicle-spec
.
This is the error stack
./pants package src/pyfleet-vehicle-spec:docker_dev
15:37:13.87 [INFO] Completed: Building docker image docker_dev:latest.
15:37:13.87 [ERROR] 1 Exception encountered:
ProcessExecutionFailure: Process 'Building docker image docker_dev:latest.' failed with exit code 1.
stdout:
stderr:
#1 [internal] load build definition from Dockerfile_dev
#1 sha256:70afa1e12870fb24144364708587cf5d1661f981d416ff91b9933fb09bf718bf
#1 transferring dockerfile: 370B done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 sha256:8be3f6d6908bac7ae4d1c83b3c98641278b5369f05b904a5bd61c9aa771021ab
#2 transferring context: 2B done
#2 DONE 0.0s
#3 [internal] load metadata for <http://docker.io/library/python:3.8.1-slim|docker.io/library/python:3.8.1-slim>
#3 sha256:897c30c5b0df12bcc7293f681243e639405b0ad6ce158f8ac7f4d6aa75160f3a
#3 DONE 0.7s
#4 [1/2] FROM <http://docker.io/library/python:3.8.1-slim@sha256:73f3903470a6e55202a6bb989c23b047487eb1728feba655410076da24106838|docker.io/library/python:3.8.1-slim@sha256:73f3903470a6e55202a6bb989c23b047487eb1728feba655410076da24106838>
#4 sha256:28d9be0d3eda75c94bdf3ffcb19aba18126f795be53f25d1fc3ed17716e5e83e
#4 CACHED
#5 [internal] load build context
#5 sha256:d8740fb29f3447aa31b7339dc3205fc961ed6fff4d68fe91e5f24b402262ebf3
#5 transferring context: 2B done
#5 DONE 0.0s
#6 [2/2] COPY requirements.txt /usr/src/app
#6 sha256:962d6b5ae5239ecc9e26d88d359e20065c2a3d56011710983dd0ee0face6bfd1
#6 ERROR: "/requirements.txt" not found: not found
------
> [2/2] COPY requirements.txt /usr/src/app:
------
failed to compute cache key: "/requirements.txt" not found: not found
curved-television-6568
12/07/2021, 2:49 PMpex_binary
targets from your Dockerfile
COPY
instructions, so you will have to add your requirements.txt
file to a files
target, and depend on that from your docker_image
.curved-television-6568
12/07/2021, 2:49 PMcurved-television-6568
12/07/2021, 2:51 PMcurved-television-6568
12/07/2021, 2:51 PMrefined-addition-53644
12/07/2021, 3:40 PMpyfleet-vehicle-spec
. This way you can even manually build it directly inside pyfleet-vehicle-spec
. I will have to change all the paths where we are adding local directory to docker image relative to pants. Not sure if something like docker_source_root
makes sense like we have source_root
for pythonrefined-addition-53644
12/07/2021, 3:41 PMdocker-compose
for testing.curved-television-6568
12/07/2021, 3:42 PMhappy-kitchen-89482
12/07/2021, 4:01 PMrelocated_files
targets work for this? https://www.pantsbuild.org/docs/reference-relocated_filesrefined-addition-53644
12/07/2021, 4:04 PMdocker_source_root
to repo root?refined-addition-53644
12/07/2021, 4:07 PMrelocated_files
work with say all the targets generated using some glob pattern?nutritious-hair-72580
01/12/2022, 10:08 AMdocker build
within the directory. @curved-television-6568 wondering if there’s been any progress on the file locations or an issue raised.
I got relocated_files
to work - I think this is ok as a workaround for now.
Btw the docs and error reporting is really easy to follow. 🙂curved-television-6568
01/12/2022, 10:50 AMfiles can in theory be pulled in from all over the repoIn practice, we could inspect the paths actually present in the build context, and descend the tree as long as there’s no branching out. I.e. if all files reside in a tree rooted at
src/project/a/…
we could build from ../a
rather than the repo root.
However, we should only do this when explicitly asked for, to a) avoid confusion by being explicit about it and b) in case you pull in something else that is rooted in say src/project/b/…
things will break, and being explicit we can provide more informative error messages.curved-television-6568
01/12/2022, 10:51 AMcurved-television-6568
01/12/2022, 10:59 AMnutritious-hair-72580
01/12/2022, 11:00 AMcurved-television-6568
01/13/2022, 8:11 AMImproving feedback regarding the build context is high on my todo list.There are some improvements out now in 2.9.0 for Docker build context issues in case of build failures.
hundreds-father-404
01/13/2022, 9:43 PMI.e. if all files reside in a tree rooted at src/project/a/… we could build from ../a rather than the repo root.Vs using
relocated_files
?curved-television-6568
01/13/2022, 9:46 PMrelocated_files
hundreds-father-404
01/13/2022, 9:53 PMrelocated_files
is already the generic way to approach this problem and it has the benefit of working with all of Pants, including Python, Go, JVM, Shell. It's also documented already
The surface area of Pants is already enormous and continues growing, so we probably want to be careful before adding a new feature when there's already a workaroundcurved-television-6568
01/13/2022, 9:56 PMcurved-television-6568
01/13/2022, 10:05 PMcurved-television-6568
01/14/2022, 2:04 PMhundreds-father-404
01/14/2022, 5:24 PMI’ve added some arguments for this new option in the PR.Cool, will take a look! To clarify, I'm not blocking and haven't looked closely enough to say no or anything. Only to bias towards reusing existing functionality like
relocated_files
when feasible to do so.
Perhaps there’s need for better grouping/nesting of features/goals/option scopes/etc as more and more gets added?Perhaps, although generally I think it's valuable to have mechanisms that apply across backends. For example: • source roots are the same mechanism regardless of Java vs Python •
resources
work with multiple languages
• Codegen targets like protobuf_source
work with multiple languages
Although, I think it could be both. We try to have mechanisms that generalize to multiple backends, and we also try to have good grouping/nesting of features when that's not possible