Skip to content
/ gcrgc Public
forked from graillus/gcrgc

Command-line tool for easily cleaning Google Container Registry repositories

License

Notifications You must be signed in to change notification settings

vizlegal/gcrgc

 
 

Repository files navigation

gcrgc

Build Status codecov.io Go Report Card GoDoc License MIT

The GCR Garbage Collector

Tool for cleaning up images on the Google Container Registry. Initially based on the gist by Ahmet Alp Balkan, and rewritten in Go.

Features

  • Remove images older than the date specified with option -date
  • Keep images within a given retention period -retention-period
  • Clean up multiple image repositories at once with option -all
  • Exclude some image repositories with option -exclude-repository
  • Exclude images with certain tag(s) from deletion with option -exclude-tag
  • Exclude images with tags matching a regexp pattern with option -exclude-tag-pattern
  • Exclude images with tags matching a SemVer pattern with option -exclude-semver-tags

    Note: The SemVer standard does not include the v or V prefix (e.g. v1.0.0), but as it is widely used, our Regexp will also match tags beginning with either v or V, so they will be excluded from deletion as well.

  • Only remove untagged images with -untagged-only flag
  • Dry-run mode with option -dry-run (don't actually delete images but get same output)

Prerequisites

You need an authenticated local gcloud installation, and write access to a Google Container Registry.

You can use a service account as well by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable. Read the Google documentation for more details.

Installation

Binary releases

  1. Download your desired version
  2. Extract it
tar xvf gcrgc_0.3.2_linux_amd64.tar.gz
  1. Move binary to desired destination
mv gcrgc /usr/local/bin

From sources

go get github.com/graillus/gcrgc
cd $GOPATH/src/github.com/graillus/gcrgc
go build -o bin/gcrgc cmd/gcrgc/gcrgc.go

Using docker

A public image repository is available on DockerHub

docker pull graillus/gcrgc

Run with Google service account credentials:

docker run -t --rm \
  -v /path/to/serviceaccount.json:/credentials \
  -e GOOGLE_APPLICATION_CREDENTIALS=/credentials/serviceaccount.json
  graillus/gcrgc ...

Usage

Clean up untagged images under the gcr.io/project-id/my-image repository.

gcrgc -registry=gcr.io/project-id -untagged-only my-image

Clean up tagged and untagged images under the gcr.io/project-id/my-image repository older than 2019-01-01, excluding tags master and latest

gcrgc -registry=gcr.io/project-id -date=2019-01-01 -exclude-tag=latest -exclude-tag=master my-image

Clean up images older than 30 days

gcrgc -registry=gcr.io/project-id -retention-period 30d

Clean up tagged and untagged images under the gcr.io/project-id/my-image excluding SemVer tags and latest

gcrgc -registry=gcr.io/project-id -exclude-tag=latest -exclude-semver-tags my-image

Clean up tagged and untagged images under the entire registry gcr.io/project-id older than 2019-01-01, excluding the images under gcr.io/project-id/my-image

gcrgc -registry=gcr.io/project-id -all -date=2019-01-01 -exclude-repository=my-image

Helm chart

A Helm chart is available if you wish to run it on a Kubernetes cluster (as a CronJob).

Check the documentation

About

Command-line tool for easily cleaning Google Container Registry repositories

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.1%
  • Dockerfile 0.9%