Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): ecr garbage collection hangs when repository has no images #31951

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading