Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maksim-paskal/gitlab-registry-cleaner
Tool to clean docker registry in Gitlab
https://github.com/maksim-paskal/gitlab-registry-cleaner
containers devops docker-registry gitlab
Last synced: 3 days ago
JSON representation
Tool to clean docker registry in Gitlab
- Host: GitHub
- URL: https://github.com/maksim-paskal/gitlab-registry-cleaner
- Owner: maksim-paskal
- License: apache-2.0
- Created: 2022-03-20T10:30:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-06T10:02:42.000Z (about 1 year ago)
- Last Synced: 2024-05-19T00:37:17.233Z (8 months ago)
- Topics: containers, devops, docker-registry, gitlab
- Language: Go
- Homepage:
- Size: 185 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gitlab Docker Registry Cleaner
## Motivation
With DevOps practices, docker registry growing fast with developing new features. Need some tool to purge stale docker registry tags in docker repository.
## Installation
create custom [values.yaml](charts/gitlab-registry-cleaner/values.yaml) for example
```yaml
env:
- name: GITLAB_TOKEN
value: sometoken
- name: GITLAB_URL
value: https://git.lab/api/v4
- name: REGISTRY_URL
value: "https://someregistry.azurecr.io"
- name: REGISTRY_USERNAME
value: "someuser"
- name: REGISTRY_PASSWORD
value: "sometoken"
# optional
- name: SENTRY_DSN
value: "https://id@sentry/0"args:
- -metrics.pushgateway=http://prometheus-pushgateway.prometheus.svc.cluster.local:9091tolerations:
- key: "kubernetes.azure.com/scalesetpriority"
operator: "Equal"
value: "spot"
effect: "NoSchedule"
``````bash
helm repo add maksim-paskal-gitlab-registry-cleaner https://maksim-paskal.github.io/gitlab-registry-cleaner
helm repo updatehelm upgrade gitlab-registry-cleaner \
--install \
--create-namespace \
--namespace gitlab-registry-cleaner \
maksim-paskal-gitlab-registry-cleaner/gitlab-registry-cleaner \
--values values.yaml
```## Requirements
All docker registry artifacts must contains the path of Gitlab project and sluglify tag of git branch or git tag
In Gitlab CI/CD is very simple to make it with
```yaml
build:
image: docker:dind
script: |
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRYexport BUILD_STAGE_NAME=someimagename
export BUILD_IMAGE_NAME=$CI_REGISTRY/$CI_PROJECT_PATH/$BUILD_STAGE_NAME:$CI_COMMIT_REF_SLUGdocker build --pull -t $BUILD_IMAGE_NAME .
docker push $BUILD_IMAGE_NAME
```All git tags that use in stage/prod envieroment must be named with `release-YYYMMDD` where `YYYYMMDD` is release date
## Clearing docker registry tags
Clearing docker tags will be peformed with this logic
### 1. If docker registry have this release tags
```bash
release-20220320
release-20220319
release-20220319-patch1
release-20220319-patch2
release-20220318-test
release-20220311
release-20220310 # will be removed
release-20220301 # will be removed
release-20220221 # will be removed
````gitlab-registry-cleaner` will leave only last 10 day of release tags
### 2. If docker registry tag exists and there if no git tag (branch was merged to main branch) - docker tag will be removed
## Clearing docker snapshots tags
in registry can be stored database snapshots, so we need to remove old snapshots also
default path in registry `devops/docker/mysql-.+` for snapshots
```bash
20210316-snap # will be removed
20210421-snap # will be removed
20210504-snap # will be removed
20211117-snap # will be removed
20220331-snap # will be removed
20220415-snap # will be removed
20220606-snap
20220615-snap
20220809-snap
```