Browse Source

Fix issues with standalone run (dependencies), update readme.

master
kaszpir 6 years ago
parent
commit
ecbd004a76
3 changed files with 52 additions and 17 deletions
  1. 36
    14
      README.md
  2. 3
    3
      clean_registry.py
  3. 13
    0
      requirements.txt

+ 36
- 14
README.md View File

@@ -1,31 +1,53 @@
1 1
 # clean_registry
2 2
 Clean the Docker Registry by removing untagged repositories and running the garbage collector in Docker Registry >= 2.4.0
3 3
 
4
-The optional `-x` flag may be used to remove the specified repositories or tagged images.
4
+The optional ``-x`` flag may be used to remove the specified repositories or tagged images.
5 5
 
6
-NOTES:
7
-  - This script stops the Registry container during cleanup to prevent corruption, making it temporarily unavailable to clients.
8
-  - This script assumes the [filesystem](https://github.com/docker/distribution/blob/master/docs/configuration.md#storage) storage driver.
9
-  - This script may run stand-alone (on local setups) or dockerized (which supports both local and remote Docker setups). To run stand-alone, you must install **docker-py** and **pyyaml** with:
10
-  
11
-  `pip3 install docker pyyaml`
12
-  
13
-## Usage:
6
+# WARNING:
7
+
8
+Make backups of target docker-registry/containers/tags to avoid loosing data.
9
+
10
+This script stops the Registry container during cleanup to prevent corruption, making it temporarily unavailable to clients.
11
+
12
+This script assumes the [filesystem](https://github.com/docker/distribution/blob/master/docs/configuration.md#storage) storage driver.
13
+
14
+## Running standalone
15
+
16
+This script may be run as stand-alone (on local setups) or dockerized (which supports both local and remote Docker setups). To run stand-alone, the best is to run in virtualenv and install required packages via pip:
17
+
18
+```bash
19
+virtualenv --python=python3 .venv
20
+. .venv/bin/activate
21
+pip3 install --upgrade pip
22
+pip3 install -r requirements.txt
23
+```
24
+
25
+You may need to execute above commands as privileged user to access docker service (sudo + activate virtualenv).
26
+
27
+## Usage
14 28
 
15 29
 ```
16 30
 clean_registry.py [OPTIONS] CONTAINER [REPOSITORY[:TAG]]...
17 31
 Options:
18 32
         -x, --remove    Remove the specified images or repositories.
19
-        -q, --quiet     Supress non-error messages.
33
+        -q, --quiet     Suppress non-error messages.
20 34
         -V, --version   Show version and exit.
21 35
 ```
22 36
 
23 37
 ## Docker usage with local Docker setup
24 38
 
25
-`docker run --rm --volumes-from CONTAINER -v /var/run/docker.sock:/var/run/docker.sock ricardobranco/clean_registry [OPTIONS] CONTAINER [REPOSITORY[:TAG]]...`
39
+```bash
40
+docker run --rm --volumes-from CONTAINER -v /var/run/docker.sock:/var/run/docker.sock ricardobranco/clean_registry [OPTIONS] CONTAINER [REPOSITORY[:TAG]] ...
41
+```
42
+
43
+## Docker usage with remote Docker setup
44
+
45
+Make sure to read about [remote Docker setup](https://docs.docker.com/engine/security/https/#secure-by-default).
26 46
 
27
-## Docker usage with [remote Docker setup](https://docs.docker.com/engine/security/https/#secure-by-default)
47
+```bash
48
+docker run --rm --volumes-from CONTAINER -e DOCKER_HOST -e DOCKER_TLS_VERIFY=1 -v /root/.docker:/root/.docker ricardobranco/clean_registry [OPTIONS] CONTAINER [REPOSITORY[:TAG]]...
49
+```
28 50
 
29
-`docker run --rm --volumes-from CONTAINER -e DOCKER_HOST -e DOCKER_TLS_VERIFY=1 -v /root/.docker:/root/.docker ricardobranco/clean_registry [OPTIONS] CONTAINER [REPOSITORY[:TAG]]...`
51
+Note:
30 52
 
31
-Note: Paths other than `/root/.docker` path may be specified with the **DOCKER_CERT_PATH** environment variable.  In any case, your `~/.docker/*.pem` files should be in the server to be able to run as a client against itself.
53
+Paths other than ``/root/.docker`` path may be specified with the ``**DOCKER_CERT_PATH**`` environment variable.  In any case, your ``~/.docker/*.pem`` files should be in the server to be able to run as a client against itself.

+ 3
- 3
clean_registry.py View File

@@ -11,7 +11,7 @@ NOTES:
11 11
   - This script may run stand-alone (on local setups) or dockerized (which supports remote Docker setups).
12 12
   - This script is Python 3 only.
13 13
 
14
-v1.2.1 by Ricardo Branco
14
+v1.2.2 by Ricardo Branco
15 15
 
16 16
 MIT License
17 17
 """
@@ -34,7 +34,7 @@ from docker.errors import APIError, NotFound, TLSParameterError
34 34
 
35 35
 import yaml
36 36
 
37
-VERSION = "1.2.1"
37
+VERSION = "1.2.2"
38 38
 REGISTRY_DIR = "REGISTRY_STORAGE_FILESYSTEM_ROOTREGISTRY_DIR"
39 39
 
40 40
 
@@ -241,7 +241,7 @@ class RegistryCleaner():
241 241
     def get_image_version(self):
242 242
         '''Gets the Docker distribution version running on the container'''
243 243
         if self.info['State']['Running']:
244
-            data = self.docker.containers.get(self.container).exec_run("/bin/registry --version")[0]
244
+            data = self.docker.containers.get(self.container).exec_run("/bin/registry --version").output
245 245
         else:
246 246
             data = self.docker.containers.run(self.info["Image"], command="--version", remove=True)
247 247
         return data.decode('utf-8').split()[2]

+ 13
- 0
requirements.txt View File

@@ -0,0 +1,13 @@
1
+backports.ssl-match-hostname==3.5.0.1
2
+backports.weakref==1.0.post1
3
+certifi==2018.1.18
4
+chardet==3.0.4
5
+docker==3.1.0
6
+docker-pycreds==0.2.2
7
+idna==2.6
8
+pkg-resources==0.0.0
9
+PyYAML==3.12
10
+requests==2.18.4
11
+six==1.11.0
12
+urllib3==1.22
13
+websocket-client==0.47.0

Loading…
Cancel
Save