Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Listens for incoming requests and deletes docker images if merge request is merged

License

Notifications You must be signed in to change notification settings

glensc/gitlab-registry-cleanup-hook

Repository files navigation

Gitlab Registry Cleanup Hook

Listens for incoming requests and deletes docker images if merge request is merged.

Archived: This project is no longer maintained

You can use this project as an alternative:

Install

cp env.example .env
docker-compose up -d

Create system hook from /admin/hooks

  • URL: http://this-service:8000/
  • Secret Token: same as $HOOK_TOKEN from the .env
  • Trigger: Merge request events

Customize images to delete

By default IMAGE_NAME_TEMPLATE=%(project_path)s/branches:%(branch)s is used to find images to delete.

It's a comma separated list of images to delete.

You can override this per project, by setting project custom attribute.

# Project custom attribute name to set per project override for IMAGE_NAME_TEMPLATE
# https://docs.gitlab.com/ce/api/custom_attributes.html
IMAGE_NAME_PROJECT_ATTRIBUTE=gitlab_registry_image_template

This will configure to cleanup branches:BRANCH_NAME-node-8 and branch:BRANCH_NAME-node-10 images when MR is merged:

./set-project-attribute.sh gitlab-org/gitlab-ce '%(project_path)s/branches:%(branch)s-node-8,%(project_path)s/branches:%(branch)s-node-10'
{"key":"custom_attribute","value":"%(project_path)s/branches:%(branch)s-node-8,%(project_path)s/branches:%(branch)s-node-10"}

Invoking helper script without value, will delete the attribute:

./set-project-attribute.sh gitlab-org/gitlab-ce

Credits

About

Listens for incoming requests and deletes docker images if merge request is merged

Resources

License

Stars

Watchers

Forks

Packages

No packages published