Created
May 31, 2018 13:07
-
-
Save riccardomc/4b1381d156d59da37dae370e00b3722e to your computer and use it in GitHub Desktop.
Quick and dirty script to check the number of images in ECR repositories and if there is an associated lifecycle policy
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
#!/bin/bash | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
REPOS=$(aws ecr describe-repositories --query 'repositories[*].repositoryName' | jq -r '.[]') | |
for r in $REPOS ; do | |
printf $r | |
COLOR=$GREEN | |
IMAGES=$(aws ecr describe-images --repository-name $r --query 'imageDetails[*].imageDigest' | jq -r '.[]') | |
IMAGES_COUNT=$(echo $IMAGES | wc -w) | |
if [ $IMAGES_COUNT -gt 500 ] ; then | |
COLOR=$RED | |
fi | |
printf " ${COLOR}$IMAGES_COUNT ${NC}" | |
COLOR=$GREEN | |
POLICY='policy' | |
$(aws ecr get-lifecycle-policy --repository-name $r > /dev/null 2>&1) | |
if [ $? != 0 ] ; then | |
COLOR=$RED | |
POLICY='no_policy' | |
fi | |
printf "${COLOR}$POLICY${NC}\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment