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

ECR repository/S3 Bucket of assets needs clean up #6692

Closed
2 tasks
DerkSchooltink opened this issue Mar 12, 2020 · 16 comments
Closed
2 tasks

ECR repository/S3 Bucket of assets needs clean up #6692

DerkSchooltink opened this issue Mar 12, 2020 · 16 comments
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-ecr Related to Amazon Elastic Container Registry effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1

Comments

@DerkSchooltink
Copy link
Contributor

DerkSchooltink commented Mar 12, 2020

Please +1 Garbage Collection RFC

Original title: (was Lifecycle support for DockerImageAssets)

It would be helpful to apply lifecycle rules for the ECR to which DockerImageAsset's are pushed to.

Use Case

Right now CDK automatically defines the repository and keeps all previous images stored in there. Because of rapid prototyping this causes a lot of images to build up. In order to save cost on storing these images and to declutter the interface from old unused images it would be neat to be able to define a lifecycle for these images.

Proposed Solution

Ideally it would be possible to define lifecycle rules for the DockerImageAsset itself, but exposing the Repository construct through DockerImageAsset#repository instead of the generic IRepository interface would also work:

import {DockerImageAsset} from "@aws-cdk/aws-ecr-assets";

const image = new DockerImageAsset(this, "Image", {
  directory: "path/to/dockerfile"
});

image.repository.addLifecycleRule({maxImageCount: 30})
  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@DerkSchooltink DerkSchooltink added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Mar 12, 2020
@SomayaB SomayaB added @aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-ecr Related to Amazon Elastic Container Registry labels Mar 12, 2020
@MrArnoldPalmer
Copy link
Contributor

@rix0rrr @eladb, how does this fit into the "single repository : n images" strategy? Can we add a method that lets you add lifecycle rules at the image level (by targetting specific tags based on the assets unique ID perhaps?) in addition to exposing at the repository level?

@MrArnoldPalmer MrArnoldPalmer added effort/medium Medium work item – several days of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Mar 14, 2020
@DerkSchooltink
Copy link
Contributor Author

@rix0rrr @eladb, how does this fit into the "single repository : n images" strategy? Can we add a method that lets you add lifecycle rules at the image level (by targetting specific tags based on the assets unique ID perhaps?) in addition to exposing at the repository level?

What about exposing a field on DockerImageAsset that allows for defining a repository yourself? That allows us to create an ECR separately (with the lifecycle rules) and would not mess with the single repository setup.

Example:

const repository = new Repository(this, 'Repository');
repository.addLifecycleRule({maxImageCount: 5});

const image = new DockerImageAsset(this, "Image", {
    directory: "path/to/dockerfile",
    repository: repository
});

@MartinLoeper
Copy link

What about exposing a field on DockerImageAsset that allows for defining a repository yourself? That allows us to create an ECR separately (with the lifecycle rules) and would not mess with the single repository setup.

That sounds reasonable. We want to change the "scanOnPush" property and add lifecycle rules to the repository. I do not see how this is currently configurable.

@luxaritas
Copy link
Contributor

luxaritas commented Jan 4, 2021

Concurred - would also like to enable scanOnPush in addition to the lifecycle policy - retention policy too even! (Edit: looks like scan on push is automatically enabled for the cdk repository)

@peterjuras
Copy link

Any update on this?

@eladb
Copy link
Contributor

eladb commented Aug 3, 2021

The current way image assets work in the CDK implies that a single ECR repository is used for all asset images. You can use cdk-ecr-deployment in order to deploy image assets to a specific ECR repository in your control.

As for garbage collecting images from the assets ECR repository, this is something we plan to add at some point as part of a broader garbage collection capability (applies to buckets as well).

Please +1 this RFC if you want to see this prioritized: aws/aws-cdk-rfcs#64

@eladb eladb changed the title Lifecycle support for DockerImageAssets ECR repository of assets needs clean up (was Lifecycle support for DockerImageAssets) Aug 3, 2021
@eladb eladb changed the title ECR repository of assets needs clean up (was Lifecycle support for DockerImageAssets) ECR repository of assets needs clean up Aug 3, 2021
@eladb eladb added p1 and removed p2 labels Aug 3, 2021
@eladb eladb removed their assignment Aug 10, 2021
@madeline-k madeline-k removed their assignment Aug 21, 2021
@zacyang
Copy link

zacyang commented Oct 20, 2021

At least could we have the ScanOnPush configuration exposed?

@blimmer
Copy link
Contributor

blimmer commented Nov 18, 2021

With the new dockerTagPrefix behavior (see https://github.com/aws/aws-cdk/pull/17028/files), you can kind of manually start to do this. For instance, you can tag your image with some recognizable prefix and then manually create a lifecycle rule. I agree that this should be built-in and "just work" per the RFC.

@jonathan-kosgei
Copy link

jonathan-kosgei commented Aug 24, 2022

@rix0rrr is there any workaround for this? Our AWS bill is up significantly due to ECR storage.

@blimmer
Copy link
Contributor

blimmer commented Aug 24, 2022

@jonathan-kosgei You might give https://github.com/jogold/cloudstructs/blob/master/src/toolkit-cleaner/README.md a try (see the linked RFC above for where I found this: aws/aws-cdk-rfcs#64 (comment)). That construct has worked well for me.

@peterwoodworth peterwoodworth changed the title ECR repository of assets needs clean up ECR repository/S3 Bucket of assets needs clean up Sep 7, 2022
@joao-moonward
Copy link

Hello everyone! This issue seems quiet. Any feedback?

@MrArnoldPalmer
Copy link
Contributor

No updates currently but there is a third party construct to help enable this for those that need something in the interim https://constructs.dev/packages/cloudstructs/v/0.6.18/api/ToolkitCleaner?lang=typescript

For tracking a built in solution aws/aws-cdk-rfcs#64 is the place to watch.

@arminnajafi
Copy link

I've been needing this feature too.

@evgenyka
Copy link
Contributor

Closing in favor of aws/aws-cdk-rfcs#64

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@peterjuras
Copy link

@evgenyka is the implementation planned on the roadmap and is there an ETA? Closing in favor of an RFC does not inspire a lot of confidence that this feature will be prioritised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-ecr Related to Amazon Elastic Container Registry effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

No branches or pull requests