From 1c81ffec4e242840ec51e03bd4dbdbdefea42e07 Mon Sep 17 00:00:00 2001 From: lixinyu Date: Thu, 4 Jan 2024 17:29:59 +0800 Subject: [PATCH] code: optimize docker image download progress * the openeuler build docker image download progress is not friendly to user, it sometimes output many lines rather than refresh immediately, whether download successful or failed oebuild will print successfully. It performance bad, not in our expect. we optimize docker image download progress and add a check if it download successful, of course, if failed, we print err log Signed-off-by: lixinyu --- src/oebuild/app/plugins/update/update.py | 6 +++- src/oebuild/docker_proxy.py | 38 +----------------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/src/oebuild/app/plugins/update/update.py b/src/oebuild/app/plugins/update/update.py index 951b9ef..7c742b7 100644 --- a/src/oebuild/app/plugins/update/update.py +++ b/src/oebuild/app/plugins/update/update.py @@ -206,4 +206,8 @@ class Update(OebuildCommand): client = DockerProxy() logger.info("Pull %s ...", docker_image) client.pull_image_with_progress(docker_image) - logger.info("Finished pull %s ...", docker_image) + # check if docker image had download successful + if not client.is_image_exists(docker_image): + logger.error("docker pull %s failed", docker_image) + sys.exit(-1) + logger.info("finishd pull %s ...", docker_image) diff --git a/src/oebuild/docker_proxy.py b/src/oebuild/docker_proxy.py index 43abf1e..3a491ca 100644 --- a/src/oebuild/docker_proxy.py +++ b/src/oebuild/docker_proxy.py @@ -13,13 +13,10 @@ See the Mulan PSL v2 for more details. import os from io import BytesIO import tarfile -from queue import Queue -import threading import docker from docker.errors import ImageNotFound, NotFound from docker.models.containers import Container -from reprint import output class DockerProxy: ''' @@ -66,40 +63,7 @@ class DockerProxy: ''' pull docker image and print progress ''' - def flush_print(in_q:Queue): - with output(output_type='dict') as output_lines: - while True: - data = in_q.get() - if data == "over": - break - if 'foot_msg' in data: - output_lines.append(data['foot_msg']) - continue - output_lines[data['id']] = data['message'] - - client = docker.APIClient() - repository,tag = self._get_image_name_tag(image_name=image_name) - p_q = Queue() - f_p = threading.Thread(target=flush_print, args=(p_q,)) - f_p.start() - resp = client.pull(repository=repository, tag=tag, stream=True, decode=True) - for line in resp: - if 'id' in line: - if "progressDetail" in line: - tmp_data = { - 'id': line['id'], - 'message': f"{line['status']}" - } - if line['progressDetail'] != {}: - tmp_data['message'] = f"{tmp_data['message']} {line['progress']}" - p_q.put(tmp_data) - else: - if 'status' in line: - if 'status' in line: - tmp_data = {'foot_msg': line['status']} - p_q.put(tmp_data) - - p_q.put("over") + os.system(f"docker pull {image_name}") def _get_image_name_tag(self, image_name: str): repository = image_name.split(':')[0] -- Gitee