mirror of
https://github.com/containers/podman.git
synced 2025-10-14 09:45:59 +08:00
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 <flouthoc.git@gmail.com>
This commit is contained in:
@ -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" {
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user