Skip to content

steffakasid/clinar

Repository files navigation

clinar - A tool to cleanup stale gitlab runners

License Apache%202.0 blue link:https://github.com/steffakasid/clinar/actions/workflows/codeql-analysis.yml link:https://github.com/steffakasid/clinar/actions/workflows/release.yml link:https://github.com/steffakasid/clinar/actions/workflows/go-test.yml coverage badge

This tool basically get’s all offline runners which a user can administer. If you don’t provide the --approve flag the tool just shows all runners which are offline with some additional information. After you provide the --approve flag all offline runners are deleted.

Installation

On OSX or Linux just use brew to install:

How to brew install
brew install steffakasid/clinar/clinar
# or
brew tap steffakasid/clinar
#and then
brew install clinar

Checkout brew help, man brew

Flags and Config Options

Usage
clinar [flags]
Environment Variables
GITLAB_HOST

set the GitLab host to be able to run against self hosted GitLab instances [Default: https://gitlab.com]

GITLAB_TOKEN

GitLab token to access the GitLab API. To view runners read_api should be sufficient. To cleanup stale runners you must have full API access.

Flags
--approve, -a

Boolean flag to toggle approve. If you provide this flag stale runners are deleted.

--exclude, -e

String[] flag (can be provided multiple times). Define projects/ groups based on their names or ids which are excluded. This flag takes precedences before include. If one group/ project is excluded the full runner is excluded from the cleanup list.

--include, -i

String flag to define a regular expressions for projects/ groups which should be included. If one group/ project is included the runner is included into the cleanup list.

Using sops encrypted config file

You can now provide a sops encrypted config file. To create one you need any supported encryption key e.g. gpg and encrypt your file like the following:

Encrpting config
❯ sops --pgp=<GPG Fingerprint> --input-type yaml --output-type yaml $HOME/.clinar
Note
You can also add the yaml extension to the filename: $HOME/.clinar.yaml in that case you don’t need to specify --input-type and --output-type
GPG Fingerprint

Your gpg fingerprint you can find out with gpg --list-keys

You can set any flag or env var within the config e.g.: .Content of config file

GITLAB_TOKEN: <gitlab personal token>
GITLAB_HOST: <custom gitlab host>
gitlab personal token

A gitlab personal token can be created in your user profile in GitLab

custom gitlab host

If necessary you can set a custom gitlab host (e.g. a company private one)

Development

Generate Coverage Badge

The badge is generated using: https://github.com/jpoles1/gopherbadger