-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.sh
More file actions
executable file
·44 lines (32 loc) · 1.13 KB
/
cleanup.sh
File metadata and controls
executable file
·44 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
set -Eeuo pipefail;
log() {
local YELLOW='\033[1;33m';
local NC='\033[0m';
printf "${YELLOW} ${1} ${NC}\n";
}
clean_repo() {
log "Cleaning Images in ${1}";
local IMAGES=($(aws ecr list-images --repository-name ${1} --query 'imageIds[].imageDigest' --output text));
if [ ${#IMAGES[@]} -ne 0 ]; then
local COMMAND="aws ecr batch-delete-image --repository-name ${1} --no-cli-pager --image-ids ";
for image in "${IMAGES[@]}"; do
COMMAND+="imageDigest=${image} ";
done
eval "${COMMAND}";
fi
}
clean_bucket() {
log "Cleaning bucket ${1}"
aws s3 rm s3://${1} --recursive || true;
}
remove_stack() {
log "Removing stack ${1}"
aws cloudformation delete-stack --stack-name ${1} --no-cli-pager;
}
log "This script requires docker and aws cli(2.8.0) to be present and configured in your path";
ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text);
clean_bucket "${ACCOUNT_ID}-meter-readings-raw";
remove_stack "meter-reading-cloudformation";
clean_repo "meter-reading-processor";
clean_repo "meter-reading-api";
remove_stack "meter-reading-ecr";