Skip to content

Commit a235a9f

Browse files
authored
fix(cli): ecr garbage collection hangs when repository has no images (#31951)
because somehow I wrote `continue` instead of `break` in that instance... added a test to make sure. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a5fdf57 commit a235a9f

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/aws-cdk/lib/api/garbage-collection/garbage-collector.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ export class GarbageCollector {
635635

636636
// No images in the repository
637637
if (!response.imageIds || response.imageIds.length === 0) {
638-
continue;
638+
break;
639639
}
640640

641641
// map unique image digest to (possibly multiple) tags

packages/aws-cdk/test/api/garbage-collection.test.ts

+34
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,40 @@ describe('ECR Garbage Collection', () => {
633633
});
634634
});
635635

636+
test('succeeds when no images are present', async () => {
637+
mockTheToolkitInfo({
638+
Outputs: [
639+
{
640+
OutputKey: 'BootstrapVersion',
641+
OutputValue: '999',
642+
},
643+
],
644+
});
645+
646+
const mockListImagesNone = jest.fn().mockImplementation(() => {
647+
return Promise.resolve({
648+
images: [],
649+
});
650+
});
651+
652+
sdk.stubEcr({
653+
batchGetImage: mockBatchGetImage,
654+
describeImages: mockDescribeImages,
655+
batchDeleteImage: mockBatchDeleteImage,
656+
putImage: mockPutImage,
657+
listImages: mockListImagesNone,
658+
});
659+
660+
garbageCollector = garbageCollector = gc({
661+
type: 'ecr',
662+
rollbackBufferDays: 0,
663+
action: 'full',
664+
});
665+
666+
// succeeds without hanging
667+
await garbageCollector.garbageCollect();
668+
});
669+
636670
test('tags are unique', async () => {
637671
mockTheToolkitInfo({
638672
Outputs: [

0 commit comments

Comments
 (0)