mirror of https://github.com/containers/podman.git
Merge pull request #10890 from rhatdan/main
Don't exclude Dockerfile, Containerfiles from tar content
This commit is contained in:
commit
788c2d136b
|
@ -301,6 +301,8 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
|
||||||
|
|
||||||
tarContent := []string{options.ContextDirectory}
|
tarContent := []string{options.ContextDirectory}
|
||||||
newContainerFiles := []string{}
|
newContainerFiles := []string{}
|
||||||
|
|
||||||
|
dontexcludes := []string{"!Dockerfile", "!Containerfile"}
|
||||||
for _, c := range containerFiles {
|
for _, c := range containerFiles {
|
||||||
if c == "/dev/stdin" {
|
if c == "/dev/stdin" {
|
||||||
content, err := ioutil.ReadAll(os.Stdin)
|
content, err := ioutil.ReadAll(os.Stdin)
|
||||||
|
@ -328,6 +330,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
|
||||||
// Do NOT add to tarfile
|
// Do NOT add to tarfile
|
||||||
if strings.HasPrefix(containerfile, contextDir+string(filepath.Separator)) {
|
if strings.HasPrefix(containerfile, contextDir+string(filepath.Separator)) {
|
||||||
containerfile = strings.TrimPrefix(containerfile, contextDir+string(filepath.Separator))
|
containerfile = strings.TrimPrefix(containerfile, contextDir+string(filepath.Separator))
|
||||||
|
dontexcludes = append(dontexcludes, "!"+containerfile)
|
||||||
} else {
|
} else {
|
||||||
// If Containerfile does not exists assume it is in context directory, do Not add to tarfile
|
// If Containerfile does not exists assume it is in context directory, do Not add to tarfile
|
||||||
if _, err := os.Lstat(containerfile); err != nil {
|
if _, err := os.Lstat(containerfile); err != nil {
|
||||||
|
@ -349,8 +352,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
|
||||||
}
|
}
|
||||||
params.Set("dockerfile", string(cFileJSON))
|
params.Set("dockerfile", string(cFileJSON))
|
||||||
}
|
}
|
||||||
|
tarfile, err := nTar(append(excludes, dontexcludes...), tarContent...)
|
||||||
tarfile, err := nTar(excludes, tarContent...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("cannot tar container entries %v error: %v", tarContent, err)
|
logrus.Errorf("cannot tar container entries %v error: %v", tarContent, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -509,6 +509,40 @@ EOF
|
||||||
done
|
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 '*'" {
|
||||||
|
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" {
|
@test "podman build - stdin test" {
|
||||||
# Random workdir, and random string to verify build output
|
# Random workdir, and random string to verify build output
|
||||||
workdir=/$(random_string 10)
|
workdir=/$(random_string 10)
|
||||||
|
|
Loading…
Reference in New Issue