This is an automated email from the ASF dual-hosted git repository.
pibizza pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-pipelines.git
The following commit(s) were added to refs/heads/main by this push:
new cf60ee4a Fixes #1405. Removing quay image cleanup since we are no
longer using quay. (#1234)
cf60ee4a is described below
commit cf60ee4a3f9232e74e4acb22f9fa9cb821d4fcb3
Author: Paolo Bizzarri <[email protected]>
AuthorDate: Tue Aug 6 14:15:09 2024 +0200
Fixes #1405. Removing quay image cleanup since we are no longer using quay.
(#1234)
---
.ci/jenkins/dsl/jobs.groovy | 7 ----
tools/clean-nightly-tags.py | 89 ---------------------------------------------
2 files changed, 96 deletions(-)
diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy
index 68578b34..56177469 100644
--- a/.ci/jenkins/dsl/jobs.groovy
+++ b/.ci/jenkins/dsl/jobs.groovy
@@ -35,7 +35,6 @@ setupUpdateJenkinsDependenciesJob()
if (isMainStream()) {
setupCreateIssueToolsJob()
setupCleanOldNamespacesToolsJob()
- setupCleanOldNightlyImagesToolsJob()
KogitoJobUtils.createQuarkusPlatformUpdateToolsJob(this, 'kogito')
@@ -84,12 +83,6 @@ void setupCleanOldNamespacesToolsJob() {
KogitoJobTemplate.createPipelineJob(this, jobParams)
}
-void setupCleanOldNightlyImagesToolsJob() {
- jobParams = JobParamsUtils.getBasicJobParams(this,
'kogito-clean-old-nightly-images', JobType.TOOLS,
"${jenkins_path}/Jenkinsfile.tools.clean-nightly-images")
- jobParams.triggers = [ cron : 'H 8 * * *' ]
- JobParamsUtils.setupJobParamsAgentDockerBuilderImageConfiguration(this,
jobParams)
- KogitoJobTemplate.createPipelineJob(this, jobParams)
-}
void setupCreateIssueToolsJob() {
jobParams = JobParamsUtils.getBasicJobParams(this, 'kogito-create-issue',
JobType.TOOLS, "${jenkins_path}/Jenkinsfile.tools.create-issue")
diff --git a/tools/clean-nightly-tags.py b/tools/clean-nightly-tags.py
deleted file mode 100644
index 4bdbcc76..00000000
--- a/tools/clean-nightly-tags.py
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/usr/bin/python3
-# Script responsible for removing extra tags of nightly images
-# QUAY_ACCESS_TOKEN is needed to set as environment variable before executing
script
-# The access token is used for authentication against the quay api.
-
-import os
-import json
-import requests
-from dateutil.relativedelta import *
-from dateutil.easter import *
-from dateutil.rrule import *
-from dateutil.parser import *
-from datetime import *
-import argparse
-
-
-try:
- QUAY_ACCESS_TOKEN = os.environ['QUAY_ACCESS_TOKEN']
-except KeyError as e:
- print("QUAY_ACCESS_TOKEN environment variable is not set. Please, set it
before running the script.")
- exit('Script exiting....')
-
-REGISTRY = "quay.io"
-NAMESPACE = "kiegroup"
-
-IMAGES={"kogito-data-index-nightly","kogito-quarkus-ubi8-nightly",
- "kogito-quarkus-jvm-ubi8-nightly","kogito-quarkus-ubi8-s2i-nightly",
- "kogito-springboot-ubi8-nightly","kogito-springboot-ubi8-s2i-nightly",
- "kogito-jobs-service-nightly","kogito-management-console-nightly",
- "kogito-cloud-operator-nightly"
- }
-def get_image_tags(image):
- '''
- Get all the available tags for the image
- :param image: image name whose tags needs to be fetched
- :return: tags: List of a strcut with tagName and lastModified as fields
- '''
- tags = []
- r =
requests.get('https://{0}/api/v1/repository/{1}/{2}/tag/?onlyActiveTags=true'.format(REGISTRY,NAMESPACE,image)
, headers={'content-type': 'application/json', 'Authorization': 'Bearer ' +
QUAY_ACCESS_TOKEN })
- image_metadata= json.loads(r.text)
- num_tags = len(image_metadata['tags'])
- for i in range(num_tags):
- tags.append({
- "tagName" : image_metadata['tags'][i]['name'],
- "lastModified" : parse(image_metadata['tags'][i]['last_modified'])
- })
-
- return tags
-
-def delete_image_tags(image, tags):
- '''
- Deletes the extra image tags from the repository
- :param image: Image whose tags needs to be deleted
- :param tags: List of struct with `tagName` and `last_modified` as fields
for the image that needs to be deleted
- '''
- if len(tags) == 0:
- print("Image {} does not have extra tags that needs to be
deleted".format(image))
- else:
- for tag in tags:
-
requests.delete('https://{0}/api/v1/repository/{1}/{2}/tag/{3}'.format(REGISTRY,NAMESPACE,image,tag['tagName'])
, headers={'content-type': 'application/json', 'Authorization': 'Bearer ' +
QUAY_ACCESS_TOKEN })
- print("Successfully deleted {} tags for the image
{}".format(len(tags),image))
-
-
-def get_and_delete_old_tags(image,max_tags):
- '''
- Driver function, calls the `get_image_tags` to get all the available tags
for a image
- finds the tags that needs to be deleted and then passes them to
`delete_image_tags`
- :param image: image name whose old tags needs to be deleted
- :param max_tags: Number of maximum tags to be kept for the image
- '''
- all_tags = get_image_tags(image)
-
- all_tags = list(filter(lambda tag: tag["tagName"]!="latest", all_tags))
#Filter out the entry with latest as tagName from the struct list
- all_tags.sort(key=lambda tagInfo: tagInfo.get("lastModified")) #sorting
in ascending order to get oldest tag on top
- delete_tags = []
- if (len(all_tags) - max_tags) > 0:
- delete_tags = all_tags[:len(all_tags) - max_tags]
-
- delete_image_tags(image,delete_tags)
-
-
-
-if __name__ == "__main__":
- parser = argparse.ArgumentParser(description='Removes extra tags from the
registry')
- parser.add_argument('--max-tags', dest='max_tags', default=50,type=int,
help='Defines the maximum number of tags for the image to be available,
defaults to 10')
- args = parser.parse_args()
-
- for image in IMAGES:
- get_and_delete_old_tags(image,args.max_tags)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]