|
@@ -11,7 +11,7 @@
|
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.0.1 by Ricardo Branco
|
|
14
|
+# v1.0.2 by Ricardo Branco
|
15
|
15
|
#
|
16
|
16
|
# MIT License
|
17
|
17
|
#
|
|
@@ -28,7 +28,7 @@ from glob import iglob
|
28
|
28
|
from io import BytesIO
|
29
|
29
|
from shutil import rmtree
|
30
|
30
|
from requests import exceptions
|
31
|
|
-from docker.errors import APIError, NotFound
|
|
31
|
+from docker.errors import APIError, NotFound, TLSParameterError
|
32
|
32
|
|
33
|
33
|
try:
|
34
|
34
|
import docker
|
|
@@ -40,7 +40,7 @@ try:
|
40
|
40
|
except ImportError:
|
41
|
41
|
error("Please install PyYaml with: pip3 install pyyaml")
|
42
|
42
|
|
43
|
|
-VERSION = "1.0.1"
|
|
43
|
+VERSION = "1.0.2"
|
44
|
44
|
|
45
|
45
|
|
46
|
46
|
def dockerized():
|
|
@@ -145,18 +145,16 @@ def check_name(image):
|
145
|
145
|
class RegistryCleaner():
|
146
|
146
|
'''Simple callable class for Docker Registry cleaning duties'''
|
147
|
147
|
def __init__(self, container_name):
|
148
|
|
- if not dockerized():
|
149
|
|
- env_vars = ('DOCKER_HOST', 'DOCKER_TLS_VERIFY', 'DOCKER_CERT_PATH')
|
150
|
|
- if any(var for var in env_vars if var in os.environ):
|
151
|
|
- error("Do not run this script stand-alone using a remote Docker setup")
|
152
|
|
-
|
153
|
|
- self.docker = docker.from_env()
|
|
148
|
+ try:
|
|
149
|
+ self.docker = docker.from_env()
|
|
150
|
+ except TLSParameterError as err:
|
|
151
|
+ error(err)
|
154
|
152
|
|
155
|
153
|
try:
|
156
|
154
|
self.info = self.docker.api.inspect_container(container_name)
|
157
|
155
|
self.container = self.info['Id']
|
158
|
156
|
except (APIError, exceptions.ConnectionError) as err:
|
159
|
|
- error(str(err))
|
|
157
|
+ error(err)
|
160
|
158
|
|
161
|
159
|
if self.info['Config']['Image'] != "registry:2":
|
162
|
160
|
error("The container %s is not running the registry:2 image" % (container_name))
|