Skip to main content

GitHub Workflow Status Code style: black PyPI PyPI - Python Version License: BSD 3-Clause

Google Container Registry Cleanup utility

If you use a CI system to push images to Google Container Registry you will eventually run into a situation where you're paying more than you would like for the storage there.

This tool helps you keep those costs reasonable, while allowing you to benefit from caches, keeping backups for rollbacks, etc.

Prerequisites and setup

  • Python 3.9+
  • Gcloud SDK with an authentication token that has admin access to the registry properly configured
pip install -U gcrc

Usage

Replace gcr.io/project-name with the specific GCR address to your repository, e.g. if your Google Cloud project is called foo-bar and it's in the EU zone this would likely be eu.gcr.io/foo-bar.

List all images

Figures out the different images we can access in the Container Registry.

gcrc list-images gcr.io/project-name

Show information on images

Analyzes current images and any need for cleanup based on current configuration without actually deleting anything. Use to check that configuration seems correct.

gcrc image-info gcr.io/project-name

Clean up images

Look up images with unneeded tags and delete them from Google Container Registry

gcrc cleanup gcr.io/project-name

Configuration

The following environment variables can be used to adjust the configuration:

KEEP_TAGS_MIN=10

Keeps at least this many tags for every image.

KEEP_TAGS_DAYS=14

Keep everything from within this many days.

KEEP_EXTRA='["^latest$", "^(master|main)-"]'

List of regex matches for important images that we want to keep an extra KEEP_TAGS_MIN items of. Formatted as a JSON list of strings.

The default is to keep latest and any tags starting with master- or main- for people who tag their images like <branch>-<timestamp or commit hash or uuid>.

You can also put these in a .env -file, but environment variables take priority over .env.

# .env
KEEP_TAGS_MIN=10
KEEP_TAGS_DAYS=14
KEEP_EXTRA='["^important-", "^latest$"]'

Financial support

This project has been made possible thanks to Cocreators and Lietu. You can help us continue our open source work by supporting us on Buy me a coffee.

"Buy Me A Coffee"

Metadata

Release files for gcrc 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gcrc 1.0.6
File Size Uploaded
gcrc-1.0.6.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gcrc 1.0.6
File Interpreter ABI Platform
gcrc-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 13.7 kB

Release files / gcrc-1.0.6.tar.gz

Download URL gcrc-1.0.6.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d4f2566049dd270c3f4548e9febc7c93549e616b086fb36786269d7c81bbc1e2
BLAKE2b-256 checksum
How to use checksums
a4fef28326a75bce826d6e9b5f7fd4161874c37f326480890196999b3b657d09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.9.7 Linux/5.8.0-1041-azure

Release files / gcrc-1.0.6-py3-none-any.whl

Download URL gcrc-1.0.6-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
021b435c0dfae0887b2a29c68a93fde74e15679f366781cf78b82b4e150a19f1
BLAKE2b-256 checksum
How to use checksums
725f724b7d990eefea7ef2855f98a2594c807866688e6769de9b218ecf337484
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.9.7 Linux/5.8.0-1041-azure

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page