Skip to content

Commit

Permalink
fix(cli): ecr garbage collection hangs when repository has no images (#…
Browse files Browse the repository at this point in the history
…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*
  • Loading branch information
kaizencc authored Oct 30, 2024
1 parent a5fdf57 commit a235a9f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ export class GarbageCollector {

// No images in the repository
if (!response.imageIds || response.imageIds.length === 0) {
continue;
break;
}

// map unique image digest to (possibly multiple) tags
Expand Down
34 changes: 34 additions & 0 deletions packages/aws-cdk/test/api/garbage-collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,40 @@ describe('ECR Garbage Collection', () => {
});
});

test('succeeds when no images are present', async () => {
mockTheToolkitInfo({
Outputs: [
{
OutputKey: 'BootstrapVersion',
OutputValue: '999',
},
],
});

const mockListImagesNone = jest.fn().mockImplementation(() => {
return Promise.resolve({
images: [],
});
});

sdk.stubEcr({
batchGetImage: mockBatchGetImage,
describeImages: mockDescribeImages,
batchDeleteImage: mockBatchDeleteImage,
putImage: mockPutImage,
listImages: mockListImagesNone,
});

garbageCollector = garbageCollector = gc({
type: 'ecr',
rollbackBufferDays: 0,
action: 'full',
});

// succeeds without hanging
await garbageCollector.garbageCollect();
});

test('tags are unique', async () => {
mockTheToolkitInfo({
Outputs: [
Expand Down

0 comments on commit a235a9f

Please sign in to comment.