Skip to content

Commit

Permalink
feat: log when image has not been pulled in 7 days and is only tag
Browse files Browse the repository at this point in the history
  • Loading branch information
knechtionscoding committed Apr 11, 2023
1 parent 3f42485 commit 511e71e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions charts/ecr-cleanup/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.3.1
version: 0.3.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.3.1"
appVersion: "0.3.2"
2 changes: 1 addition & 1 deletion charts/ecr-cleanup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Deploys a job that cleans up an ECR repo based on the following rules.
3. Has the container been tagged with the word `keep`
4. Is the container the only tag in the ECR repository

![Version: 0.3.1](https://img.shields.io/badge/Version-0.3.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.3.1](https://img.shields.io/badge/AppVersion-0.3.1-informational?style=flat-square)
![Version: 0.3.2](https://img.shields.io/badge/Version-0.3.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.3.2](https://img.shields.io/badge/AppVersion-0.3.2-informational?style=flat-square)

## Values

Expand Down
12 changes: 12 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ def get_ecr_images(
logger.info(
f"Image {repository['repository_uri']}@{imageDetails[0]['imageDigest']} is the only image in the repository skipping"
)
if "lastRecordedPullTime" in imageDetails:
last_pull_time = imageDetails["lastRecordedPullTime"]
localized_now_ts = UTC.localize(datetime.now() - timedelta(7))
if last_pull_time > localized_now_ts:
logger.debug("The last pulltime was more than 7 days ago")
logger.info(
f"Image {repository['repository_uri']}@{imageDetails[0]['imageDigest']} is the only image in the repository skipping and hasn't been pulled in 7 days, consider deleting"
)
else:
logger.info(
f"Image {repository['repository_uri']}@{imageDetails[0]['imageDigest']} is the only image in the repository skipping and hasn't been pulled in 7 days, consider deleting"
)
break
images = append_image(images, imageDetails, repository)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ecr-image-cleanup-job"
version = "0.2.1"
version = "0.3.2"
description = ""
authors = ["Hans Knecht <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 511e71e

Please sign in to comment.