mirror of https://github.com/containers/podman.git
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:
parent
e98e128012
commit
eadded9154
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/containers/podman/v5/cmd/podman/utils"
|
"github.com/containers/podman/v5/cmd/podman/utils"
|
||||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||||
"github.com/containers/podman/v5/pkg/env"
|
"github.com/containers/podman/v5/pkg/env"
|
||||||
|
"github.com/openshift/imagebuilder"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -585,9 +586,9 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *Buil
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.IgnoreFile != "" {
|
if flags.IgnoreFile != "" {
|
||||||
excludes, err := parseDockerignore(flags.IgnoreFile)
|
excludes, err := imagebuilder.ParseIgnore(flags.IgnoreFile)
|
||||||
if err != nil {
|
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
|
opts.Excludes = excludes
|
||||||
}
|
}
|
||||||
|
@ -628,21 +629,6 @@ func getDecryptConfig(decryptionKeys []string) (*encconfig.DecryptConfig, error)
|
||||||
return decConfig, nil
|
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 {
|
func areContainerfilesValid(contextDir string, containerFiles []string) error {
|
||||||
for _, f := range containerFiles {
|
for _, f := range containerFiles {
|
||||||
if isURL(f) || f == "/dev/stdin" {
|
if isURL(f) || f == "/dev/stdin" {
|
||||||
|
|
|
@ -584,6 +584,7 @@ Labels.\"io.buildah.version\" | $buildah_version
|
||||||
-subdir2/sub2 -subdir2/sub2.txt
|
-subdir2/sub2 -subdir2/sub2.txt
|
||||||
-subdir2/sub3 -subdir2/sub3.txt
|
-subdir2/sub3 -subdir2/sub3.txt
|
||||||
this-file-does-not-match-anything-in-ignore-file
|
this-file-does-not-match-anything-in-ignore-file
|
||||||
|
-foo
|
||||||
comment
|
comment
|
||||||
)
|
)
|
||||||
for f in "${files[@]}"; do
|
for f in "${files[@]}"; do
|
||||||
|
@ -613,6 +614,7 @@ subdir1
|
||||||
subdir2
|
subdir2
|
||||||
!*/sub1*
|
!*/sub1*
|
||||||
!subdir1/sub3*
|
!subdir1/sub3*
|
||||||
|
/foo
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Build an image. For .dockerignore
|
# Build an image. For .dockerignore
|
||||||
|
|
Loading…
Reference in New Issue