Apply pep8
This commit is contained in:
parent
5819ded812
commit
955afa71ee
@ -3,7 +3,8 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import boto3
|
import boto3
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Implement basic public ECR lifecycle policy')
|
parser = argparse.ArgumentParser(
|
||||||
|
description='Implement basic public ECR lifecycle policy')
|
||||||
parser.add_argument('--repo', dest='repositoryName', action='store', required=True,
|
parser.add_argument('--repo', dest='repositoryName', action='store', required=True,
|
||||||
help='Name of the public ECR repository')
|
help='Name of the public ECR repository')
|
||||||
parser.add_argument('--keep', dest='keep', action='store', default=10, type=int,
|
parser.add_argument('--keep', dest='keep', action='store', default=10, type=int,
|
||||||
@ -15,7 +16,8 @@ args = parser.parse_args()
|
|||||||
|
|
||||||
client = boto3.client('ecr-public', region_name='us-east-1')
|
client = boto3.client('ecr-public', region_name='us-east-1')
|
||||||
|
|
||||||
images = client.describe_images(repositoryName=args.repositoryName)["imageDetails"]
|
images = client.describe_images(repositoryName=args.repositoryName)[
|
||||||
|
"imageDetails"]
|
||||||
|
|
||||||
untagged = []
|
untagged = []
|
||||||
kept = 0
|
kept = 0
|
||||||
@ -31,30 +33,31 @@ for image in sorted(images, key=lambda d: d['imagePushedAt'], reverse=True):
|
|||||||
# if registry uses image index all actual images will be untagged anyways
|
# if registry uses image index all actual images will be untagged anyways
|
||||||
if 'imageTags' not in image:
|
if 'imageTags' not in image:
|
||||||
untagged.append({"imageDigest": image['imageDigest']})
|
untagged.append({"imageDigest": image['imageDigest']})
|
||||||
#print("Delete untagged image {}".format(image["imageDigest"]))
|
# print("Delete untagged image {}".format(image["imageDigest"]))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# check for dev tags
|
# check for dev tags
|
||||||
if args.delete_dev:
|
if args.delete_dev:
|
||||||
_delete=True
|
_delete = True
|
||||||
for tag in image["imageTags"]:
|
for tag in image["imageTags"]:
|
||||||
# Look for at least one tag NOT beign a SemVer dev tag
|
# Look for at least one tag NOT beign a SemVer dev tag
|
||||||
if "-" not in tag:
|
if "-" not in tag:
|
||||||
_delete=False
|
_delete = False
|
||||||
if _delete:
|
if _delete:
|
||||||
print("Deleting development image {}".format(image["imageTags"]))
|
print("Deleting development image {}".format(image["imageTags"]))
|
||||||
untagged.append({"imageDigest": image['imageDigest']})
|
untagged.append({"imageDigest": image['imageDigest']})
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if kept < args.keep:
|
if kept < args.keep:
|
||||||
kept=kept+1
|
kept = kept+1
|
||||||
print("Keeping tagged image {}".format(image["imageTags"]))
|
print("Keeping tagged image {}".format(image["imageTags"]))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
print("Deleting tagged image {}".format(image["imageTags"]))
|
print("Deleting tagged image {}".format(image["imageTags"]))
|
||||||
untagged.append({"imageDigest": image['imageDigest']})
|
untagged.append({"imageDigest": image['imageDigest']})
|
||||||
|
|
||||||
deleted_images = client.batch_delete_image(repositoryName=args.repositoryName, imageIds=untagged)
|
deleted_images = client.batch_delete_image(
|
||||||
|
repositoryName=args.repositoryName, imageIds=untagged)
|
||||||
|
|
||||||
if deleted_images["imageIds"]:
|
if deleted_images["imageIds"]:
|
||||||
print("Deleted images: {}".format(deleted_images["imageIds"]))
|
print("Deleted images: {}".format(deleted_images["imageIds"]))
|
||||||
|
Loading…
Reference in New Issue
Block a user