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

Don't exclude Dockerfile, Containerfiles from tar content #10890

Merged
merged 1 commit into from
Jul 12, 2021
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
6 changes: 4 additions & 2 deletions pkg/bindings/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO

tarContent := []string{options.ContextDirectory}
newContainerFiles := []string{}

dontexcludes := []string{"!Dockerfile", "!Containerfile"}
for _, c := range containerFiles {
if c == "/dev/stdin" {
content, err := ioutil.ReadAll(os.Stdin)
Expand Down Expand Up @@ -328,6 +330,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
// Do NOT add to tarfile
if strings.HasPrefix(containerfile, contextDir+string(filepath.Separator)) {
containerfile = strings.TrimPrefix(containerfile, contextDir+string(filepath.Separator))
dontexcludes = append(dontexcludes, "!"+containerfile)
} else {
// If Containerfile does not exists assume it is in context directory, do Not add to tarfile
if _, err := os.Lstat(containerfile); err != nil {
Expand All @@ -349,8 +352,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
}
params.Set("dockerfile", string(cFileJSON))
}

tarfile, err := nTar(excludes, tarContent...)
tarfile, err := nTar(append(excludes, dontexcludes...), tarContent...)
if err != nil {
logrus.Errorf("cannot tar container entries %v error: %v", tarContent, err)
return nil, err
Expand Down
34 changes: 34 additions & 0 deletions test/system/070-build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,40 @@ EOF
done
}

# Regression test for #9867
# Make sure that if you exclude everything in context dir, that
# the Containerfile/Dockerfile in the context dir are used
@test "podman build with ignore '*'" {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment that this is a regression test for ##9867?

local tmpdir=$PODMAN_TMPDIR/build-test-$(random_string 10)
mkdir -p $tmpdir

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

cat >$tmpdir/.dockerignore <<EOF
*
EOF

run_podman build -t build_test $tmpdir

# Rename Containerfile to Dockerfile
mv $tmpdir/Containerfile $tmpdir/Dockerfile

run_podman build -t build_test $tmpdir

# Rename Dockerfile to foofile
mv $tmpdir/Dockerfile $tmpdir/foofile

run_podman 125 build -t build_test $tmpdir
is "$output" ".*Dockerfile: no such file or directory"

run_podman build -t build_test -f $tmpdir/foofile $tmpdir

# 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