-
Notifications
You must be signed in to change notification settings - Fork 14
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
Correctly ignore files from .dockerignore #508
Conversation
Does the PR have any schema changes?Looking good! No breaking changes found. |
1 similar comment
Does the PR have any schema changes?Looking good! No breaking changes found. |
daf8b79
to
f82ec09
Compare
Does the PR have any schema changes?Looking good! No breaking changes found. |
2 similar comments
Does the PR have any schema changes?Looking good! No breaking changes found. |
Does the PR have any schema changes?Looking good! No breaking changes found. |
Does the PR have any schema changes?Looking good! No breaking changes found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, made some comments but fine to merge as is
dockerIgnore, err := os.ReadFile(dockerIgnorePath) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
// .dockerignore files are optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great comment! i found it helpful
Does the PR have any schema changes?Looking good! No breaking changes found. |
2 similar comments
Does the PR have any schema changes?Looking good! No breaking changes found. |
Does the PR have any schema changes?Looking good! No breaking changes found. |
… bug in hash function.
85e7346
to
b41834b
Compare
Does the PR have any schema changes?Looking good! No breaking changes found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last question, otherwise the changes LGTM
Does the PR have any schema changes?Looking good! No breaking changes found. |
… running in buildkit mode and attempting to dockerignore
Does the PR have any schema changes?Looking good! No breaking changes found. |
provider/image.go
Outdated
"Due to limitations when running this provider in Buildkit mode, your build files may get copied " + | ||
"into your image. Please ensure any copied file systems do not include build files." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only applies to .dockerignore and the Dockerfile. Perhaps we should tone this message down, that seems very low impact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this?
provider/image.go
Outdated
// warn user about accidentally copying build files | ||
if build.BuilderVersion == defaultBuilder { | ||
for _, pattern := range ignorePatterns { | ||
if pattern == "!Dockerfile" || pattern == "!.Dockerignore" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if these patterns will fire - .dockerignore
is typically lowercase.
Rather than try to check if the pattern matches, should we store the ignorePatterns
on line 97 in a different variable from the return value of buildCmd.TrimBuildFilesFromExcludes
and check len(before) != len(after)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignorePatterns, err := getIgnore(dockerIgnorePath)
// copy ignore patterns to compare
initialIgnorePatterns := append([]string, ignorePatterns...)
ignorePatterns = buildCmd.TrimBuildFilesFromExcludes(ignorePatterns, img.Build.Dockerfile, false)
// warn user about accidentally copying build files, link to GitHub Issue:
if build.BuilderVersion == defaultBuilder && len(initialIgnorePatterns) != len(ignorePatterns) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oooh, I like it! good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Does the PR have any schema changes?Looking good! No breaking changes found. |
Does the PR have any schema changes?Looking good! No breaking changes found. |
This PR fixes a bug discovered by a trial user:
It appears the Docker client does not handle the dockerignore file on its own, so this PR adds logic to ignore file patterns read from the dockerignore file.
The
.dockerignore
file is always expected to be at the root of the build context, both by convention and by design.We read the to-be-ignored patterns into a slice of strings, which can then be passed to the
TarOptions
asExcludePatterns
.The provider will now build an image which properly excludes the ignore files.
Additionally this PR creates a separate function to obtain the ignore file slice, since the hash function uses this information too.
This also fixes a minor bug in the hash function.