Skip to content

Commit c105564

Browse files
committed
fix: ecr
1 parent 819fbd1 commit c105564

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

.github/workflows/push-to-ecr.yml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,38 @@ jobs:
9999
role-to-assume: ${{ secrets.role }}
100100
role-session-name: GitHub_Action_LambdaPerf_Session
101101
aws-region: ${{ inputs.environment == 'DEV' && secrets.devRegion || inputs.environment == 'PROD' && secrets.prodRegion }}
102-
- name: clean untagged images
103-
env:
104-
AWS_REGION: ${{ inputs.environment == 'DEV' && secrets.devRegion || inputs.environment == 'PROD' && secrets.prodRegion }}
105-
run: |
106-
UNTAGGED_IMAGES=$(aws ecr list-images --region "${AWS_REGION}" --repository-name lambda-perf --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json)
107-
if [[ "$UNTAGGED_IMAGES" == "[]" ]]; then
108-
echo "No untagged images found. Skipping deletion."
109-
else
110-
aws ecr batch-delete-image --region "${AWS_REGION}" --repository-name lambda-perf --image-ids "$UNTAGGED_IMAGES"
111-
fi
102+
- name: clean untagged images
103+
env:
104+
AWS_REGION: ${{ inputs.environment == 'DEV' && secrets.devRegion || inputs.environment == 'PROD' && secrets.prodRegion }}
105+
run: |
106+
echo "Fetching untagged images..."
107+
108+
IMAGES=$(aws ecr list-images \
109+
--region "${AWS_REGION}" \
110+
--repository-name lambda-perf \
111+
--filter "tagStatus=UNTAGGED" \
112+
--query 'imageIds' \
113+
--output json)
114+
115+
COUNT=$(echo "$IMAGES" | jq length)
116+
117+
if [ "$COUNT" -eq 0 ]; then
118+
echo "No untagged images found. Skipping deletion."
119+
exit 0
120+
fi
121+
122+
echo "Found $COUNT untagged images. Deleting in batches of 100..."
123+
124+
# Split into chunks of 100
125+
echo "$IMAGES" | jq -c '.[]' | split -l 100 -d batch_
126+
127+
for batch in batch_*; do
128+
IDS=$(jq -s '.' "$batch")
129+
echo "Deleting batch: $batch"
130+
aws ecr batch-delete-image \
131+
--region "${AWS_REGION}" \
132+
--repository-name lambda-perf \
133+
--image-ids "$IDS"
134+
done
135+
112136

0 commit comments

Comments
 (0)