Merge pull request #26216 from flouthoc/reuse-excludes

build: reuse `parse.ContainerIgnoreFile` from buildah
This commit is contained in:
openshift-merge-bot[bot] 2025-06-03 23:59:19 +00:00 committed by GitHub
commit 6a39f37845
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 17 deletions

View File

@ -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" {

View File

@ -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