|
|
6810df |
From 6d7ab38f33edb9ab87a290a0c68cfd27b55b061f Mon Sep 17 00:00:00 2001
|
|
|
6810df |
From: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
6810df |
Date: Wed, 8 Jan 2020 11:02:05 -0500
|
|
|
6810df |
Subject: [PATCH 1/2] Check for .dockerignore specifically
|
|
|
6810df |
|
|
|
6810df |
When generating the list of exclusions to process .dockerignore
|
|
|
6810df |
contents, don't include .dockerignore if we don't have a .dockerignore
|
|
|
6810df |
file in the context directory. That way, if the file doesn't exist, and
|
|
|
6810df |
the caller didn't pass in any patterns, we get no patterns instead of
|
|
|
6810df |
just one ".dockerignore" pattern, and we can hit the faster copy path.
|
|
|
6810df |
|
|
|
6810df |
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
6810df |
|
|
|
6810df |
Closes: #2072
|
|
|
6810df |
Approved by: giuseppe
|
|
|
6810df |
---
|
|
|
6810df |
add.go | 10 ++++++++--
|
|
|
6810df |
1 file changed, 8 insertions(+), 2 deletions(-)
|
|
|
6810df |
|
|
|
6810df |
diff --git a/add.go b/add.go
|
|
|
6810df |
index b5119e369..e82a5ef9a 100644
|
|
|
6810df |
--- a/add.go
|
|
|
6810df |
+++ b/add.go
|
|
|
6810df |
@@ -215,7 +215,12 @@ func dockerIgnoreMatcher(lines []string, contextDir string) (*fileutils.PatternM
|
|
|
6810df |
if contextDir == "" {
|
|
|
6810df |
return nil, nil
|
|
|
6810df |
}
|
|
|
6810df |
- patterns := []string{".dockerignore"}
|
|
|
6810df |
+ // If there's no .dockerignore file, then we don't have to add a
|
|
|
6810df |
+ // pattern to tell copy logic to ignore it later.
|
|
|
6810df |
+ var patterns []string
|
|
|
6810df |
+ if _, err := os.Stat(filepath.Join(contextDir, ".dockerignore")); err == nil || !os.IsNotExist(err) {
|
|
|
6810df |
+ patterns = []string{".dockerignore"}
|
|
|
6810df |
+ }
|
|
|
6810df |
for _, ignoreSpec := range lines {
|
|
|
6810df |
ignoreSpec = strings.TrimSpace(ignoreSpec)
|
|
|
6810df |
// ignore comments passed back from .dockerignore
|
|
|
6810df |
@@ -224,7 +229,8 @@ func dockerIgnoreMatcher(lines []string, contextDir string) (*fileutils.PatternM
|
|
|
6810df |
}
|
|
|
6810df |
// if the spec starts with '!' it means the pattern
|
|
|
6810df |
// should be included. make a note so that we can move
|
|
|
6810df |
- // it to the front of the updated pattern
|
|
|
6810df |
+ // it to the front of the updated pattern, and insert
|
|
|
6810df |
+ // the context dir's path in between
|
|
|
6810df |
includeFlag := ""
|
|
|
6810df |
if strings.HasPrefix(ignoreSpec, "!") {
|
|
|
6810df |
includeFlag = "!"
|
|
|
6810df |
|
|
|
6810df |
From f999964084ce75c833b0cffd17fb09b947dad506 Mon Sep 17 00:00:00 2001
|
|
|
6810df |
From: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
6810df |
Date: Wed, 8 Jan 2020 11:04:57 -0500
|
|
|
6810df |
Subject: [PATCH 2/2] copyFileWithTar: close source files at the right time
|
|
|
6810df |
|
|
|
6810df |
Close source files after we've finished reading from them, rather than
|
|
|
6810df |
leaving it for later.
|
|
|
6810df |
|
|
|
6810df |
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
|
|
|
6810df |
|
|
|
6810df |
Closes: #2072
|
|
|
6810df |
Approved by: giuseppe
|
|
|
6810df |
---
|
|
|
6810df |
util.go | 9 +++------
|
|
|
6810df |
1 file changed, 3 insertions(+), 6 deletions(-)
|
|
|
6810df |
|
|
|
6810df |
diff --git a/util.go b/util.go
|
|
|
6810df |
index b4670e41c..2f923357c 100644
|
|
|
6810df |
--- a/util.go
|
|
|
6810df |
+++ b/util.go
|
|
|
6810df |
@@ -165,11 +165,6 @@ func (b *Builder) copyFileWithTar(tarIDMappingOptions *IDMappingOptions, chownOp
|
|
|
6810df |
if err != nil {
|
|
|
6810df |
return errors.Wrapf(err, "error opening %q to copy its contents", src)
|
|
|
6810df |
}
|
|
|
6810df |
- defer func() {
|
|
|
6810df |
- if err := f.Close(); err != nil {
|
|
|
6810df |
- logrus.Debugf("error closing %s: %v", fi.Name(), err)
|
|
|
6810df |
- }
|
|
|
6810df |
- }()
|
|
|
6810df |
}
|
|
|
6810df |
}
|
|
|
6810df |
|
|
|
6810df |
@@ -200,6 +195,9 @@ func (b *Builder) copyFileWithTar(tarIDMappingOptions *IDMappingOptions, chownOp
|
|
|
6810df |
logrus.Debugf("error copying contents of %s: %v", fi.Name(), err)
|
|
|
6810df |
copyErr = err
|
|
|
6810df |
}
|
|
|
6810df |
+ if err = srcFile.Close(); err != nil {
|
|
|
6810df |
+ logrus.Debugf("error closing %s: %v", fi.Name(), err)
|
|
|
6810df |
+ }
|
|
|
6810df |
}
|
|
|
6810df |
if err = writer.Close(); err != nil {
|
|
|
6810df |
logrus.Debugf("error closing write pipe for %s: %v", hdr.Name, err)
|
|
|
6810df |
@@ -213,7 +211,6 @@ func (b *Builder) copyFileWithTar(tarIDMappingOptions *IDMappingOptions, chownOp
|
|
|
6810df |
if err == nil {
|
|
|
6810df |
err = copyErr
|
|
|
6810df |
}
|
|
|
6810df |
- f = nil
|
|
|
6810df |
if pipeWriter != nil {
|
|
|
6810df |
pipeWriter.Close()
|
|
|
6810df |
}
|