Skip to content

Commit

Permalink
Merge pull request #20288 from albnnc/fix/do-not-ignore-external-cont…
Browse files Browse the repository at this point in the history
…ainerfiles

fix: don't ignore containerfiles outside of build context
  • Loading branch information
openshift-ci[bot] authored Oct 9, 2023
2 parents 0dba5ac + 732cec7 commit b2c5418
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
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

1 comment on commit b2c5418

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.