Prior to `2.13.0` I was using a common Dockerfile ...
# general
q
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
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
ah, ok. so
source
in this case cannot refer to a dependency file?
h
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
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
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
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
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