README.md 3.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
# containinator

A simple Clojure command line app to instruct GitLab to clean Docker image tags for all projects.
It uses the GitLab REST API (v4) to retrieve project information and sending bulk deletion requests for tags.
The app can be used to list projects and their number of registry repositories and tags as well.

The app is meant to be used in conjunction with [GitLab's docker-distribution-pruner](https://gitlab.com/gitlab-org/docker-distribution-pruner).
The `docker-distribution-pruner` cli app seems to delete more of the orphaned image data than the built in `gitlab-ctl registry-garbage-collect`.
For this reason you should probably use `docker-distribution-pruner` after running containinator.

## Installation

13
14
15
16
17
18
19
20
21
22
23
24
25
26
You can run the command via the Docker image:

```bash
docker run -it --rm docker.nsd.no/ops/containinator:latest --help
```

You can also build the app binary yourself.
Refer to the development section for detailed instructions.

```bash
clj -Anative-image
# You need to tell the command where to find java libs so it can get the libsunec.so file
./containinator -Djava.library.path=/path/to/java/lib/ --help
```
27
28
29

### Caveat

30
Currently binaries compiled with GraalVM's native-image does not statically link the `sunec` dependency.
31
32
33
34
If you are running the binary on its own you need to supply the sunec library via an openjdk or graalvm installation.
There is [an issue](https://github.com/oracle/graal/issues/1336) about this in the official graal repository.

For the time being you can run the binary with `containinator -Djava.library.path=/<path to java/graal>/lib/`.
35
The Docker image is based on the `adoptopenjdk/openjdk12` image and thus bundles the libsunec.so file.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


## Usage

```bash
./containinator --help
```

There are two sub-commands in the app:

- locate
- terminate

The `locate` command lists projects and key stats about the project's container registry.
The `terminate` command sends bulk tag deletion commands for all projects with a container registry.


## Examples

```bash
56
./containinator -Djava.library.path=$JAVA_HOME/lib/ --token <yourtoken> --gitlab https://gitlab.<yourdomain>.<tld> locate --sort tag-count --limit 20 -f tag-count -f registry-count
57
58
59
60
61
62
63
64
65
66
67
68
Locating projects for given arguments on https://gitlab.nsd.no Please be patient, it could take some time.


| :id |                 :name | :registry-count | :tag-count |
|-----+-----------------------+-----------------+------------|
| 123 |             project-a |               1 |         28 |
| 242 |             project-b |               1 |         27 |

```

## Development

69
70
71
72
73
74
75
Ensure you have the following installed:

- [openjdk](https://adoptopenjdk.net/)
- [Clojure](https://clojure.org/guides/getting_started)
- [GraalVM](https://github.com/oracle/graal/releases)

To run a repl:
76

77
78
79
80
81
82
```bash
clj
```

Use your editor's jack-in functionality when developing with an editor like Emacs, VSCode Calva, or IntelliJ Cursive.

83
### To comple a binary using GraalVM:
84
85
86
87
88

```bash
clj -Anative-image
```

89
90
91
92
93
94
95
96
97
Note that you need to install [GraalVM](https://github.com/oracle/graal/releases) and associated libs:

```
sudo apt-get install build-essential libz-dev zlib1g-dev
```

Add `/path/to/graal-vm/bin` to your `$PATH`, and a `$GRAALVM_HOME` to point to `/path/to/graal-vm`.

### To build a Docker image:
98
99
100
101
102
103
104

Ensure that the `libsunec.so` command is present in the project root.
You can copy it from your GraalVM installation.

```bash
docker build -t docker.nsd.no/ops/containinator:latest .
```
105

106
## Testing
107

108
Testing is not really applicable as more or less the entire app is side-effecting.
109
110
111
112
113
114
115
116
117
118


## License

Copyright © 2019 NSD - Norsk senter for forskningsdata AS

Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.

The `links.clj` file is verbatim copied from [clj-http](https://github.com/dakrone/clj-http) and retains its original license.