-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8aaa1d1
Exclude files from dockerignore when uploading context tarball
guineveresaenger de13388
clean up ignore patterns
guineveresaenger 2df3c9a
Refactor ignorePatterns into separate function. Fix dockerignore path…
guineveresaenger 0d4091b
dockerignore details
guineveresaenger 3f33e4b
unskipping dotnet test
guineveresaenger a00e445
Do not ignore Dockerfile
guineveresaenger cd6172f
Improve readability for dockerfile exists condition
guineveresaenger 13ae4df
address review feedback
guineveresaenger a0002d3
undo excluding Dockerfiles
guineveresaenger b41834b
Do not dockerignore and
guineveresaenger 9c8d526
Add . to includeFiles
guineveresaenger 3c911ce
Add warning for build files potentially being copied to an image when…
guineveresaenger 28794f4
use length of ignorefiles to send warning to user
guineveresaenger 193cb5f
tone down message
guineveresaenger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ import ( | |
controlapi "github.com/moby/buildkit/api/services/control" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin" | ||
|
||
buildCmd "github.com/docker/cli/cli/command/image/build" | ||
) | ||
|
||
const defaultDockerfile = "Dockerfile" | ||
|
@@ -93,13 +95,29 @@ func (p *dockerNativeProvider) dockerBuild(ctx context.Context, | |
// make the build context and ensure to exclude dockerignore file patterns | ||
dockerIgnorePath := filepath.Join(build.Context, ".dockerignore") | ||
ignorePatterns, err := getIgnore(dockerIgnorePath) | ||
ignorePatterns = buildCmd.TrimBuildFilesFromExcludes(ignorePatterns, img.Build.Dockerfile, false) | ||
|
||
// warn user about accidentally copying build files | ||
if build.BuilderVersion == defaultBuilder { | ||
for _, pattern := range ignorePatterns { | ||
if pattern == "!Dockerfile" || pattern == "!.Dockerignore" { | ||
msg := "It looks like you are trying to dockerignore a build file such as Dockerfile or .dockerignore. " + | ||
"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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. how is this? |
||
err = p.host.Log(ctx, "warning", urn, msg) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
} | ||
} | ||
} | ||
|
||
if err != nil { | ||
return "", nil, err | ||
} | ||
|
||
tar, err := archive.TarWithOptions(img.Build.Context, &archive.TarOptions{ | ||
ExcludePatterns: ignorePatterns, | ||
IncludeFiles: []string{".", img.Build.Dockerfile, ".dockerignore"}, | ||
}) | ||
if err != nil { | ||
return "", nil, err | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ofbuildCmd.TrimBuildFilesFromExcludes
and checklen(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.
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!