mirror of
https://github.com/containers/podman.git
synced 2025-05-17 23:26:08 +08:00
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:
@ -581,9 +581,9 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
if _, found := r.URL.Query()["pull"]; found {
|
||||
switch strings.ToLower(query.Pull) {
|
||||
case "false":
|
||||
case "0", "f", "false":
|
||||
pullPolicy = buildahDefine.PullIfMissing
|
||||
case "true":
|
||||
case "on", "1", "t", "true":
|
||||
pullPolicy = buildahDefine.PullAlways
|
||||
default:
|
||||
policyFromMap, foundPolicy := buildahDefine.PolicyMap[query.Pull]
|
||||
|
@ -8,6 +8,7 @@ import time
|
||||
from typing import IO, List, Optional
|
||||
|
||||
from docker import errors
|
||||
from docker.errors import BuildError
|
||||
from docker.models.containers import Container
|
||||
from docker.models.images import Image
|
||||
from docker.models.volumes import Volume
|
||||
@ -282,3 +283,48 @@ class TestContainers(common.DockerTestCase):
|
||||
finally:
|
||||
ctr.stop()
|
||||
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")
|
||||
|
Reference in New Issue
Block a user