awslabs / ecr-cleanup-lambda

A script to discover stale ECR images and take action on them with Lambda to help reduce costs.
Other
161 stars 96 forks source link

Repositories filter and env variables fix #28

Open talset opened 6 years ago

talset commented 6 years ago

main.py: filter on repositories

In order to "limitate" the clean, adding a filter on repositories name
to keep.

It use a list to match repositories name. If the repository is in the list, the repository is used for the clean else it is skipped.

main.py: fix multiple tags deleting issue

When using the -ignoretagsregex, if we had an image with multiple tags
the image is deleted if all tags not match the ignoretagsregex

For example image tag: dev foo bar

-ignoretagsregex dev

the image will be added to the deletesha list.

The fix ensure that if one of the images's tags match the
ignoretagsregex, the image is skiped

main.py: add python shebang

In order to be able to chmod +x main.py and use it directly with ./main.py

main.py: arg to use os.environ

Previously environnement variable was defined but always overrided by
args:

  os.environ["DRYRUN"] = args.dryrun.lower()

and then affected to the global var:

  DRYRUN = os.environ.get('DRYRUN', "false").lower()

In this case the real env variables wasn't use.

This fix allow parser to get by default the env var and them a default
value. Global var are now using directly args. from parser.

main.py take care of ignored tag in the keep count

Previously the could keep was done on all tagged image but when using
IGNORE_TAGS_REGEX, the image ignored was taken in the keep count.

That means if we have 3 images

  * image1 tagfoo
  * image2 tagbar
  * image3 tag bla

and set keep 1 with ignoretags tagfoo it would have deleted image2 and
3.

Now keep is done on other image that are ignored. I the previous example
it will delete image3 only, ignore image1 (tagfoo) and  keep image2

main.py: Add filter to clean image with tag match

Inspired by https://github.com/awslabs/ecr-cleanup-lambda/pull/17/files

Add parameter to allow only deleting images where the tag contains a
specific string

Specify a regex to match tags. If no tags on the image match, the image
will be skipped/ignored.

Allow us to only clean a specifig type/tag of images
talset commented 6 years ago

Fix the

17

talset commented 5 years ago

PR conflict merge fixed regarding last commit https://github.com/awslabs/ecr-cleanup-lambda/commit/c451cb65daa07548966ade5eb6ac9ee851130373 merged by @anshrma

This commit is not needed in this PR because the confition changed regarding regex

kladiv commented 5 years ago

+1 for this PR (filter by repository name)