You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a small tool to delete tags, or, to be more correct, delete image manifests, from a Docker Registry implementing the API v2.
@@ -9,7 +9,8 @@ Information about the needed garbage collection is described at [https://docs.do
9
9
10
10
## History
11
11
12
-
* v0.7.1 - Added a `--skip-tls-verify` attribute
12
+
* v0.8.0 - Finally find the time to migrate to Python 3 and Github Actions. This comes this many changes in the code and the surrounding build system. Support for `linux\arm64` added.
13
+
* v0.7.1 - Added a `--skip-tls-verify` attribute (_unreleased_)
13
14
* v0.7 - This is a release which breaks some stuff (configuration file is now yaml based), adding new options for keeping images (e.g. `--since`, `--regex`) (thanks to @JulianSauer for his [PR10](https://github.com/hcguersoy/cleanreg/pull/10))
14
15
* v0.6 - add `-cf` flag which allows to clean up all repos in a registry (thanks @kekru for his PR)
15
16
* v0.5 - fix for issue [#8](https://github.com/hcguersoy/cleanreg/issues/8) which resulted in deleting more layers then intended; performance improvements; added `--metadata-workers` attribute
@@ -19,32 +20,34 @@ Information about the needed garbage collection is described at [https://docs.do
19
20
* v0.2 - added support for registry server using self signed certificates
20
21
* v0.1 - first version with basics
21
22
22
-
## Prerequisites and supported Plattform
23
+
## Prerequisites and supported Platform
23
24
24
25
You need Docker and a Docker registry system which implements the Registry API v2.
25
26
For Docker Registry v2 API specification see [https://docs.docker.com/registry/spec/api/](https://docs.docker.com/registry/spec/api/).
26
27
27
-
Be sure to configure your registry server to allow deletion (see [https://docs.docker.com/registry/configuration/#/delete](https://docs.docker.com/registry/configuration/#/delete)).
28
+
Be sure to configure your registry server to allow deletion (see [https://docs.docker.com/registry/configuration/#/delete](https://docs.docker.com/registry/configuration/#/delete)).
28
29
29
30
## Usage
30
31
31
-
Download the file *cleanreg.py* or clone this repository to a local directory or pull the docker image. This is the suggested way to run `cleanreg`!
32
+
Download the file _cleanreg.py_ or clone this repository to a local directory or pull the docker image.
33
+
Beginning with version `v0.0.8`, images are supported for `linux/amd64` and (this is new) `linux\arm64`.
34
+
This is the suggested way to run `cleanreg`!
32
35
33
-
```
34
-
docker pull hcguersoy/cleanreg:v0.7.0
36
+
```shell
37
+
docker pull hcguersoy/cleanreg:v0.8.0
35
38
```
36
39
37
40
The image is hosted here: [https://hub.docker.com/r/hcguersoy/cleanreg/](https://hub.docker.com/r/hcguersoy/cleanreg/"")
38
41
39
-
*Hint:*`latest` tag is not supported (you know, `latest` is evil 😈).
42
+
_Hint:_`latest` tag is not supported (you know, `latest` is evil :imp:).
40
43
41
44
To get a immediate help simply run it without any parameters:
As an alternative, you can create your own image, inheriting from `cleanreg`:
128
130
129
-
```
130
-
FROM hcguersoy/cleanreg:v0.7.0
131
+
```shell
132
+
FROM hcguersoy/cleanreg:<version>
131
133
ADD myconfig.yaml /config.yaml
132
134
```
133
135
134
136
## Examples
135
137
136
-
**Attention:** It is strongly recommended that you use the *-i* flag even it is more time and memory consuming. If not you can delete images / layers which you not wanted to delete because registry itself doesn't check if a digest is referenced by multiple tags!
138
+
**Attention:** It is strongly recommended that you use the _-i_ flag even it is more time and memory consuming. If not you can delete images / layers which you not wanted to delete because registry itself doesn't check if a digest is referenced by multiple tags!
137
139
138
140
Cleaning up a single repository called mysql on registry server 192.168.56.2:5000 and keeping 5 of the latest images:
139
141
140
-
```
142
+
```shell
141
143
docker run --rm -it hcguersoy/cleanreg:<version> -r http://192.168.56.2:5000 -n mysql -k 5
142
144
```
145
+
143
146
Be aware that you don't keep here the five last tags but digests/images. As a digest can be associated with multiple tags this can result in deletion of images which you not intended in!
144
147
Again: to be secure use the `-i` flag:
145
148
146
-
```
149
+
```shell
147
150
docker run --rm -it hcguersoy/cleanreg:<version> -r http://192.168.56.2:5000 -n mysql -k 5 -i
148
151
```
149
152
150
153
Same as above but ignore images which are associated with multiple tags.
151
154
152
-
```
155
+
```shell
153
156
docker run --rm -it hcguersoy/cleanreg:<version> -r http://192.168.56.2:5000 -n mysql:latest -i
154
157
```
155
158
156
159
Will only delete the image mysql which is tagged as latest.
If you have a very large registry and enough bandwidth you can increase the parallel workers to retrieve the image metadata. The default is *6*. Be aware that you can generate a *DoS* on your registry server by increasing to much.
169
-
171
+
If you have a very large registry and enough bandwidth you can increase the parallel workers to retrieve the image metadata. The default is _6_. Be aware that you can generate a _DoS_ on your registry server by increasing to much.
@@ -198,7 +201,7 @@ The configuration file has the format
198
201
199
202
The values for`tag`, `keepimages` and `keepsince` are optional. If the tag should be parsed as a regular expression use the `-re` flag as shown above. A simple example for the configuration file:
200
203
201
-
```
204
+
```yaml
202
205
consul:
203
206
tag: OnlyThisTag
204
207
keepimages: 20
@@ -210,36 +213,38 @@ dummybox:
210
213
keepimages: 0
211
214
```
212
215
213
-
214
216
The configuration file can be used together with the clean-full-catalog option:
This will clean the repositories with images to keep as defined in the configuration file and it will additionally clean all other repositories of the registry, keeping images per repository that were created since 2018.
220
221
222
+
This will clean the repositories with images to keep as defined in the configuration file and it will additionally clean all other repositories of the registry, keeping images per repository that were created since 2018.
221
223
222
224
There is a simple script added to create multiple image tags (based on `busybox`) on your registry server.
223
225
224
-
If you have installed a *semi secure* registry server using TLS and self signed certificates you have to provide the path to the CA certificate file:
226
+
If you have installed a _semi secure_ registry server using TLS and self signed certificates you have to provide the path to the CA certificate file:
If you run *cleanreg* in a container you should not forget to mount the certificate file into the container like the configuration file above.
232
+
If you run _cleanreg_ in a container you should not forget to mount the certificate file into the container like the configuration file above.
233
+
Alternatively you can set the option `--skip-tls-verify`. In this case, you don't need to provide a certificate.
231
234
232
-
If your registry is protected with basic auth and the username is `test` and the password is `secret`, you have to pass these credentials to *cleanreg*.
235
+
> :exclamation: be aware that this should only used for (local) testing but not for productive environments.
233
236
234
-
```
237
+
If your registry is protected with basic auth and the username is `test` and the password is `secret`, you have to pass these credentials to _cleanreg_.
238
+
239
+
```shell
235
240
./cleanreg.py -r https://192.168.56.3:5000 -u test -pw secret -f cleanreg-example.conf
236
241
```
237
242
238
-
## Runing Garbage Collection
243
+
## Running Garbage Collection
239
244
240
245
Example on running the garbage collection:
241
246
242
-
```
247
+
```shell
243
248
$ docker run --rm \
244
249
-v /docker/registry2:/var/lib/registry:rw \
245
250
registry:latest bin/registry \
@@ -254,27 +259,28 @@ The registry itself should be stopped before running this.
254
259
255
260
Feel free to contribute your changes as a PR. Please ensure that the tests run without errors and provide tests for additional functionality.
256
261
257
-
This tool was implemented and tested on Ubuntu Linux 16.04 and on MacOS 10.13 using Python 2.7. It is developed against Docker Registry version [2.5.1](https://github.com/docker/distribution/releases/tag/v2.5.1), but tested against [2.6.1](https://github.com/docker/distribution/releases/tag/v2.6.1) and *latest* (see [https://hub.docker.com/r/library/registry/](https://hub.docker.com/r/library/registry/)).
262
+
This tool was initially implemented and tested on Ubuntu Linux 16.04 and on MacOS 10.13 using Python 2.7 and migrated to Python 3.10 on macOS 12 (arm64).
263
+
It is developed and tested against Docker Registry versions [v2.7.1](https://github.com/docker/distribution/releases/tag/v2.7.1) and [v2.8.0](https://github.com/docker/distribution/releases/tag/v2.8.8).
264
+
It should work with older registry versions which are supporting the API, but they are not tested anymore.
258
265
259
-
You need to install the Python modules *requests* and *PyYAML*:
266
+
You need to install the Python modules _requests_ and _PyYAML_:
260
267
261
-
```
268
+
```shell
262
269
$ pip install requests PyYAML
263
270
```
264
271
265
-
Be sure to configure your registry server to allow deletion (see [https://docs.docker.com/registry/configuration/#/delete](https://docs.docker.com/registry/configuration/#/delete)).
266
-
272
+
Be sure to configure your registry server to allow deletion (see [https://docs.docker.com/registry/configuration/#delete](https://docs.docker.com/registry/configuration/#delete)).
267
273
268
-
### Run tests
274
+
### Run tests locally
269
275
270
276
Prerequisites:
271
277
272
278
* Bash
273
-
* Locally installed Docker engine (remote execution is not yet implemented; runs with Docker for MacOS fine)
279
+
* Locally installed Docker engine. Remote execution is not yet implemented. Runs with [Rancher Desktop](https://rancherdesktop.io) on macOS fine (configured to use _dockerd_ as runtime).
274
280
275
-
You can run all tests, with the *runAllTests.sh* script:
281
+
You can run all tests, with the _runAllTests.sh_ script:
276
282
277
-
```
283
+
```shell
278
284
cd test
279
285
./runAllTests.sh
280
286
```
@@ -283,14 +289,25 @@ This will run all tests and repeat them for different versions of the Docker Reg
283
289
284
290
To run a single test, change to the `test/tests` directory and run a test script:
285
291
286
-
```
292
+
```shell
287
293
cd test/tests
288
294
./simple_clean.sh
289
295
```
290
-
By default the test will start the Docker Registry from Docker Hub with the tag `latest`. To specify another registry version, write its Docker Hub tag to the environment variable `REGISTRYTAG`.
291
296
292
-
```
297
+
By default the test will start the Docker Registry from Docker Hub with the tag `latest`.
298
+
To specify another registry version, set it using the environment variable `REGISTRYTAG`.
299
+
300
+
```shell
293
301
cd test/tests
294
302
export REGISTRYTAG=2.5.1
295
303
./simple_clean.sh
296
304
```
305
+
306
+
### GitHub Actions
307
+
308
+
After pushing to `master` or a branch `feature\*` or `pr\*` a GitHub Action will be triggered which runs the tests defined in `test/runAllTests.sh`. If one of these tests fail, the action will fail, too.
309
+
If the build was triggered due to the creation of a release, a GitHub Action will be triggered, too. In this case, after running successfully the tests, the Docker image will be build with the help of _buildx_.
310
+
Currently, two kinds of architectures are supported: `linux/amd64` and `linux/arm64`.
311
+
The later one could be used on Apple Silicon systems this the according runtime, e. g. Rancher Desktop.
312
+
313
+
> Due to lack of knowledge regarding other ARM systems (e. g. Raspberry Pi) you are very welcome to provide a PR.
0 commit comments