Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
atdima committed Nov 12, 2021
1 parent 2dcba29 commit 66bd2e5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ agent:
type: e1-standard-2
os_image: ubuntu2004
blocks:
- name: Linting
task:
jobs:
- name: Golangci-lint
commands:
- golangci-lint run -c ./golangci.yaml
prologue:
commands:
- sem-version go 1.17
- checkout
- 'cache restore vendor-$SEMAPHORE_GIT_BRANCH-$(checksum go.mod),vendor-$SEMAPHORE_GIT_BRANCH,vendor-master'
- 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.17.3'
epilogue:
always:
commands:
- cache save
- name: Build
task:
jobs:
Expand Down
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
# Gitlab container registry cleaner
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/traefik/traefik/blob/master/LICENSE.md)

## About deploy
Gitlab container registry cleaner
---

https://semaphoreci.com/community/tutorials/how-to-deploy-a-go-web-application-with-docker
## Features
Periodic removes old images from GitLab container registry in all projects.

## Run linter
## Environment variables
- PRODUCTION=false ( configure log format )
- THRESHOLD=3 ( images over threshold will be deleted automatically )
- BASE_API_URL=https://gitlab.com/api/v4 ( gitlab api endpoint )
- ACCESS_TOKEN=XXX ( gitlab access token, see https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token )
- CRON_TIME=01:11 ( time of day to run clean )

## Configuration file
```
cp ./.env.example ./.env
```

## Run clean command in docker
```
docker run \
--name gitlab-registry-cleaner \
--env-file=./.env \
--env COMMAND_NAME=clean \
ataklychev/gitlab-registry-cleaner
```

## Run cron command in docker
```
make lint
docker run \
--name gitlab-registry-cleaner \
--env-file=./.env \
--env COMMAND_NAME=cron \
ataklychev/gitlab-registry-cleaner
```
4 changes: 4 additions & 0 deletions service/garbage_collection_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func NewGarbageCollectionService(
gitlabRepo repository.GitlabRepositoryInterface,
logger logger.Logger,
) GarbageCollectionServiceInterface {
// minimal number of saved images
if threshold < 1 {
threshold = 1
}
return &GarbageCollectionService{
threshold: threshold,
gitlabRepo: gitlabRepo,
Expand Down

0 comments on commit 66bd2e5

Please sign in to comment.