Merge pull request #19633 from Luap99/4.6.1-rhel

[v4.6.1-rhel] fix: pull param parsing for the /build compat ep
This commit is contained in:
OpenShift Merge Robot
2023-08-15 14:08:01 -02:30
committed by GitHub
2 changed files with 48 additions and 2 deletions

View File

@ -581,9 +581,9 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
} else { } else {
if _, found := r.URL.Query()["pull"]; found { if _, found := r.URL.Query()["pull"]; found {
switch strings.ToLower(query.Pull) { switch strings.ToLower(query.Pull) {
case "false": case "0", "f", "false":
pullPolicy = buildahDefine.PullIfMissing pullPolicy = buildahDefine.PullIfMissing
case "true": case "on", "1", "t", "true":
pullPolicy = buildahDefine.PullAlways pullPolicy = buildahDefine.PullAlways
default: default:
policyFromMap, foundPolicy := buildahDefine.PolicyMap[query.Pull] policyFromMap, foundPolicy := buildahDefine.PolicyMap[query.Pull]

View File

@ -8,6 +8,7 @@ import time
from typing import IO, List, Optional from typing import IO, List, Optional
from docker import errors from docker import errors
from docker.errors import BuildError
from docker.models.containers import Container from docker.models.containers import Container
from docker.models.images import Image from docker.models.images import Image
from docker.models.volumes import Volume from docker.models.volumes import Volume
@ -282,3 +283,48 @@ class TestContainers(common.DockerTestCase):
finally: finally:
ctr.stop() ctr.stop()
ctr.remove(force=True) ctr.remove(force=True)
def test_build_pull_true(self):
dockerfile = (
b"FROM quay.io/libpod/alpine:latest\n"
)
img: Image
img, logs = self.docker.images.build(fileobj=io.BytesIO(dockerfile), quiet=False, pull=True)
has_tried_pull = False
for e in logs:
if "stream" in e and "trying to pull" in e["stream"].lower():
has_tried_pull = True
self.assertTrue(has_tried_pull, "the build process has not tried to pull the base image")
def test_build_pull_one(self):
dockerfile = (
b"FROM quay.io/libpod/alpine:latest\n"
)
img: Image
img, logs = self.docker.images.build(fileobj=io.BytesIO(dockerfile), quiet=False, pull=1)
has_tried_pull = False
for e in logs:
if "stream" in e and "trying to pull" in e["stream"].lower():
has_tried_pull = True
self.assertTrue(has_tried_pull, "the build process has not tried to pull the base image")
def test_build_pull_false(self):
dockerfile = (
b"FROM quay.io/libpod/alpine:latest\n"
)
img, logs = self.docker.images.build(fileobj=io.BytesIO(dockerfile), quiet=False, pull=False)
has_tried_pull = False
for e in logs:
if "stream" in e and "trying to pull" in e["stream"].lower():
has_tried_pull = True
self.assertFalse(has_tried_pull, "the build process has tried tried to pull the base image")
def test_build_pull_never(self):
try:
dockerfile = (
b"FROM quay.io/libpod/does-not-exist:latest\n"
)
_, _ = self.docker.images.build(fileobj=io.BytesIO(dockerfile), quiet=False, pull="never")
self.fail("this line should not have been reached")
except BuildError as e:
self.assertTrue("image not known" in e.msg, "the exception should have been caused by missing base image")