Pārlūkot izejas kodu

Merge pull request #1 from nvtkaszpir/fix-dependencies

Fix issues with standalone run (dependencies), update readme.
master
Ricardo Branco 6 gadus atpakaļ
vecāks
revīzija
d4a71d1b11
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam
4 mainītis faili ar 54 papildinājumiem un 17 dzēšanām
  1. 2
    0
      .gitignore
  2. 36
    14
      README.md
  3. 3
    3
      clean_registry.py
  4. 13
    0
      requirements.txt

+ 2
- 0
.gitignore Parādīt failu

1
+.venv/
2
+*.pyc

+ 36
- 14
README.md Parādīt failu

1
 # clean_registry
1
 # clean_registry
2
 Clean the Docker Registry by removing untagged repositories and running the garbage collector in Docker Registry >= 2.4.0
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
 clean_registry.py [OPTIONS] CONTAINER [REPOSITORY[:TAG]]...
30
 clean_registry.py [OPTIONS] CONTAINER [REPOSITORY[:TAG]]...
17
 Options:
31
 Options:
18
         -x, --remove    Remove the specified images or repositories.
32
         -x, --remove    Remove the specified images or repositories.
19
-        -q, --quiet     Supress non-error messages.
33
+        -q, --quiet     Suppress non-error messages.
20
         -V, --version   Show version and exit.
34
         -V, --version   Show version and exit.
21
 ```
35
 ```
22
 
36
 
23
 ## Docker usage with local Docker setup
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 Parādīt failu

11
   - This script may run stand-alone (on local setups) or dockerized (which supports remote Docker setups).
11
   - This script may run stand-alone (on local setups) or dockerized (which supports remote Docker setups).
12
   - This script is Python 3 only.
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
 MIT License
16
 MIT License
17
 """
17
 """
34
 
34
 
35
 import yaml
35
 import yaml
36
 
36
 
37
-VERSION = "1.2.1"
37
+VERSION = "1.2.2"
38
 REGISTRY_DIR = "REGISTRY_STORAGE_FILESYSTEM_ROOTREGISTRY_DIR"
38
 REGISTRY_DIR = "REGISTRY_STORAGE_FILESYSTEM_ROOTREGISTRY_DIR"
39
 
39
 
40
 
40
 
241
     def get_image_version(self):
241
     def get_image_version(self):
242
         '''Gets the Docker distribution version running on the container'''
242
         '''Gets the Docker distribution version running on the container'''
243
         if self.info['State']['Running']:
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
         else:
245
         else:
246
             data = self.docker.containers.run(self.info["Image"], command="--version", remove=True)
246
             data = self.docker.containers.run(self.info["Image"], command="--version", remove=True)
247
         return data.decode('utf-8').split()[2]
247
         return data.decode('utf-8').split()[2]

+ 13
- 0
requirements.txt Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt