https://pantsbuild.org/ logo
#general
Title
# general
q

quick-apartment-97325

09/14/2022, 7:25 PM
Prior to
2.13.0
I was using a common Dockerfile for multiple targets and referring to it with a relative path:
Copy code
docker_image(
    name="docker",
    source="../Dockerfile.prod",
    ...
)
After upgrading to
2.13.0
I am now getting:
Copy code
InvalidFieldException: The 'source' field in target xxx:docker should not include `../` patterns because targets can only have sources in the current directory or subdirectories
I have tried creating a
files
target and including it into
docker_image.dependencies
but am not having any luck with that either Is there another way I should try? Should I open an issue to track on GH?
1
h

hundreds-father-404

09/14/2022, 7:26 PM
Hi! The recommended fix is to move the
docker_image
target definitions to the BUILD file in the directory with
Dockerfile.prod
FYI we intended to always ban
../
and it was a bug we weren't erroring. It messes up things like
--changed-since
q

quick-apartment-97325

09/14/2022, 7:28 PM
ah, ok. so
source
in this case cannot refer to a dependency file?
h

hundreds-father-404

09/14/2022, 7:32 PM
source
should still refer to
Dockerfile.prod
because that is the Dockerfile that you are giving metadata for. You only can't use
../
in the path to it, so thus the target definition needs to live alongside the file. Does that make sense?
q

quick-apartment-97325

09/14/2022, 7:35 PM
that makes sense, I just wasn't sure if I could reference a
source
file that came from
dependencies
, example:
Copy code
docker/
  BUILD
  Dockerfile.prod
xxx/
  BUILD
  app
yyy/
  BUILD
  app
then inside
docker/BUILD
do:
Copy code
files(
    name="files",
    sources=["Dockerfile.prod"]
)
and inside
xxx/BUILD
and
yyy/build
do:
Copy code
docker_image(
    name="docker",
    source="docker/Dockerfile.prod",
    dependencies: ["docker:files"]
    ...
)
w

witty-crayon-22786

09/14/2022, 8:28 PM
yep: sorry for the breaking change here, but not enforcing this would have lead to subtle bugs elsewhere, so we needed to patch it up quickly
h

happy-kitchen-89482

09/14/2022, 9:50 PM
I’m not sure you need that dependency on the
files
target? Just referencing the source in the
docker_image
target should be enough, IIRC
q

quick-apartment-97325

09/15/2022, 1:25 PM
I was experimenting with if it was possible to import the
source
Dockerfile from another target, but it did not work I have moved the
docker_image
declarations into the same target directory as the Dockerfile and it is working now Thank you for the quick help!
❤️ 1