Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.dockerignore not considered when computing cache keys #871

Closed
michaelhixson opened this issue Nov 20, 2019 · 2 comments
Closed

.dockerignore not considered when computing cache keys #871

michaelhixson opened this issue Nov 20, 2019 · 2 comments
Labels
area/caching For all bugs related to cache issues in progress kind/bug Something isn't working priority/p2 High impact feature/bug. Will get a lot of users happy

Comments

@michaelhixson
Copy link

michaelhixson commented Nov 20, 2019

Actual behavior
Files excluded by .dockerignore are wrongly included when determining whether the cache can be used for a COPY build step.

Expected behavior
Modifications to files excluded by .dockerignore do not affect the cacheability of COPY steps.

To Reproduce

Project files

example/project/.dockerignore

files/a.txt

example/project/Dockerfile

FROM alpine
COPY files files
CMD ["ls", "files"]

example/project/files/a.txt

hi

example/project/files/b.txt

bye

example/docker_config.json

{
  "auths": {
    REDACTED
  }
}

example/docker-compose.yml [*]

version: "3.7"
services:
  foo:
    image: gcr.io/kaniko-project/executor:latest
    volumes:
      - ./project:/workspace
      - ./docker_config.json:/kaniko/.docker/config.json
    command:
      - --context=/workspace
      - --destination=REDACTED
      - --cache=true

[*] I would have used docker run ... instead of docker-compose except I couldn't figure out the Windows-compatible syntax that docker run wanted for mounting volumes.

Command line instructions

I do not include the full output of each command. Instead I include my own comments about the output ### formatted like this.

$ cd example

$ docker build project
### OK: docker won't use a cache for the "COPY files files" step
###     since it's the first build

$ docker build project
### OK: this time docker will use a cache for "COPY files files"

$ echo "hi2" >> project/files/a.txt
$ docker build project
### OK: docker will still use a cache for "COPY files files"
###     because files/a.txt was .dockerignored!

$ docker-compose up --build
### OK: kaniko won't use a cache for the "COPY files files" step
###     since it's the first build

$ docker-compose up --build
### OK: this time kaniko will use a cache for "COPY files files"

$ echo "hi3" >> project/files/a.txt
$ docker-compose up --build
### BAD: kaniko won't use a cache for "COPY files files"
###      but it should, since files/a.txt was dockerignored

Additional Information

$ docker images gcr.io/kaniko-project/executor --digests
REPOSITORY                       TAG                 DIGEST                                                                    IMAGE ID            CREATED             SIZE
gcr.io/kaniko-project/executor   latest              sha256:9c40a04cf1bc9d886f7f000e0b7fa5300c31c89e2ad001e97eeeecdce9f07a29   4afd732d4dfa        12 days ago         61.3MB

My theory for the issue's cause
While copy.go's ExecuteCommand takes exclusions from .dockerignore into account, the FilesUsedFromContext function from that same file does not consider exclusions, and that second function is what's used to compute cache keys. Either FilesUsedFromContext or its caller in build.go should be changed to be aware of .dockerignore.

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
Please check if the build works in docker but not in kaniko
Please check if this error is seen when you use --cache flag
Please check if your dockerfile is a multistage dockerfile
@michaelhixson
Copy link
Author

Oops, I didn't see #854 before filing this, but I bet that PR will fix this.

@cvgw cvgw added area/caching For all bugs related to cache issues kind/bug Something isn't working priority/p2 High impact feature/bug. Will get a lot of users happy labels Nov 22, 2019
@cvgw cvgw added this to the GA Release v1.0.0 milestone Jan 10, 2020
@tejal29
Copy link
Contributor

tejal29 commented Feb 3, 2020

This is closed via #924 and released in kaniko v0.17.0

@tejal29 tejal29 closed this as completed Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/caching For all bugs related to cache issues in progress kind/bug Something isn't working priority/p2 High impact feature/bug. Will get a lot of users happy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants