Created
January 17, 2025 23:48
-
-
Save broguinn/9cbcaa00754d3c0b49ded6eb5be72c06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/cloud/infra/init/ecr-policy.json b/cloud/infra/init/ecr-policy.json | |
index ab2d9c1b5..205c4b0d6 100644 | |
--- a/cloud/infra/init/ecr-policy.json | |
+++ b/cloud/infra/init/ecr-policy.json | |
@@ -12,6 +12,19 @@ | |
"action": { | |
"type": "expire" | |
} | |
+ }, | |
+ { | |
+ "rulePriority": 2, | |
+ "description": "Expire images older than 60 days (https://docs.aws.amazon.com/AmazonECR/latest/userguide/service-quotas.html", | |
+ "selection": { | |
+ "tagStatus": "tagged", | |
+ "countType": "sinceImagePushed", | |
+ "countUnit": "days", | |
+ "countNumber": 120 | |
+ }, | |
+ "action": { | |
+ "type": "expire" | |
+ } | |
} | |
] | |
} | |
diff --git a/scripts/initialize_env.sh b/scripts/initialize_env.sh | |
index fcfb738c7..fe29d8476 100755 | |
--- a/scripts/initialize_env.sh | |
+++ b/scripts/initialize_env.sh | |
@@ -88,11 +88,11 @@ function delete_s3_bucket() { | |
# Function to create an ECR repository if it does not exist. | |
function create_ecr_repository() { | |
local repo_name=$1 | |
+ aws ecr put-lifecycle-policy --repository-name "$repo_name" --lifecycle-policy-text file://cloud/infra/init/ecr-policy.json | |
if aws ecr describe-repositories --repository-names "$repo_name" 2>&1 | grep -q 'RepositoryNotFoundException'; then | |
echo "Repository does not exist, creating repository: $repo_name" | |
# Create the repository since it does not exist | |
aws ecr create-repository --repository-name "$repo_name" | |
- aws ecr put-lifecycle-policy --repository-name "$repo_name" --lifecycle-policy-text file://cloud/infra/init/ecr-policy.json | |
else | |
echo "Repository already exists: $repo_name" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment