Skip to content

Commit

Permalink
issue #26: sys.exit() if no previous tag was found
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCardin committed Jan 31, 2024
1 parent d8798d3 commit c7a7c0a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions remove-previous-image/remove-previous-image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
import requests
import sys
from requests.auth import HTTPBasicAuth

"""
Expand All @@ -18,7 +19,7 @@ def delete_old_image(version_id, org, headers, auth):
if response.status_code == 204:
print(f'Previous container deleted!')
else:
raise Exception(f"error deleting the previous container: {response.status_code} {response.text}")
raise Exception(f"Error deleting the previous container: {response.status_code} {response.text}")

"""
Find the previous tag for a specific container.
Expand Down Expand Up @@ -75,8 +76,15 @@ def print_console(message):
response = get_container_tags(org, container_name, auth, headers, container_path)
print("Done!")

"""
If there's no previous image to delete, we will stop the script (sys.exit()).
"""
print_console(f"Looking for the previous tag...")
previous_tag, version_id = find_previous_container_tag(response.json(), unique_tag)
try:
previous_tag, version_id = find_previous_container_tag(response.json(), unique_tag)
except Exception as e:
print(e)
sys.exit()
print("Done!")

print_console(f"Deleting the previous container with tag ({previous_tag}) and version_id {version_id}...")
Expand Down

0 comments on commit c7a7c0a

Please sign in to comment.