Skip to content

Commit

Permalink
fixing the flow
Browse files Browse the repository at this point in the history
  • Loading branch information
atharvar28 committed Dec 7, 2023
1 parent 6e889c4 commit 191d320
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions jenkins-jobs-scripts/step10/check_ecr_image.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import os
import subprocess
import boto3
# import boto3

release = os.environ.get("RELEASE_VERSION")
failed_list = []

ecr = boto3.client('ecr')
# ecr = boto3.client('ecr')

def get_ecr_image():
def get_ecr_image(services):
# command to run gen3 ecr check
print("--------------------------------")
print(f"Checking ECR image for {services}...")
# get_image_command = ['gen3', 'ecr', 'describe-image', 'services', 'release']
# try:
# image = subprocess.run(get_image_command, shell=True, check=True)
# if 'imageDetails' in image.stdout:
# return
# except subprocess.CalledProcessError:
# print(f"ECR image with tag '{release}' does not exist in ECR repository '{services}'")
# failed_list.append(services)
try:
response = ecr.describe_images(
repositoryName='gen3/{services}',
imageIds=[{'imageTag': release}]
)
image_info = response['imageDetails'][0]
print(f"ECR image with tag '{release}' exists in repository 'gen3/{services}")
print(f"Image Tag: (image_info['imageTags'])")
return True
except ecr.exceptions.ImageNotFoundException:
print(f"ECR image with tag '{release}' does not exist in repository 'gen3/{services}")
return False
get_image_command = ['gen3', 'ecr', 'describe-image', services, release]
try:
image = subprocess.run(get_image_command, capture_output=True, text=True)
if image.returncode == 0:
print(f"Image {release} exists in repository {services}")
print(f"Image Details : {image.stdout}")
except subprocess.CalledProcessError:
print(f"ECR image with tag '{release}' does not exist in ECR repository '{services}'")
failed_list.append(services)
# try:
# response = ecr.describe_images(
# repositoryName='gen3/{services}', ## cant accept / only accepts - or _
# imageIds=[{'imageTag': release}]
# )
# image_info = response['imageDetails'][0]
# print(f"ECR image with tag '{release}' exists in repository 'gen3/{services}")
# print(f"Image Tag: (image_info['imageTags'])")
# return True
# except ecr.exceptions.ImageNotFoundException:
# print(f"ECR image with tag '{release}' does not exist in repository 'gen3/{services}")
# return False

# here
# key : github repo name
Expand All @@ -47,10 +49,9 @@ def get_ecr_image():
with open("../../repo_list.txt") as repoList:
for repo in repoList:
repo = repo.strip()
services = repo
if repo in repo_dict:
services = repo_dict[repo]
get_ecr_image()
get_ecr_image(services)
continue
elif repo == "sower-jobs":
print("Iterating through the list of images for sower-jobs")
Expand All @@ -63,12 +64,14 @@ def get_ecr_image():
]
for sowerjob in sower_jobs:
services = sowerjob.strip()
get_ecr_image()
get_ecr_image(services)
continue
get_ecr_image()
else:
services = repo
get_ecr_image(services)

print(f"List of repos that failed the check : {failed_list}")
# if the failed_list contains any repo name
# then the job should fail and print the list
if len(failed_list) > 0:
raise Exception(f"The following services do not have the quay image for {release}: {failed_list}")
if failed_list:
raise Exception(f"The following services do not have the ECR image for {release}: {failed_list}")

0 comments on commit 191d320

Please sign in to comment.