tests/docker: remove FROM qemu/ support from docker.py

We want to migrate from docker.py to building our images directly with
docker/podman. Before we get there we need to make sure we don't
re-introduce our layered builds so bug out if we see FROM qemu/ in a
Dockerfile.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Acked-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220914155950.804707-30-alex.bennee@linaro.org>
This commit is contained in:
Alex Bennée 2022-09-14 16:59:49 +01:00
parent 4239162add
commit 07056db1b5

View File

@ -205,22 +205,17 @@ def _read_qemu_dockerfile(img_name):
return _read_dockerfile(df) return _read_dockerfile(df)
def _dockerfile_preprocess(df): def _dockerfile_verify_flat(df):
out = "" "Verify we do not include other qemu/ layers"
for l in df.splitlines(): for l in df.splitlines():
if len(l.strip()) == 0 or l.startswith("#"): if len(l.strip()) == 0 or l.startswith("#"):
continue continue
from_pref = "FROM qemu/" from_pref = "FROM qemu/"
if l.startswith(from_pref): if l.startswith(from_pref):
# TODO: Alternatively we could replace this line with "FROM $ID" print("We no longer support multiple QEMU layers.")
# where $ID is the image's hex id obtained with print("Dockerfiles should be flat, ideally created by lcitool")
# $ docker images $IMAGE --format="{{.Id}}" return False
# but unfortunately that's not supported by RHEL 7. return True
inlining = _read_qemu_dockerfile(l[len(from_pref):])
out += _dockerfile_preprocess(inlining)
continue
out += l + "\n"
return out
class Docker(object): class Docker(object):
@ -309,23 +304,10 @@ class Docker(object):
if argv is None: if argv is None:
argv = [] argv = []
# pre-calculate the docker checksum before any if not _dockerfile_verify_flat(dockerfile):
# substitutions we make for caching return -1
checksum = _text_checksum(_dockerfile_preprocess(dockerfile))
if registry is not None: checksum = _text_checksum(dockerfile)
sources = re.findall("FROM qemu\/(.*)", dockerfile)
# Fetch any cache layers we can, may fail
for s in sources:
pull_args = ["pull", "%s/qemu/%s" % (registry, s)]
if self._do(pull_args, quiet=quiet) != 0:
registry = None
break
# Make substitutions
if registry is not None:
dockerfile = dockerfile.replace("FROM qemu/",
"FROM %s/qemu/" %
(registry))
tmp_df = tempfile.NamedTemporaryFile(mode="w+t", tmp_df = tempfile.NamedTemporaryFile(mode="w+t",
encoding='utf-8', encoding='utf-8',
@ -371,7 +353,7 @@ class Docker(object):
checksum = self.get_image_dockerfile_checksum(tag) checksum = self.get_image_dockerfile_checksum(tag)
except Exception: except Exception:
return False return False
return checksum == _text_checksum(_dockerfile_preprocess(dockerfile)) return checksum == _text_checksum(dockerfile)
def run(self, cmd, keep, quiet, as_user=False): def run(self, cmd, keep, quiet, as_user=False):
label = uuid.uuid4().hex label = uuid.uuid4().hex