项目作者: agrrh

项目描述 :
Private Docker registry cleanup tool, supposed to be triggered by GitLab webhooks
高级语言: Python
项目地址: git://github.com/agrrh/docker-registry-cleanup.git
创建时间: 2019-10-20T13:07:45Z
项目社区:https://github.com/agrrh/docker-registry-cleanup

开源协议:

下载


Info

Private Docker registry cleanup tool.

Supposed to be triggered with GitLab webhook on push event.

Note that as for docker registry v2.4.x, this tools itself does not actually remove blobs, it just mark them as unused. Run garbage collection process to truly remove data from disk.

Usage

Running

  1. docker run -d --name docker-registry-cleanup \
  2. -p 80:5000 \
  3. agrrh/docker-registry-cleanup

Environment variables

  • DRC_CONFIG_PATH - config file to use, defaults to ./config.yml
  • DRC_LISTEN_HOST - address to bind to, defaults to 0.0.0.0
  • DRC_LISTEN_PORT - address to bind to, defaults to 5000
  • DRC_DEBUG - set to yes or true to run in debug mode

Testing

Using httpie:

  1. http POST :8080/event @./res/sample_payload/gitlab/push.json

Configuration

Tool is configured via config.yml:

<config>
  1. projects:
  2. - <project>
  3. - <project>
<project>
  1. - name: myproject
  2. gitlab:
  3. secret_token: '' # Use if specified in GitLab > Settings > Integrations
  4. registry:
  5. verify_ssl: false
  6. images:
  7. - repository: my/project
  8. rules:
  9. - <rule>
  10. - <rule>
  11. - <rule>

Recommended ruleset scheme is:

  1. rules:
  2. - action: remove
  3. - action: save
  4. regexp: '^.*$'
  5. order: created
  6. limit: 20
<rule>

First rule is default policy and must contain single action directive:

  1. - action: remove

If default rules is remove, it will never remove :latest tag if it exists.

Let’s say, we are pushing tags in branch_name.pipeline_id format. Then other rules would define saving actions to preserve sane amount of images, e.g. save 10 newest tags matching master.[0-9]+ regular expression:

  1. - action: save
  2. regexp: '^master\.[0-9]+$'
  3. order: created
  4. limit: 10

Also we would like to save some newest images across rest of tags. Consider 40 as reasonable amount and add following rule:

  1. - action: save
  2. regexp: '^(?!master).*$'
  3. order: created
  4. limit: 40

It’s also possible to add more remove rules. In case some images matches both remove and save rules, default action would take precedence.