Created
June 5, 2018 19:46
-
-
Save talolard/5fde6e5c036e6fffbf588ddbe0100410 to your computer and use it in GitHub Desktop.
Get the most recent semver tag for an ECR repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pprint | |
import boto3 | |
import sys | |
repo_name = sys.argv[1] | |
print(repo_name) | |
client = boto3.client('ecr') | |
response = client.list_images( | |
repositoryName=repo_name, | |
filter={ | |
'tagStatus': 'TAGGED' | |
} | |
) | |
images = response['imageIds'] | |
def splitter(image): | |
tag = image['imageTag'] | |
try: | |
return tuple(map(int, tag.split('.'))) | |
except: | |
return (0,0,0) | |
sorted = images.sort(key=splitter,reverse=True ) | |
print(images[0]['imageTag']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this to know which tag of an image to deploy