Skip to content

Commit 1b2fadd

Browse files
Merge pull request #19633 from Luap99/4.6.1-rhel
[v4.6.1-rhel] fix: pull param parsing for the /build compat ep
2 parents 13fb059 + dbb22be commit 1b2fadd

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

pkg/api/handlers/compat/images_build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,9 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
581581
} else {
582582
if _, found := r.URL.Query()["pull"]; found {
583583
switch strings.ToLower(query.Pull) {
584-
case "false":
584+
case "0", "f", "false":
585585
pullPolicy = buildahDefine.PullIfMissing
586-
case "true":
586+
case "on", "1", "t", "true":
587587
pullPolicy = buildahDefine.PullAlways
588588
default:
589589
policyFromMap, foundPolicy := buildahDefine.PolicyMap[query.Pull]

test/python/docker/compat/test_containers.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import IO, List, Optional
99

1010
from docker import errors
11+
from docker.errors import BuildError
1112
from docker.models.containers import Container
1213
from docker.models.images import Image
1314
from docker.models.volumes import Volume
@@ -282,3 +283,48 @@ def wait_and_start():
282283
finally:
283284
ctr.stop()
284285
ctr.remove(force=True)
286+
287+
def test_build_pull_true(self):
288+
dockerfile = (
289+
b"FROM quay.io/libpod/alpine:latest\n"
290+
)
291+
img: Image
292+
img, logs = self.docker.images.build(fileobj=io.BytesIO(dockerfile), quiet=False, pull=True)
293+
has_tried_pull = False
294+
for e in logs:
295+
if "stream" in e and "trying to pull" in e["stream"].lower():
296+
has_tried_pull = True
297+
self.assertTrue(has_tried_pull, "the build process has not tried to pull the base image")
298+
299+
def test_build_pull_one(self):
300+
dockerfile = (
301+
b"FROM quay.io/libpod/alpine:latest\n"
302+
)
303+
img: Image
304+
img, logs = self.docker.images.build(fileobj=io.BytesIO(dockerfile), quiet=False, pull=1)
305+
has_tried_pull = False
306+
for e in logs:
307+
if "stream" in e and "trying to pull" in e["stream"].lower():
308+
has_tried_pull = True
309+
self.assertTrue(has_tried_pull, "the build process has not tried to pull the base image")
310+
311+
def test_build_pull_false(self):
312+
dockerfile = (
313+
b"FROM quay.io/libpod/alpine:latest\n"
314+
)
315+
img, logs = self.docker.images.build(fileobj=io.BytesIO(dockerfile), quiet=False, pull=False)
316+
has_tried_pull = False
317+
for e in logs:
318+
if "stream" in e and "trying to pull" in e["stream"].lower():
319+
has_tried_pull = True
320+
self.assertFalse(has_tried_pull, "the build process has tried tried to pull the base image")
321+
322+
def test_build_pull_never(self):
323+
try:
324+
dockerfile = (
325+
b"FROM quay.io/libpod/does-not-exist:latest\n"
326+
)
327+
_, _ = self.docker.images.build(fileobj=io.BytesIO(dockerfile), quiet=False, pull="never")
328+
self.fail("this line should not have been reached")
329+
except BuildError as e:
330+
self.assertTrue("image not known" in e.msg, "the exception should have been caused by missing base image")

0 commit comments

Comments
 (0)