Skip to content

Commit

Permalink
Merge branch 'main' into organization-webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
dviryamin authored Oct 26, 2024
2 parents c8c5f0b + 5c6cc5e commit 6cf830d
Show file tree
Hide file tree
Showing 17 changed files with 1,121 additions and 340 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.v2.alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.164.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.164.0-alpha.0...v2.164.1-alpha.0) (2024-10-25)

## [2.164.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.163.1-alpha.0...v2.164.0-alpha.0) (2024-10-24)


Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.164.1](https://github.com/aws/aws-cdk/compare/v2.164.0...v2.164.1) (2024-10-25)


### Bug Fixes

* enable node-fips compatible body checksums for S3 ([#31883](https://github.com/aws/aws-cdk/issues/31883)) ([290a499](https://github.com/aws/aws-cdk/commit/290a499f31413bd71eece4ad9f196eb5993747a9))

## [2.164.0](https://github.com/aws/aws-cdk/compare/v2.163.1...v2.164.0) (2024-10-24)


Expand Down
14 changes: 13 additions & 1 deletion packages/@aws-cdk-testing/cli-integ/lib/with-cdk-app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
import * as assert from 'assert';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
Expand Down Expand Up @@ -544,6 +545,17 @@ export class TestFixture extends ShellHelper {
return JSON.parse(fs.readFileSync(templatePath, { encoding: 'utf-8' }).toString());
}

public async bootstrapRepoName(): Promise<string> {
await ensureBootstrapped(this);

const response = await this.aws.cloudFormation.send(new DescribeStacksCommand({}));

const stack = (response.Stacks ?? [])
.filter((s) => s.StackName && s.StackName == this.bootstrapStackName);
assert(stack.length == 1);
return outputFromStack('ImageRepositoryName', stack[0]) ?? '';
}

public get bootstrapStackName() {
return this.fullStackName('bootstrap-stack');
}
Expand All @@ -569,7 +581,7 @@ export class TestFixture extends ShellHelper {
}

/**
* Cleanup leftover stacks and buckets
* Cleanup leftover stacks and bootstrapped resources
*/
public async dispose(success: boolean) {
const stacksToDelete = await this.deleteableStacks(this.stackNamePrefix);
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,19 @@ class DockerStack extends cdk.Stack {
}
}

class DockerInUseStack extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);

// Use the docker file in a lambda otherwise it will not be referenced in the template
const fn = new lambda.Function(this, 'my-function', {
code: lambda.Code.fromAssetImage(path.join(__dirname, 'docker')),
runtime: lambda.Runtime.FROM_IMAGE,
handler: lambda.Handler.FROM_IMAGE,
});
}
}

class DockerStackWithCustomFile extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);
Expand Down Expand Up @@ -814,6 +827,7 @@ switch (stackSet) {
new EcsHotswapStack(app, `${stackPrefix}-ecs-hotswap`);
new AppSyncHotswapStack(app, `${stackPrefix}-appsync-hotswap`);
new DockerStack(app, `${stackPrefix}-docker`);
new DockerInUseStack(app, `${stackPrefix}-docker-in-use`);
new DockerStackWithCustomFile(app, `${stackPrefix}-docker-with-custom-file`);

new NotificationArnPropStack(app, `${stackPrefix}-notification-arn-prop`, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { BatchGetImageCommand, ListImagesCommand, PutImageCommand } from '@aws-sdk/client-ecr';
import { GetObjectTaggingCommand, ListObjectsV2Command, PutObjectTaggingCommand } from '@aws-sdk/client-s3';
import { integTest, randomString, withoutBootstrap } from '../../lib';

const S3_ISOLATED_TAG = 'aws-cdk:isolated';
const ECR_ISOLATED_TAG = 'aws-cdk.isolated';

jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime

integTest(
'Garbage Collection deletes unused assets',
'Garbage Collection deletes unused s3 objects',
withoutBootstrap(async (fixture) => {
const toolkitStackName = fixture.bootstrapStackName;
const bootstrapBucketName = `aws-cdk-garbage-collect-integ-test-bckt-${randomString()}`;
Expand Down Expand Up @@ -50,7 +54,50 @@ integTest(
);

integTest(
'Garbage Collection keeps in use assets',
'Garbage Collection deletes unused ecr images',
withoutBootstrap(async (fixture) => {
const toolkitStackName = fixture.bootstrapStackName;

await fixture.cdkBootstrapModern({
toolkitStackName,
});

const repoName = await fixture.bootstrapRepoName();

await fixture.cdkDeploy('docker-in-use', {
options: [
'--context', `@aws-cdk/core:bootstrapQualifier=${fixture.qualifier}`,
'--toolkit-stack-name', toolkitStackName,
'--force',
],
});
fixture.log('Setup complete!');

await fixture.cdkDestroy('docker-in-use', {
options: [
'--context', `@aws-cdk/core:bootstrapQualifier=${fixture.qualifier}`,
'--toolkit-stack-name', toolkitStackName,
'--force',
],
});

await fixture.cdkGarbageCollect({
rollbackBufferDays: 0,
type: 'ecr',
bootstrapStackName: toolkitStackName,
});
fixture.log('Garbage collection complete!');

// assert that the bootstrap repository is empty
await fixture.aws.ecr.send(new ListImagesCommand({ repositoryName: repoName }))
.then((result) => {
expect(result.imageIds).toEqual([]);
});
}),
);

integTest(
'Garbage Collection keeps in use s3 objects',
withoutBootstrap(async (fixture) => {
const toolkitStackName = fixture.bootstrapStackName;
const bootstrapBucketName = `aws-cdk-garbage-collect-integ-test-bckt-${randomString()}`;
Expand Down Expand Up @@ -97,7 +144,50 @@ integTest(
);

integTest(
'Garbage Collection tags unused assets',
'Garbage Collection keeps in use ecr images',
withoutBootstrap(async (fixture) => {
const toolkitStackName = fixture.bootstrapStackName;

await fixture.cdkBootstrapModern({
toolkitStackName,
});

const repoName = await fixture.bootstrapRepoName();

await fixture.cdkDeploy('docker-in-use', {
options: [
'--context', `@aws-cdk/core:bootstrapQualifier=${fixture.qualifier}`,
'--toolkit-stack-name', toolkitStackName,
'--force',
],
});
fixture.log('Setup complete!');

await fixture.cdkGarbageCollect({
rollbackBufferDays: 0,
type: 'ecr',
bootstrapStackName: toolkitStackName,
});
fixture.log('Garbage collection complete!');

// assert that the bootstrap repository is empty
await fixture.aws.ecr.send(new ListImagesCommand({ repositoryName: repoName }))
.then((result) => {
expect(result.imageIds).toHaveLength(1);
});

await fixture.cdkDestroy('docker-in-use', {
options: [
'--context', `@aws-cdk/core:bootstrapQualifier=${fixture.qualifier}`,
'--toolkit-stack-name', toolkitStackName,
'--force',
],
});
}),
);

integTest(
'Garbage Collection tags unused s3 objects',
withoutBootstrap(async (fixture) => {
const toolkitStackName = fixture.bootstrapStackName;
const bootstrapBucketName = `aws-cdk-garbage-collect-integ-test-bckt-${randomString()}`;
Expand Down Expand Up @@ -142,11 +232,62 @@ integTest(
const tags = await fixture.aws.s3.send(new GetObjectTaggingCommand({ Bucket: bootstrapBucketName, Key: key }));
expect(tags.TagSet).toHaveLength(1);
});

await fixture.cdkDestroy('lambda', {
options: [
'--context', `bootstrapBucket=${bootstrapBucketName}`,
'--context', `@aws-cdk/core:bootstrapQualifier=${fixture.qualifier}`,
'--toolkit-stack-name', toolkitStackName,
'--force',
],
});
}),
);

integTest(
'Garbage Collection tags unused ecr images',
withoutBootstrap(async (fixture) => {
const toolkitStackName = fixture.bootstrapStackName;

await fixture.cdkBootstrapModern({
toolkitStackName,
});

const repoName = await fixture.bootstrapRepoName();

await fixture.cdkDeploy('docker-in-use', {
options: [
'--context', `@aws-cdk/core:bootstrapQualifier=${fixture.qualifier}`,
'--toolkit-stack-name', toolkitStackName,
'--force',
],
});
fixture.log('Setup complete!');

await fixture.cdkDestroy('docker-in-use', {
options: [
'--context', `@aws-cdk/core:bootstrapQualifier=${fixture.qualifier}`,
'--toolkit-stack-name', toolkitStackName,
'--force',
],
});

await fixture.cdkGarbageCollect({
rollbackBufferDays: 100, // this will ensure that we do not delete assets immediately (and just tag them)
type: 'ecr',
bootstrapStackName: toolkitStackName,
});
fixture.log('Garbage collection complete!');

await fixture.aws.ecr.send(new ListImagesCommand({ repositoryName: repoName }))
.then((result) => {
expect(result.imageIds).toHaveLength(2); // the second tag comes in as a second 'id'
});
}),
);

integTest(
'Garbage Collection untags in-use assets',
'Garbage Collection untags in-use s3 objects',
withoutBootstrap(async (fixture) => {
const toolkitStackName = fixture.bootstrapStackName;
const bootstrapBucketName = `aws-cdk-garbage-collect-integ-test-bckt-${randomString()}`;
Expand Down Expand Up @@ -175,7 +316,7 @@ integTest(
Key: key,
Tagging: {
TagSet: [{
Key: 'aws-cdk:isolated',
Key: S3_ISOLATED_TAG,
Value: '12345',
}, {
Key: 'bogus',
Expand All @@ -200,3 +341,52 @@ integTest(
}]);
}),
);

integTest(
'Garbage Collection untags in-use ecr images',
withoutBootstrap(async (fixture) => {
const toolkitStackName = fixture.bootstrapStackName;

await fixture.cdkBootstrapModern({
toolkitStackName,
});

const repoName = await fixture.bootstrapRepoName();

await fixture.cdkDeploy('docker-in-use', {
options: [
'--context', `@aws-cdk/core:bootstrapQualifier=${fixture.qualifier}`,
'--toolkit-stack-name', toolkitStackName,
'--force',
],
});
fixture.log('Setup complete!');

// Artificially add tagging to the asset in the bootstrap bucket
const imageIds = await fixture.aws.ecr.send(new ListImagesCommand({ repositoryName: repoName }));
const digest = imageIds.imageIds![0].imageDigest;
const imageManifests = await fixture.aws.ecr.send(new BatchGetImageCommand({ repositoryName: repoName, imageIds: [{ imageDigest: digest }] }));
const manifest = imageManifests.images![0].imageManifest;
await fixture.aws.ecr.send(new PutImageCommand({ repositoryName: repoName, imageManifest: manifest, imageDigest: digest, imageTag: `0-${ECR_ISOLATED_TAG}-12345` }));

await fixture.cdkGarbageCollect({
rollbackBufferDays: 100, // this will ensure that we do not delete assets immediately (and just tag them)
type: 'ecr',
bootstrapStackName: toolkitStackName,
});
fixture.log('Garbage collection complete!');

await fixture.aws.ecr.send(new ListImagesCommand({ repositoryName: repoName }))
.then((result) => {
expect(result.imageIds).toHaveLength(1); // the second tag has been removed
});

await fixture.cdkDestroy('docker-in-use', {
options: [
'--context', `@aws-cdk/core:bootstrapQualifier=${fixture.qualifier}`,
'--toolkit-stack-name', toolkitStackName,
'--force',
],
});
}),
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
certifi==2024.7.4
chardet==3.0.4
idna==3.7
urllib3==1.26.18
urllib3==1.26.19
# Requests used by this lambda
Loading

0 comments on commit 6cf830d

Please sign in to comment.