Browse Source

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

master
Ricardo Branco 6 years ago
parent
commit
0cf5308576
1 changed files with 9 additions and 4 deletions
  1. 9
    4
      clean_registry.py

+ 9
- 4
clean_registry.py View File

@@ -2,16 +2,16 @@
2 2
 #
3 3
 # This script purges untagged repositories and runs the garbage collector in Docker Registry >= 2.4.0.
4 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 7
 # NOTES:
8 8
 #   - This script stops the Registry container during cleanup to prevent corruption,
9 9
 #     making it temporarily unavailable to clients.
10 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 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 16
 # MIT License
17 17
 #
@@ -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"
43
+VERSION = "1.0.1"
44 44
 
45 45
 
46 46
 def dockerized():
@@ -145,6 +145,11 @@ 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
+
148 153
         self.docker = docker.from_env()
149 154
 
150 155
         try:

Loading…
Cancel
Save