GithubHelp home page GithubHelp logo

khalilgharbaoui / gitlab-registry-cleaner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thecodingmachine/gitlab-registry-cleaner

0.0 1.0 0.0 3 KB

A simple Docker image to be used in Gitlab CI to easily delete images in the Gitlab registry

Shell 100.00%

gitlab-registry-cleaner's Introduction

Gitlab registry cleaner

Out of the box, there is no easy way to delete a special tag of a given image in the Gitlab registry (as of version 10.8).

This image provides a simple script that enables you to delete images easily.

Why?

If you want to do continuous deployment, it is not uncommon to build one image per pipeline in Gitlab. You will typically tag all your images using the commit SHA or the branch name. You will soon end up having a lot of images in your Gitlab registry. Docker images are big, and disk-space is finite so at some point, you will need to have a mechanism to automatically delete an image when it is no more needed.

As it turns out, deleting an image is surprisingly difficult, due to a number of outstanding issues:

This image is here to help.

Usage

You will typically use this image in your .gitlab-ci.yml file.

.gitlab-ci.yml

delete_image:
  stage: cleanup
  image: thecodingmachine/gitlab-registry-cleaner:latest
  script:
    - /delete_image.sh registry.gitlab.mycompany.com/path/to/image:$CI_COMMIT_REF_NAME
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop
  only:
  - branches
  except:
  - master

The /delete_image.sh script takes one single argument: the full path to the image to be deleted (including the tag).

Important: for the script to work, you must add a "Secret variable" in Gitlab CI named CI_ACCOUNT. This variable must be in the form [user]:[password] where [user] is a Gitlab user that has access to the registry and [password] is the Gitlab password of the user. This can be regarded obviously as a security issue if you don't trust all developers who have access to the CI environment (as they will be able to "echo" this secret variable).

This is needed because the default Gitlab registry token available to the CI does not have the rights to delete an image by default. An issue is opened in Gitlab to fix this issue: #39490 - Allow to bulk delete docker images

Special thanks

All the hard work has been done by Alessandro Lai and Vincent Composieux.

I've only put your ideas in a Docker image.

Miscellaneous

This image also contains kubectl (the command line tool for Kubernetes) that can be useful to perform cleanup actions in a Kubernetes cluster.

gitlab-registry-cleaner's People

Contributors

moufmouf avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.