From 15caebfe561952eaadd4896b7efb56f26724cce5 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 27 Jan 2021 16:49:47 +0100 Subject: podman build --pull: use correct policy The `--pull` flag should be using the "pull if newer" pull policy rather than "pull always". This aligns with what the help message states, what Buildah does and, according to #9111, what was done before, Also add a test to prevent future regressions. Fixes: #9111 Signed-off-by: Valentin Rothberg --- cmd/podman/images/build.go | 2 +- test/system/070-build.bats | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go index 4219e325b..957c0ac2d 100644 --- a/cmd/podman/images/build.go +++ b/cmd/podman/images/build.go @@ -266,7 +266,7 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil pullPolicy := imagebuildah.PullIfMissing if c.Flags().Changed("pull") && flags.Pull { - pullPolicy = imagebuildah.PullAlways + pullPolicy = imagebuildah.PullIfNewer } if flags.PullAlways { pullPolicy = imagebuildah.PullAlways diff --git a/test/system/070-build.bats b/test/system/070-build.bats index 7a42a4c18..6b5bc68fb 100644 --- a/test/system/070-build.bats +++ b/test/system/070-build.bats @@ -29,6 +29,29 @@ EOF run_podman rmi -f build_test } +@test "podman build - basic test with --pull" { + rand_filename=$(random_string 20) + rand_content=$(random_string 50) + + run_podman tag $IMAGE localhost/localonly + + tmpdir=$PODMAN_TMPDIR/build-test + mkdir -p $tmpdir + dockerfile=$tmpdir/Dockerfile + cat >$dockerfile < /$rand_filename +EOF + # With --pull, Podman would try to pull a newer image but use the local one + # if present. See #9111. + run_podman build --pull -t build_test $tmpdir + + run_podman run --rm build_test cat /$rand_filename + is "$output" "$rand_content" "reading generated file in image" + + run_podman rmi -f build_test localhost/localonly +} + @test "podman build - global runtime flags test" { skip_if_remote "--runtime-flag flag not supported for remote" -- cgit v1.2.3-54-g00ecf