Skip to content

Commit eb63a1f

Browse files
Merge pull request #27005 from zifeitong/newer
Fix podman build "newer" pull policy
2 parents 5d04586 + 58e99d6 commit eb63a1f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

cmd/podman/common/build.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *Buil
326326
pullPolicy = buildahDefine.PullNever
327327
}
328328

329+
if strings.EqualFold(strings.TrimSpace(flags.Pull), "newer") {
330+
pullPolicy = buildahDefine.PullIfNewer
331+
}
332+
329333
var cleanTmpFile bool
330334
flags.Authfile, cleanTmpFile = buildahUtil.MirrorToTempFileIfPathIsDescriptor(flags.Authfile)
331335
if cleanTmpFile {

test/system/070-build.bats

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
load helpers
88
load helpers.network
9+
load helpers.registry
910

1011
@test "podman build - basic test" {
1112
rand_filename=$(random_string 20)
@@ -951,6 +952,61 @@ EOF
951952
"--pull-never fails with expected error message"
952953
}
953954

955+
@test "podman build --pull=newer" {
956+
skip_if_remote "tests depend on start_registry which does not work with podman-remote"
957+
start_registry
958+
959+
local registry=localhost:${PODMAN_LOGIN_REGISTRY_PORT}
960+
local image_for_test=$registry/i-$(safename):$(random_string)
961+
local authfile=$PODMAN_TMPDIR/authfile.json
962+
local tmpdir=$PODMAN_TMPDIR/build-test
963+
964+
run_podman login --authfile=$authfile \
965+
--tls-verify=false \
966+
--username ${PODMAN_LOGIN_USER} \
967+
--password ${PODMAN_LOGIN_PASS} \
968+
$registry
969+
970+
# Generate a test image and push it to the registry.
971+
# For safety in parallel runs, test image must be isolated
972+
# from $IMAGE. A simple add-tag will not work. (#23756)
973+
run_podman create -q $IMAGE true
974+
local tmpcid=$output
975+
run_podman commit -q $tmpcid $image_for_test
976+
run_podman rm $tmpcid
977+
run_podman image push --tls-verify=false --authfile=$authfile $image_for_test
978+
979+
local tmpdir=$PODMAN_TMPDIR/build-test
980+
mkdir -p $tmpdir
981+
982+
# Now build using $image_for_test
983+
cat >$tmpdir/Containerfile <<EOF
984+
FROM $image_for_test
985+
EOF
986+
987+
# Build the image
988+
run_podman build $tmpdir --pull=newer --tls-verify=false --authfile=$authfile
989+
is "$output" ".*pull" "pull seen in log"
990+
is "$output" ".*COMMIT" "COMMIT seen in log"
991+
992+
# Build again
993+
run_podman build $tmpdir --pull=newer --tls-verify=false --authfile=$authfile
994+
assert "$output" !~ "pull" "should not pull the image again"
995+
996+
# Now refresh the remote image
997+
run_podman create -q $IMAGE true
998+
local tmpcid=$output
999+
run_podman commit -q $tmpcid $image_for_test
1000+
run_podman rm $tmpcid
1001+
run_podman image push --tls-verify=false --authfile=$authfile $image_for_test
1002+
1003+
# Build one more time
1004+
run_podman build $tmpdir --pull=newer --tls-verify=false --authfile=$authfile
1005+
is "$output" ".*pull" "pull seen in log"
1006+
1007+
run_podman image rm --ignore $image_for_test
1008+
}
1009+
9541010
@test "podman build --logfile test" {
9551011
tmpdir=$PODMAN_TMPDIR/build-test
9561012
mkdir -p $tmpdir

0 commit comments

Comments
 (0)