Skip to content

Commit

Permalink
Honor the --layers flag
Browse files Browse the repository at this point in the history
Currently the --layers flag set by the user is ignored, and only the BUILDAH_LAYERS
environment variable being set is observed.

Fixes: containers#8643

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Dec 9, 2020
1 parent dd295f2 commit 0033f3f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
7 changes: 2 additions & 5 deletions cmd/podman/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func buildFlags(cmd *cobra.Command) {
// --layers flag
flag = layerFlags.Lookup("layers")
useLayersVal := useLayers()
buildOpts.Layers = useLayersVal == "true"
if err := flag.Value.Set(useLayersVal); err != nil {
logrus.Errorf("unable to set --layers to %v: %v", useLayersVal, err)
}
Expand Down Expand Up @@ -274,11 +275,7 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
}
}
}
// Check to see if the BUILDAH_LAYERS environment variable is set and
// override command-line.
if _, ok := os.LookupEnv("BUILDAH_LAYERS"); ok {
flags.Layers = true
}
flags.Layers = buildOpts.Layers

// `buildah bud --layers=false` acts like `docker build --squash` does.
// That is all of the new layers created during the build process are
Expand Down
42 changes: 42 additions & 0 deletions test/system/070-build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,48 @@ a${random3}z"
run_podman rmi -f build_test
}

@test "podman build --layers test" {
rand_content=$(random_string 50)
tmpdir=$PODMAN_TMPDIR/build-test
run mkdir -p $tmpdir
containerfile=$tmpdir/Containerfile
cat >$containerfile <<EOF
FROM $IMAGE
RUN echo $rand_content
EOF

# Build twice to make sure second time uses cache
run_podman build -t build_test $tmpdir
if [[ "$output" =~ "Using cache" ]]; then
is "$output" "[no instance of 'Using cache']" "no cache used"
fi

run_podman build -t build_test $tmpdir
is "$output" ".*cache" "used cache"

run_podman build -t build_test --layers=true $tmpdir
is "$output" ".*cache" "used cache"

run_podman build -t build_test --layers=false $tmpdir
if [[ "$output" =~ "Using cache" ]]; then
is "$output" "[no instance of 'Using cache']" "no cache used"
fi

BUILDAH_LAYERS=false run_podman build -t build_test $tmpdir
if [[ "$output" =~ "Using cache" ]]; then
is "$output" "[no instance of 'Using cache']" "no cache used"
fi

BUILDAH_LAYERS=false run_podman build -t build_test --layers=1 $tmpdir
is "$output" ".*cache" "used cache"

BUILDAH_LAYERS=1 run_podman build -t build_test --layers=false $tmpdir
if [[ "$output" =~ "Using cache" ]]; then
is "$output" "[no instance of 'Using cache']" "no cache used"
fi

run_podman rmi -a --force
}

function teardown() {
# A timeout or other error in 'build' can leave behind stale images
Expand Down

0 comments on commit 0033f3f

Please sign in to comment.