From 48ff2ef5a36df054a6aaf30ee34574ee1ec0b6d7 Mon Sep 17 00:00:00 2001
From: Daniel J Walsh <dwalsh@redhat.com>
Date: Fri, 9 Jul 2021 07:50:28 -0400
Subject: Don't exclude Dockerfile, Containerfiles from tar content

If the user specifies "*" in a .dockerignore or a .containerignore
then podman-remote build should not exclude the Dockerfile or
Containerfile or any content pointed to by `-f` in the context
directory.

We still need these files on the server side to complete the build.

Fixes: https://github.com/containers/podman/issues/9867

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
---
 pkg/bindings/images/build.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'pkg')

diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index 95d9d4df7..3fbc41f99 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"}
 	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
-- 
cgit v1.2.3-54-g00ecf