Skip to content

Commit cbdbf1b

Browse files
authored
Update push-to-ecr.yml
1 parent f8a5348 commit cbdbf1b

1 file changed

Lines changed: 0 additions & 59 deletions

File tree

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

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -88,62 +88,3 @@ jobs:
8888
cd container-uploader
8989
yarn install
9090
node app.mjs
91-
92-
clean-untagged-image:
93-
needs: build-upload
94-
runs-on: ubuntu-24.04
95-
steps:
96-
- name: configure aws credentials
97-
uses: aws-actions/configure-aws-credentials@v4
98-
with:
99-
role-to-assume: ${{ secrets.role }}
100-
role-session-name: GitHub_Action_LambdaPerf_Session
101-
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-
echo "Fetching untagged images..."
107-
IMAGES_JSON=$(aws ecr list-images \
108-
--region "${AWS_REGION}" \
109-
--repository-name lambda-perf \
110-
--filter "tagStatus=UNTAGGED" \
111-
--query 'imageIds' \
112-
--output json)
113-
114-
COUNT=$(echo "$IMAGES_JSON" | jq length)
115-
if (( COUNT == 0 )); then
116-
echo "No untagged images found. Skipping deletion."
117-
exit 0
118-
fi
119-
120-
echo "Found $COUNT untagged images. Deleting in batches of 100..."
121-
122-
# read all images into an array
123-
mapfile -t IMAGES_ARRAY < <(echo "$IMAGES_JSON" | jq -c '.[]')
124-
125-
BATCH=()
126-
for IMG in "${IMAGES_ARRAY[@]}"; do
127-
BATCH+=("$IMG")
128-
129-
if (( ${#BATCH[@]} == 100 )); then
130-
BATCH_JSON=$(printf '%s\n' "${BATCH[@]}" | jq -s '.')
131-
echo "Deleting batch of 100 images..."
132-
aws ecr batch-delete-image \
133-
--region "${AWS_REGION}" \
134-
--repository-name lambda-perf \
135-
--image-ids "$BATCH_JSON"
136-
BATCH=()
137-
fi
138-
done
139-
140-
# delete leftover images
141-
if (( ${#BATCH[@]} > 0 )); then
142-
BATCH_JSON=$(printf '%s\n' "${BATCH[@]}" | jq -s '.')
143-
LEFT_COUNT=${#BATCH[@]}
144-
echo "Deleting final batch of $LEFT_COUNT images..."
145-
aws ecr batch-delete-image \
146-
--region "${AWS_REGION}" \
147-
--repository-name lambda-perf \
148-
--image-ids "$BATCH_JSON"
149-
fi

0 commit comments

Comments
 (0)