From 5afb7231c96995f375280d54c4000402ddecd8e5 Mon Sep 17 00:00:00 2001 From: Filippo Ledda Date: Tue, 7 Mar 2023 19:35:16 +0100 Subject: [PATCH] #592 CH-48 use rest api for image check --- deployment/Dockerfile | 2 ++ tools/deployment-cli-tools/ch_cli_tools/codefresh.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 deployment/Dockerfile diff --git a/deployment/Dockerfile b/deployment/Dockerfile new file mode 100644 index 00000000..05f1e561 --- /dev/null +++ b/deployment/Dockerfile @@ -0,0 +1,2 @@ +FROM codefresh/cf-docker-puller +RUN docker images diff --git a/tools/deployment-cli-tools/ch_cli_tools/codefresh.py b/tools/deployment-cli-tools/ch_cli_tools/codefresh.py index 98bc454e..9e3f520d 100644 --- a/tools/deployment-cli-tools/ch_cli_tools/codefresh.py +++ b/tools/deployment-cli-tools/ch_cli_tools/codefresh.py @@ -1,6 +1,6 @@ import os from os.path import join, relpath, exists, dirname -import subprocess +import requests import logging from cloudharness_model.models.api_tests_config import ApiTestsConfig @@ -38,8 +38,13 @@ def write_env_file(helm_values: HarnessMainConfig, filename): logging.info("Create env file with image info %s", filename) def check_image_exists(name, image): - p = subprocess.run(f"docker manifest inspect {image}".split()) - if p.returncode == 0: + tag = image.split(":")[1] + chunks = image.split(":")[0].split("/") + registry = chunks[0] if "." in chunks[0] else "docker.io" + image_name = "/".join(chunks[1::] if "." in chunks[0] else chunks[0::]) + api_url = f"https://{registry}/v2/{image_name}/manifests/{tag}" + resp = requests.get(api_url) + if resp.status_code == 200: env[app_specific_tag_variable(name) + "_EXISTS"] = 1 else: env[app_specific_tag_variable(name) + "_NEW"] = 1