Skip to content

Commit

Permalink
Delete images older than 1 year
Browse files Browse the repository at this point in the history
  • Loading branch information
amezin committed Dec 26, 2023
1 parent 11fe021 commit 49e3d49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ For every repository:

1. Images created less than 1 day ago are kept

2. Images with no defined build date (cache?) are kept
2. Images created more than 1 year ago are deleted

3. Images with `org.opencontainers.image.version` label matching existing
3. Images with no defined build date (cache?) are kept

4. Images with `org.opencontainers.image.version` label matching existing
tags/branches or open pull requests are kept

4. Everything else is deleted
5. Everything else is deleted

## REST API pagination race condition

Expand Down
8 changes: 8 additions & 0 deletions cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ async function main() {
const minAge = new Date();
minAge.setDate(minAge.getDate() - 1);

const maxAge = new Date();
maxAge.setFullYear(minAge.getFullYear() - 1);

const shouldDelete = async (version, config) => {
const created = Date.parse(config?.created);
if (isNaN(created)) {
Expand All @@ -322,6 +325,11 @@ async function main() {
return false;
}

if (created < maxAge) {
octokit.log.info(`Image ${version.displayImage} is too old`, created);
return true;
}

const labels = config?.config?.Labels;
const refName = labels ? labels['org.opencontainers.image.version'] : null;
octokit.log.debug(`Version of ${version.displayImage}: ${refName}`);
Expand Down

0 comments on commit 49e3d49

Please sign in to comment.