Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't ignore containerfiles outside of build context #20288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions pkg/bindings/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,15 +695,19 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
}
name = filepath.ToSlash(path)
}
excluded, err := pm.Matches(name) //nolint:staticcheck
if err != nil {
return fmt.Errorf("checking if %q is excluded: %w", name, err)
}
if excluded {
// Note: filepath.SkipDir is not possible to use given .dockerignore semantics.
// An exception to exclusions may include an excluded directory, therefore we
// are required to visit all files. :(
return nil
// If name is absolute path, then it has to be containerfile outside of build context.
// If not, we should check it for being excluded via pattern matcher.
if !filepath.IsAbs(name) {
excluded, err := pm.Matches(name) //nolint:staticcheck
if err != nil {
return fmt.Errorf("checking if %q is excluded: %w", name, err)
}
if excluded {
// Note: filepath.SkipDir is not possible to use given .dockerignore semantics.
// An exception to exclusions may include an excluded directory, therefore we
// are required to visit all files. :(
return nil
}
}
switch {
case dentry.Type().IsRegular(): // add file item
Expand Down
19 changes: 19 additions & 0 deletions test/system/070-build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,25 @@ EOF
run_podman rmi -f build_test
}

# Regression test for #20259
@test "podman build with ignore '*' and containerfile outside of build context" {
local tmpdir=$PODMAN_TMPDIR/build-test-$(random_string 10)
mkdir -p $tmpdir
mkdir -p $tmpdir/context

cat >$tmpdir/Containerfile <<EOF
FROM scratch
EOF

cat >$tmpdir/context/.containerignore <<EOF
*
EOF
run_podman build -t build_test -f $tmpdir/Containerfile $tmpdir/context

# Clean up
run_podman rmi -f build_test
}

@test "podman build - stdin test" {
# Random workdir, and random string to verify build output
workdir=/$(random_string 10)
Expand Down