Ver código fonte

Catch remote Docker setup errors

master
Ricardo Branco 6 anos atrás
pai
commit
ec8001c839
1 arquivos alterados com 8 adições e 10 exclusões
  1. 8
    10
      clean_registry.py

+ 8
- 10
clean_registry.py Ver arquivo

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.0.1 by Ricardo Branco
14
+# v1.0.2 by Ricardo Branco
15
 #
15
 #
16
 # MIT License
16
 # MIT License
17
 #
17
 #
28
 from io import BytesIO
28
 from io import BytesIO
29
 from shutil import rmtree
29
 from shutil import rmtree
30
 from requests import exceptions
30
 from requests import exceptions
31
-from docker.errors import APIError, NotFound
31
+from docker.errors import APIError, NotFound, TLSParameterError
32
 
32
 
33
 try:
33
 try:
34
     import docker
34
     import docker
40
 except ImportError:
40
 except ImportError:
41
     error("Please install PyYaml with: pip3 install pyyaml")
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
 def dockerized():
46
 def dockerized():
145
 class RegistryCleaner():
145
 class RegistryCleaner():
146
     '''Simple callable class for Docker Registry cleaning duties'''
146
     '''Simple callable class for Docker Registry cleaning duties'''
147
     def __init__(self, container_name):
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
         try:
153
         try:
156
             self.info = self.docker.api.inspect_container(container_name)
154
             self.info = self.docker.api.inspect_container(container_name)
157
             self.container = self.info['Id']
155
             self.container = self.info['Id']
158
         except (APIError, exceptions.ConnectionError) as err:
156
         except (APIError, exceptions.ConnectionError) as err:
159
-            error(str(err))
157
+            error(err)
160
 
158
 
161
         if self.info['Config']['Image'] != "registry:2":
159
         if self.info['Config']['Image'] != "registry:2":
162
             error("The container %s is not running the registry:2 image" % (container_name))
160
             error("The container %s is not running the registry:2 image" % (container_name))

Carregando…
Cancelar
Salvar