Skip to content

Commit

Permalink
chore: Let AWS Image Builder and ECR deal with deleting old images fo…
Browse files Browse the repository at this point in the history
…r us (#476)

AWS Image Builder [recently introduced lifecycle rules](https://aws.amazon.com/about-aws/whats-new/2023/11/ec2-image-builder-lifecycle-management-deletion/) that can help us remove old images from EC2/ECR, and their descriptors on AWS Image Builder side.

CDK [added automatic deletion of images in repositories](aws/aws-cdk#24572) so they can be deleted in CloudFormation easily. We had a custom resource to delete images, but now we can just use `autoDeleteImages`.

We still have to clean-up AWS Image Builder image descriptors and AMIs with a custom resource. We do this so removing our construct won't leave anything behind.

Resolves #471

BREAKING CHANGE: CDK 2.110.0 and above is required
  • Loading branch information
kichik authored Nov 30, 2023
1 parent 994f474 commit 27447ea
Show file tree
Hide file tree
Showing 23 changed files with 1,448 additions and 1,679 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .projen/files.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 18 additions & 39 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
author: 'Amir Szekely',
authorAddress: 'amir@cloudsnorkel.com',
stability: Stability.EXPERIMENTAL,
cdkVersion: '2.77.0', // 2.21.1 for lambda url, 2.29.0 for Names.uniqueResourceName(), 2.50.0 for JsonPath.base64Encode, 2.77.0 for node 16
cdkVersion: '2.110.0', // 2.21.1 for lambda url, 2.29.0 for Names.uniqueResourceName(), 2.50.0 for JsonPath.base64Encode, 2.77.0 for node 16, 2.110.0 for ib lifecycle
defaultReleaseBranch: 'main',
name: '@cloudsnorkel/cdk-github-runners',
repositoryUrl: 'https://github.com/CloudSnorkel/cdk-github-runners.git',
Expand Down
10 changes: 4 additions & 6 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions src/image-builders/aws-image-builder/ami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,24 @@ interface AmiRecipeProperties {
export class AmiRecipe extends ImageBuilderObjectBase {
public readonly arn: string;
public readonly name: string;
public readonly version: string;

constructor(scope: Construct, id: string, props: AmiRecipeProperties) {
super(scope, id);

const name = uniqueImageBuilderName(this);

let components = props.components.map(component => {
return {
componentArn: component.arn,
};
});

this.name = uniqueImageBuilderName(this);
this.version = this.generateVersion('ImageRecipe', this.name, {
platform: props.platform,
components,
parentAmi: props.baseAmi,
});

let workingDirectory;
if (props.platform == 'Linux') {
workingDirectory = '/home/runner';
Expand All @@ -61,19 +67,14 @@ export class AmiRecipe extends ImageBuilderObjectBase {
}

const recipe = new imagebuilder.CfnImageRecipe(this, 'Recipe', {
name: name,
version: this.version('ImageRecipe', name, {
platform: props.platform,
components,
parentAmi: props.baseAmi,
}),
name: this.name,
version: this.version,
parentImage: props.baseAmi,
components,
workingDirectory,
});

this.arn = recipe.attrArn;
this.name = name;
}
}

Expand Down
Loading

0 comments on commit 27447ea

Please sign in to comment.