An open API service indexing awesome lists of open source software.

https://github.com/mattevans/ecr-cleanse

🛁 A golang implementation for removing old images from ECR repositories
https://github.com/mattevans/ecr-cleanse

aws aws-ecr aws-ecs ecr ecr-repositories ecs go golang golang-library

Last synced: 6 months ago
JSON representation

🛁 A golang implementation for removing old images from ECR repositories

Awesome Lists containing this project

README

          

# ecr-cleanse

[![Go Report Card](https://goreportcard.com/badge/github.com/mattevans/ecr-cleanse)](https://goreportcard.com/report/github.com/mattevans/ecr-cleanse)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/mattevans/ecr-cleanse/blob/master/LICENSE)

The [documented limit](http://docs.aws.amazon.com/AmazonECR/latest/userguide/service_limits.html) to the number of images in an ECR repository is ~1000~ ([Now 10K as of Jul 19 2019](https://aws.amazon.com/about-aws/whats-new/2019/07/amazon-ecr-now-supports-increased-repository-and-image-limits/)). This is a golang implementation for removing unused images from your ECR repositories.

This script will inspect all container services/tasks, across all ECS clusters, removing images that are not in-use (in [batches](http://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_BatchDeleteImage.html) of 100).

Usage
-----------------

```go
go run main.go
```

Flags
-----------------

- `-aws-region`: Pass your AWS region.
- `-dry-run`: Execute the script without purging any images.

```go
go run main.go -aws-region us-west-2 -dry-run
```

Example Output
-----------------

```
INFO[0005] Dry Run: true
INFO[0005] AWS Region: us-west-2
INFO[0005] Repositories Found: 3
INFO[0005] Active Images Found: 8
INFO[0005] ----------------------------------------------------------------
INFO[0005] Repository: my.production.repository
INFO[0005] [DRY RUN] `2` images would be purged
INFO[0005] ----------------------------------------------------------------
INFO[0005] Repository: my.staging.repository
INFO[0005] [DRY RUN] `2` images would be purged
INFO[0005] ----------------------------------------------------------------
INFO[0006] Repository: my.test.repository
INFO[0006] [DRY RUN] `1` images would be purged
INFO[0006] ----------------------------------------------------------------
```

Contributing
-----------------
If you've found a bug or would like to contribute, please create an issue here on GitHub, or better yet fork the project and submit a pull request!