[PR #2302] [MERGED] Implement a cleanup of old Docker images and untagged images #9481

Closed
opened 2026-02-05 14:05:33 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/immich-app/immich/pull/2302
Author: @stumpylog
Created: 4/20/2023
Status: Merged
Merged: 4/26/2023
Merged by: @alextran1502

Base: mainHead: main


📝 Commits (1)

  • 7be49f2 chore(ci): Implement a cleanup of Docker images

📊 Changes

1 file changed (+77 additions, -0 deletions)

View changed files

.github/workflows/docker-cleanup.yml (+77 -0)

📄 Description

This PR adds a new workflow which will runs when a PR closes to remove the associated Docker image which was built from the PR and images which are untagged. In an ideal world, this would be something built into github, but until that day... This helps keep the packages with tags down to just the released versions and those PRs which are still in some sort of active state.

Stale Images

I've tested this with a read PAT in a sample repository here: https://github.com/stumpylog/immich-sample-repo/actions/runs/4791378901

Taking immich-server as the example, the list of images which would be removed.

The logic is pretty simple (and encapsulated into an action). It filters to packages with 1 tag (extra security), with match the regex ^pr-(\d+)$|^(\d+)$. The capturing groups are used to get a PR number. If the PR is closed (which also means merged), the package is considered done with and can be removed

Untagged Images

Requires a little more knowledge of Docker and registries to understand, but not terrible.

Basically, when a tag is updated to point to a newly built image (say the PR or branch was updated), the old image doesn't get removed. In fact, it could still be accessed via a tag of the form @sha256:<digest>. But most people are using :main or :pr-1234, not a SHA.

So the action looks for images with no tags applied and not pointed to by a multi-arch manifest and removes those.

TBD

  • The repository would need a PAT with the OAuth scope of package deletion in the secrets
  • The action requires the delete option to be set to actually delete anything. For now, it's more like a dry run

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/immich-app/immich/pull/2302 **Author:** [@stumpylog](https://github.com/stumpylog) **Created:** 4/20/2023 **Status:** ✅ Merged **Merged:** 4/26/2023 **Merged by:** [@alextran1502](https://github.com/alextran1502) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (1) - [`7be49f2`](https://github.com/immich-app/immich/commit/7be49f255ce9be341ccfebbb9df32f660a3f0d17) chore(ci): Implement a cleanup of Docker images ### 📊 Changes **1 file changed** (+77 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `.github/workflows/docker-cleanup.yml` (+77 -0) </details> ### 📄 Description This PR adds a new workflow which will runs when a PR closes to remove the associated Docker image which was built from the PR and images which are untagged. In an ideal world, this would be something built into github, but until that day... This helps keep the [packages with tags](https://github.com/immich-app/immich/pkgs/container/immich-server/versions?filters%5Bversion_type%5D=tagged) down to just the released versions and those PRs which are still in some sort of active state. ## Stale Images I've tested this with a read PAT in a sample repository here: https://github.com/stumpylog/immich-sample-repo/actions/runs/4791378901 Taking `immich-server` as the example, [the list of images which would be removed](https://github.com/stumpylog/immich-sample-repo/actions/runs/4791378901/jobs/8525616166#step:2:129). The logic is pretty simple (and encapsulated into an action). It filters to packages with 1 tag (extra security), with match the regex `^pr-(\d+)$|^(\d+)$`. The capturing groups are used to get a PR number. If the PR is closed (which also means merged), the package is considered done with and can be removed ## Untagged Images Requires a little more knowledge of Docker and registries to understand, but not terrible. Basically, when a tag is updated to point to a newly built image (say the PR or branch was updated), the old image doesn't get removed. In fact, it could still be accessed via a tag of the form `@sha256:<digest>`. But most people are using `:main` or `:pr-1234`, not a SHA. So the action looks for images with no tags applied and not pointed to by a multi-arch manifest and removes those. ## TBD - The repository would need a PAT with the OAuth scope of package deletion in the secrets - The action requires the `delete` option to be set to actually delete anything. For now, it's more like a dry run --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 14:05:33 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#9481