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

Repositories filter and env variables fix #28

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

talset
Copy link

@talset talset commented Oct 10, 2018

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

In order to "limitate" the clean, adding a filter on repositories name
to keep.
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
Previously environnement variable was defined but always overrided by
args:

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

and then affectied 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.
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
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
Copy link
Author

talset commented Oct 12, 2018

Fix the

# #17

@talset
Copy link
Author

talset commented Nov 1, 2018

PR conflict merge fixed regarding last commit c451cb6 merged by @anshrma

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

@kladiv
Copy link

kladiv commented Apr 17, 2019

+1 for this PR (filter by repository name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants