Skip to content

imglife cleanup

imglife cleanup [flags]

Applies the retention policy to all images in build.images and their corresponding mirrors. Deletes (or archives) tags that exceed keep_last or max_age_days.

Flag Default Description
--dry-run false Simulate deletions without making any changes
--list false Print affected tags and exit
--force false Override the safety guard and clean up even when no applicative-referenced base images are found
Terminal window
# Preview: show what would be deleted
imglife cleanup --list
# Dry-run: simulate without deleting
imglife cleanup --dry-run
# Apply the retention policy
imglife cleanup

A tag is a deletion candidate if it satisfies either condition:

  1. Its position in the sorted tag list of its version line exceeds keep_last.
  2. Its creation timestamp is older than max_age_days days.

Tags listed in retention.exclude_tags are never deleted.

Ranking happens per version line, never across the whole repository: one line per sync entry targeting the repo (using its own keep_last, falling back to retention.keep_last) and one line per build.images block producing it. Three folder: jdk blocks pinned to JDK 8, 11 and 25 therefore each keep their own keep_last tags — the newer line no longer evicts the older ones. Tags of a mirror repository matching no line stay ranked together under retention.keep_last.

Registries delete a manifest by digest, which removes every tag pointing to it. Before deleting anything, cleanup resolves the digest of each tag in the repository:

  • A candidate that shares its digest with a kept tag (excluded, used by a project, within keep_last, too recent) is kept.
  • Candidates that share a digest with each other are archived one by one, then their manifest is deleted once. The summary counts each tag.

For example, python:3.12 (used by a project) and python:3.12.5 (outside keep_last, 90 days old) point to the same manifest. Deleting 3.12.5 would delete 3.12 too, so cleanup keeps both.

A base or mirror tag is also protected when a scanned project uses it (usage records published by imglife scan --register). To avoid mass deletion, when build.images are configured but usage records exist that yield no referenced image — or some records cannot be read — cleanup aborts instead of treating every image as unreferenced.

The guard does not engage when the package registry cleanly reports no usage record at all: that is a young setup whose project pipelines have not published anything yet, with nothing that could be mistaken for unreferenced. Cleanup then proceeds under the normal keep_last / max_age_days policies. A misconfigured or unreachable registry surfaces earlier as an explicit error rather than an empty list.

Pass --force to override the guard, for example once all usage records have genuinely been removed. The guard never engages for mirror-only setups (no build.images) or in --dry-run/--list mode.

When retention.archive.enabled: true, tags are copied to retention.archive.registry before deletion. This creates a safety net for accidentally deleted images.

After retention.archive.keep_days days, the archived copy is deleted on the next cleanup run.

imglife reports images that exist in the OCI registry but are no longer declared in build.images. These “type-orphan” images appear in the --list output with a warning but are not automatically deleted. Remove them manually after verification.

retention:
keep_last: 5
max_age_days: 90
exclude_tags: [latest, stable]
archive:
enabled: true
registry: registry.example.com/archive
keep_days: 180

See retention configuration for the full reference.

After each run (not in --list mode), imglife prints a summary to stdout:

Cleanup Summary · 3.8s
───────────────────────────────────
Tags examined 24
├─ Deleted 5
├─ Archived 2
├─ Kept 17
└─ Errors 0

In --dry-run mode the header is prefixed with [dry-run]. Set NO_COLOR=1 or TERM=dumb to disable ANSI colors.

Code Meaning
0 Cleanup completed (including partial deletions)
1 Fatal error preventing cleanup