Hi team, When using the `docker_image` target in P...
# general
b
Hi team, When using the
docker_image
target in Pants the
COPY
command in a
Dockerfile
appears to bypass
.dockerignore
logic (
COPY folder folder
) if the files are matched by
Copy code
files(
sources=[
    "folder/**/*"]
)
in BUILD. All files are materialized in the build sandbox and subsequently copied into the image, even if they are listed in
.dockerignore
. While I can use
!
exclusions in the
BUILD
file, should not pants honors the
.dockerignore
file automatically to be more compliant with the Docker/Podman?
h
cc @curved-television-6568 does this ring a bell? It does look like we don't reference .dockerignore at all, so I would consider this a bug
@billions-sundown-65740 can you open an issue for this at https://github.com/pantsbuild/pants/issues ? A tiny repo that demonstrates the problem in a minimal way would be golden
c
Well, yes and no. It's all "by design" (even when/if lacking 😂 ) What's happening is that pants is responsible for materializing files in the sandbox for the docker build context, and pants does not consult
.dockerignore
Then when pants runs
docker build
using the sandbox as build context, it (i.e. docker) will respect any
.dockerignore
in the sandbox meaning, you'll need to make sure that pants materializes it there, by including
.dockerignore
in some valid target source type that is a dependency of your
docker_image
I'd suggest the fix to be to look for and always include any
.dockerignore
files when deciding what goes into the build context/sandbox.
or, of course, honoring the .dockerignore file in the first place, avoiding the files going into the context.. but then again, you're pretty much in charge of what goes into the sandbox already.. so feels overkill to try to replicate the rules of the .dockerignore file itself
b
I will open an issue and create a tiny repo as soon as I have more time. I guess including the
.dockerignore
files by default into the sandbox is the best and simplest approach for now. Maybe adding a parameter (feature flag) to
pants.toml
in order to activate it (and adding a deprecation warning that in future releases the behaviour will change) would be the safest approach to prevent unexpected behaviours when updating the pants version.