Skip to content

Commit

Permalink
ci: debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
harshilgajera-crest committed Aug 9, 2024
1 parent b46aef5 commit d7ef48c
Showing 1 changed file with 12 additions and 44 deletions.
56 changes: 12 additions & 44 deletions splunk_matrix_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ def filter_image_list(images_list):
return filter_images


def get_build_number_1(token, latest_image_digest):
def get_build_number(token, latest_image_digest):
_, image_lists = get_images_list(token)
# images_list = [d["name"] for d in image_lists]
# images_list = filter_image_list(images_list)
match_and_return_name = next(
(
d["name"]
Expand All @@ -71,39 +69,16 @@ def get_build_number_1(token, latest_image_digest):
return match_and_return_name


def get_image_digest(token, image):
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.docker.distribution.manifest.v2+json",
}
image_digest_url = (
f"https://registry.hub.docker.com/v2/splunk/splunk/manifests/{image}"
def get_image_digest(token, image, image_list):
return next(
(
image_data['digest']
for d in image_list
if d['name'] == image
for image_data in d.get('images', [])
),
None
)
response = requests.get(image_digest_url, headers=headers)
response.raise_for_status()
if response.headers["Docker-Content-Digest"]:
return response.headers["Docker-Content-Digest"]
else:
token = get_token()
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.docker.distribution.manifest.v2+json",
}
image_digest_url = (
"https://registry.hub.docker.com/v2/splunk/splunk/manifests/{}".format(
image
)
)
response = requests.get(image_digest_url, headers=headers)
response.raise_for_status()
return response.headers["Docker-Content-Digest"]


def get_build_number(token, filter_images, latest_image_digest):
for image in filter_images:
if get_image_digest(token, image) == latest_image_digest:
return image


def update_splunk_version(token):
if os.path.isfile("config/splunk_matrix.conf"):
Expand All @@ -116,19 +91,12 @@ def update_splunk_version(token):
# images_list = [d["name"] for d in all_images]
for stanza in config.sections():
if stanza != "GENERAL":
print(images_list)
latest_image_version = get_latest_image(stanza, images_list)
stanza_image_version = config.get(stanza, "VERSION")
print(latest_image_version,stanza_image_version)
if check_image_version(latest_image_version, stanza_image_version):
config.set(stanza, "VERSION", latest_image_version)
latest_image_digest = get_image_digest(token, latest_image_version)
# build_number = get_build_number(
# token, filter_images, latest_image_digest
# )
print(latest_image_digest)
build_number = get_build_number_1(token, latest_image_digest)
print(build_number)
latest_image_digest = get_image_digest(token, latest_image_version, all_images)
build_number = get_build_number(token, latest_image_digest)
config.set(stanza, "BUILD", build_number)
update_file = True

Expand Down

0 comments on commit d7ef48c

Please sign in to comment.