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

Support Dockerfile.dockerignore #801

Merged

Conversation

victornoel
Copy link
Contributor

@victornoel victornoel commented Oct 3, 2019

This fixes #776

Description

  • Use Dockerfile.dockerignore in priority over the context's .dockerignore file.
  • Actual name checked is based on the docker file passed to the command line
  • Introduces unit tests and integration test to validate the behaviour.

I haven't added an unit test because it wasn't clear what was to correct way to test this because excludes seems to be managed globally via a static field. I would be interested by guidance from knowledgeable people on this.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

  • Support Dockerfile.dockerignore file in the same way as docker build

@victornoel victornoel marked this pull request as ready for review October 3, 2019 15:11
Copy link
Member

@tejal29 tejal29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except additional tests.

dockerfilepath: "../../integration/dockerfiles/Dockerfile_test_dockerignore_relative",
buildcontext: "../../integration/",
excluded: "ignore_relative/bar",
notExcluded: "ignore_relative/foo",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should test ignore/bar is not excluded along with ignore_relative/foo here to make sure context dockerignore is not used.? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good point, yes!

dockerfilepath: "../../integration/dockerfiles/Dockerfile_test_dockerignore",
buildcontext: "../../integration/",
excluded: "ignore/bar",
notExcluded: "ignore/foo",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test ignore_relative/bar is not excluded here to make sure Dockerfile_test_dockerignore_relative.dockerignore is not used?

@tejal29
Copy link
Member

tejal29 commented Oct 4, 2019

The newly added dockerfile failed

Error building images: Failed to build image gcr.io/kaniko-test/docker-dockerfile_test_dockerignore_relative with docker command "[docker build -t gcr.io/kaniko-test/docker-dockerfile_test_dockerignore_relative -f dockerfiles/Dockerfile_test_dockerignore_relative .]": exit status 1 Sending build context to Docker daemon  122.4kB

Step 1/2 : FROM scratch
 ---> 
Step 2/2 : COPY ignore_relative/* /foo
When using COPY with more than one source file, the destination must be a directory and end with a /
exit status 1
FAIL	github.com/GoogleContainerTools/kaniko/integration	265.988s

The way integration tests are setup,

  1. it first builds with docker build
  2. builds an image with kaniko
  3. Compared them

So, in your case step 1 fails.

@victornoel
Copy link
Contributor Author

@tejal29 apparently, docker only reads the Dockerfile.dockerignore when DOCKER_BUILDKIT=1 is used for docker build: moby/moby#12886 (comment)

I'm not sure what is the best course of action then now. Is there some way to alter the integration test for this one or should we just drop it because it's not supported by vanilla docker build?

@victornoel
Copy link
Contributor Author

victornoel commented Oct 4, 2019

@tejal29 I added another commit with more unit tests (and refactored it to separate them in multiple t.Run) per your comments

@@ -0,0 +1,5 @@
# This dockerfile makes sure Dockerfile.dockerignore is working
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this from integration test and rename this to "Dockerfile_dockeringore_relative"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tejal29 I'm not 100% sure how things work: if the file doesn't have the word test in it, then it won't be included in integration tests or is there more to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah you answered below, thx :)

@tejal29
Copy link
Member

tejal29 commented Oct 4, 2019

Thanks @victornoel, your integration test is still going to fail.

@tejal29 I added another commit with more unit tests (and refactored it to separate them in multiple t.Run) per your comments

Awesome!

The integration test will be fixed if you rename Dockerfile_test_dockerignore_relative to not match pattern

allDockerfiles, err := filepath.Glob(path.Join(dockerfilesPath, "Dockerfile_test*"))

@victornoel
Copy link
Contributor Author

@tejal29 it's pushed, do you want me to squash everything into one commit or should I leave it like that?

@victornoel
Copy link
Contributor Author

@tejal29 @kokoro-team seams to have remove the kokoro:run tag just after you added it :)

@tejal29
Copy link
Member

tejal29 commented Oct 4, 2019

@victornoel, whenever kokoro (internal jenkins) receives the notification via label, it kicks off a job to run the tests on the PR and removes the label.

@tejal29 tejal29 merged commit 9eb4a1c into GoogleContainerTools:master Oct 4, 2019
@victornoel
Copy link
Contributor Author

@tejal29 ah, ok, excellent, thank you for your help, my first PR here and in Go :)

@guillaume86
Copy link

Could this be upstreamed to moby/moby ?
I would love to have this option available for my windows builds.
As noted here it would probably get approved: moby/moby#12886 (comment)

@victornoel
Copy link
Contributor Author

@guillaume86 isn't what moby/buildkit#901 was for? (cited in GoogleContainerTools/skaffold#3837)

@guillaume86
Copy link

@victornoel Yes but buildkit is not supported on windows.

@victornoel
Copy link
Contributor Author

@guillaume86 ah, sorry about that, well here it's about kaniko, you would need to ask in the moby repository for implementing this feature, not sure you will get help here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Dockerfile.dockerignore
4 participants