From eadded9154758ac8eb11a1016d69ae47c98a9ae8 Mon Sep 17 00:00:00 2001 From: flouthoc Date: Tue, 27 May 2025 09:51:00 -0700 Subject: [PATCH] build: reuse parse.ContainerIgnoreFile from buildah podman's logic to parse excludes from `--ignorefile` is not consistent with buildah, use code directly from imagebuilder. Closes: https://github.com/containers/podman/issues/25746 Signed-off-by: flouthoc --- cmd/podman/common/build.go | 20 +++----------------- test/system/070-build.bats | 2 ++ 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/cmd/podman/common/build.go b/cmd/podman/common/build.go index 1c4f6a577e..a213ffe596 100644 --- a/cmd/podman/common/build.go +++ b/cmd/podman/common/build.go @@ -25,6 +25,7 @@ import ( "github.com/containers/podman/v5/cmd/podman/utils" "github.com/containers/podman/v5/pkg/domain/entities" "github.com/containers/podman/v5/pkg/env" + "github.com/openshift/imagebuilder" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -585,9 +586,9 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *Buil } if flags.IgnoreFile != "" { - excludes, err := parseDockerignore(flags.IgnoreFile) + excludes, err := imagebuilder.ParseIgnore(flags.IgnoreFile) if err != nil { - return nil, fmt.Errorf("unable to obtain decrypt config: %w", err) + return nil, fmt.Errorf("unable to parse ignore file: %w", err) } opts.Excludes = excludes } @@ -628,21 +629,6 @@ func getDecryptConfig(decryptionKeys []string) (*encconfig.DecryptConfig, error) return decConfig, nil } -func parseDockerignore(ignoreFile string) ([]string, error) { - excludes := []string{} - ignore, err := os.ReadFile(ignoreFile) - if err != nil { - return excludes, err - } - for _, e := range strings.Split(string(ignore), "\n") { - if len(e) == 0 || e[0] == '#' { - continue - } - excludes = append(excludes, e) - } - return excludes, nil -} - func areContainerfilesValid(contextDir string, containerFiles []string) error { for _, f := range containerFiles { if isURL(f) || f == "/dev/stdin" { diff --git a/test/system/070-build.bats b/test/system/070-build.bats index 139756ae29..9d603864e7 100644 --- a/test/system/070-build.bats +++ b/test/system/070-build.bats @@ -584,6 +584,7 @@ Labels.\"io.buildah.version\" | $buildah_version -subdir2/sub2 -subdir2/sub2.txt -subdir2/sub3 -subdir2/sub3.txt this-file-does-not-match-anything-in-ignore-file + -foo comment ) for f in "${files[@]}"; do @@ -613,6 +614,7 @@ subdir1 subdir2 !*/sub1* !subdir1/sub3* +/foo EOF # Build an image. For .dockerignore