Skip to content

Commit

Permalink
#592 CH-48 use rest api for image check
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Mar 7, 2023
1 parent 251db49 commit 5afb723
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM codefresh/cf-docker-puller
RUN docker images
11 changes: 8 additions & 3 deletions tools/deployment-cli-tools/ch_cli_tools/codefresh.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5afb723

Please sign in to comment.