diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 3fbc41f999..142204f277 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -302,7 +302,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO tarContent := []string{options.ContextDirectory} newContainerFiles := []string{} - dontexcludes := []string{"!Dockerfile", "!Containerfile"} + dontexcludes := []string{"!Dockerfile", "!Containerfile", "!.dockerignore", "!.containerignore"} for _, c := range containerFiles { if c == "/dev/stdin" { content, err := ioutil.ReadAll(os.Stdin) @@ -550,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)) diff --git a/test/system/070-build.bats b/test/system/070-build.bats index 7046625c61..06ff0c9e23 100644 --- a/test/system/070-build.bats +++ b/test/system/070-build.bats @@ -851,7 +851,7 @@ EOF run_podman rmi -f build_test } -@test "podman build -f test " { +@test "podman build -f test" { tmpdir=$PODMAN_TMPDIR/build-test subdir=$tmpdir/subdir mkdir -p $subdir @@ -877,6 +877,44 @@ EOF run_podman rmi -f build_test } +@test "podman build .dockerignore failure test" { + tmpdir=$PODMAN_TMPDIR/build-test + subdir=$tmpdir/subdir + mkdir -p $subdir + + cat >$tmpdir/.dockerignore <$tmpdir/Containerfile <$tmpdir/.containerignore <$tmpdir/.dockerignore <$tmpdir/Containerfile <