summaryrefslogtreecommitdiff
path: root/pkg/bindings/images/build.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/bindings/images/build.go')
-rw-r--r--pkg/bindings/images/build.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index 95d9d4df7..142204f27 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -301,6 +301,8 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
tarContent := []string{options.ContextDirectory}
newContainerFiles := []string{}
+
+ dontexcludes := []string{"!Dockerfile", "!Containerfile", "!.dockerignore", "!.containerignore"}
for _, c := range containerFiles {
if c == "/dev/stdin" {
content, err := ioutil.ReadAll(os.Stdin)
@@ -328,6 +330,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
// Do NOT add to tarfile
if strings.HasPrefix(containerfile, contextDir+string(filepath.Separator)) {
containerfile = strings.TrimPrefix(containerfile, contextDir+string(filepath.Separator))
+ dontexcludes = append(dontexcludes, "!"+containerfile)
} else {
// If Containerfile does not exists assume it is in context directory, do Not add to tarfile
if _, err := os.Lstat(containerfile); err != nil {
@@ -349,8 +352,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
}
params.Set("dockerfile", string(cFileJSON))
}
-
- tarfile, err := nTar(excludes, tarContent...)
+ tarfile, err := nTar(append(excludes, dontexcludes...), tarContent...)
if err != nil {
logrus.Errorf("cannot tar container entries %v error: %v", tarContent, err)
return nil, err
@@ -548,9 +550,13 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
}
func parseDockerignore(root string) ([]string, error) {
- ignore, err := ioutil.ReadFile(filepath.Join(root, ".dockerignore"))
- if err != nil && !os.IsNotExist(err) {
- return nil, errors.Wrapf(err, "error reading .dockerignore: '%s'", root)
+ ignore, err := ioutil.ReadFile(filepath.Join(root, ".containerignore"))
+ if err != nil {
+ var dockerIgnoreErr error
+ ignore, dockerIgnoreErr = ioutil.ReadFile(filepath.Join(root, ".dockerignore"))
+ if dockerIgnoreErr != nil && !os.IsNotExist(dockerIgnoreErr) {
+ return nil, errors.Wrapf(err, "error reading .containerignore: '%s'", root)
+ }
}
rawexcludes := strings.Split(string(ignore), "\n")
excludes := make([]string, 0, len(rawexcludes))