Skip to main content

A tool to remove stale images from AWS ECR repositories.

Project description

Image Cleanup for Amazon ECR

The script removes stale ECR images. Although ECR offers lifecycle policies that serve a similar task, the logic this script implements cannot be achieved by using them.

The intention is to protect the set of images, that meet the criteria :

  • comes from a specified period, counting from the oldest significant tag,
  • counts no less than N-images, counting from the oldest significant tag (if less than N comes from the specified period).

Significant tags are those that are somehow meaningful for the release process, ie. 'dev', 'rc', 'prod', 'stable' and so on.

As the production/stable images are usually older than their development counterparts, using the oldest tag date as an anchor to calculate the protected period, means protecting some set of images that directly precede the current production release.

Example

The diagram below explains how script works, assuming:

  • protected period = one year,
  • protected count = 13,
  • significant tags = dev, rc, prod,
  • ecr repositories limited to: hello_world, other_ecr_repo.

example

By default, it runs in dry mode. To print what images will be removed, run:

python3 main.py --config <config_file.yaml>

with config file content:

- name: Flush untagged images older than 7 days, leave no less than 7 images
  protected_period: 7
  protected_count: 7
  significant_tags: '*'
  protected_repositories:
    - some_ignored_repository
- name: Protect images are that created for a year since a last significant tag, leave no less than 13 images
  protected_period: 365
  protected_count: 13
  significant_tags:
    - dev
    - rc
    - prod
    - latest
  repositories:
    - hello_world

When no repository list is provided, the script will iterate through all of the ECR repositories that are accessible by the AWS account used. To skip some repositories use protected_repositories option.

To actually remove the images, run:

python3 main.py --config <config_file.yaml> --apply

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-ecr-cleanup-0.1.5.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_ecr_cleanup-0.1.5-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file aws-ecr-cleanup-0.1.5.tar.gz.

File metadata

  • Download URL: aws-ecr-cleanup-0.1.5.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for aws-ecr-cleanup-0.1.5.tar.gz
Algorithm Hash digest
SHA256 518ffde12988e5873b59d658da79693ddf3e9328c3587c81a2ce99e6f778794b
MD5 05f589899b1add1de6b7f405fcbeea6b
BLAKE2b-256 31f77fec1e93fb1b2138f0697f78fedd5ee63cc2da8515a337d75be111d96aa9

See more details on using hashes here.

File details

Details for the file aws_ecr_cleanup-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_ecr_cleanup-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fc3b3421634f1235f15253f134f7bee9c001790d4e831c6981e4a1882416d1f7
MD5 5586b1197c790766f92f588c23b64a0b
BLAKE2b-256 fca30afc9cb2c4ec95319ed08d2d670d42a9988fdb221c7b18e8f43985326516

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page