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
- Host: GitHub
- URL: https://github.com/mattevans/ecr-cleanse
- Owner: mattevans
- License: mit
- Created: 2016-12-18T23:43:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-25T02:12:37.000Z (over 6 years ago)
- Last Synced: 2024-06-20T09:17:27.530Z (about 2 years ago)
- Topics: aws, aws-ecr, aws-ecs, ecr, ecr-repositories, ecs, go, golang, golang-library
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ecr-cleanse
[](https://goreportcard.com/report/github.com/mattevans/ecr-cleanse)
[](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!