Explorar el Código

Add error message if trying to run stand-alone with a remote Docker setup

master
Ricardo Branco hace 6 años
padre
commit
0cf5308576
Se han modificado 1 ficheros con 9 adiciones y 4 borrados
  1. 9
    4
      clean_registry.py

+ 9
- 4
clean_registry.py Ver fichero

2
 #
2
 #
3
 # This script purges untagged repositories and runs the garbage collector in Docker Registry >= 2.4.0.
3
 # This script purges untagged repositories and runs the garbage collector in Docker Registry >= 2.4.0.
4
 # It works on the whole registry or the specified repositories.
4
 # It works on the whole registry or the specified repositories.
5
-# The optional flag -x may be used to completely remove the specified repositories or tagged images.
5
+# The optional -x flag may be used to completely remove the specified repositories or tagged images.
6
 #
6
 #
7
 # NOTES:
7
 # NOTES:
8
 #   - This script stops the Registry container during cleanup to prevent corruption,
8
 #   - This script stops the Registry container during cleanup to prevent corruption,
9
 #     making it temporarily unavailable to clients.
9
 #     making it temporarily unavailable to clients.
10
 #   - This script assumes local storage (the filesystem storage driver).
10
 #   - This script assumes local storage (the filesystem storage driver).
11
-#   - This script may run standalone or dockerized.
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 by Ricardo Branco
14
+# v1.0.1 by Ricardo Branco
15
 #
15
 #
16
 # MIT License
16
 # MIT License
17
 #
17
 #
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"
43
+VERSION = "1.0.1"
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
+
148
         self.docker = docker.from_env()
153
         self.docker = docker.from_env()
149
 
154
 
150
         try:
155
         try:

Loading…
Cancelar
Guardar