Browse Source

Support docker-py 3.0.x

master
Ricardo Branco 6 years ago
parent
commit
f28887db63
2 changed files with 11 additions and 10 deletions
  1. 1
    1
      Dockerfile
  2. 10
    9
      clean_registry.py

+ 1
- 1
Dockerfile View File

@@ -2,7 +2,7 @@ FROM	registry:2
2 2
 
3 3
 RUN	apk --no-cache add python3 python3-dev
4 4
 
5
-RUN	pip3 install --no-cache-dir docker==2.7.0 docker[tls] pyyaml
5
+RUN	pip3 install --no-cache-dir docker docker[tls] pyyaml
6 6
 
7 7
 COPY	clean_registry.py /usr/local/bin/clean_registry.py
8 8
 

+ 10
- 9
clean_registry.py View File

@@ -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.2 by Ricardo Branco
14
+# v1.2.1 by Ricardo Branco
15 15
 #
16 16
 # MIT License
17 17
 #
@@ -32,7 +32,7 @@ from shutil import rmtree
32 32
 from requests import exceptions
33 33
 from docker.errors import APIError, NotFound, TLSParameterError
34 34
 
35
-VERSION = "1.2"
35
+VERSION = "1.2.1"
36 36
 REGISTRY_DIR = "REGISTRY_STORAGE_FILESYSTEM_ROOTREGISTRY_DIR"
37 37
 
38 38
 
@@ -200,11 +200,12 @@ class RegistryCleaner():
200 200
     def get_file(self, filename):
201 201
         '''Returns the contents of the specified file from the container'''
202 202
         try:
203
-            with self.docker.api.get_archive(self.container, filename)[0] as tar:
204
-                with BytesIO(tar.data) as buf:
205
-                    with tarfile.open(fileobj=buf) as tarf:
206
-                        with tarf.extractfile(os.path.basename(filename)) as f:
207
-                            data = f.read()
203
+            archive = self.docker.api.get_archive(self.container, filename)[0]
204
+            binary = b"".join(chunk for chunk in archive)
205
+            with BytesIO(binary) as buf:
206
+                with tarfile.open(fileobj=buf) as tar:
207
+                    with tar.extractfile(os.path.basename(filename)) as f:
208
+                        data = f.read()
208 209
         except NotFound as err:
209 210
             error(err)
210 211
         return data
@@ -240,7 +241,7 @@ class RegistryCleaner():
240 241
     def get_image_version(self):
241 242
         '''Gets the Docker distribution version running on the container'''
242 243
         if self.info['State']['Running']:
243
-            data = self.docker.containers.get(self.container).exec_run("/bin/registry --version")
244
+            data = self.docker.containers.get(self.container).exec_run("/bin/registry --version")[0]
244 245
         else:
245 246
             data = self.docker.containers.run(self.info["Image"], command="--version", remove=True)
246 247
         return data.decode('utf-8').split()[2]
@@ -260,7 +261,7 @@ class RegistryCleaner():
260 261
             if not args.quiet:
261 262
                 for line in cli.logs(stream=True):
262 263
                     print(line.decode('utf-8'), end="")
263
-            status = True if cli.wait() == 0 else False
264
+            status = True if cli.wait()['StatusCode'] == 0 else False
264 265
             cli.remove()
265 266
         return status
266 267
 

Loading…
Cancel
Save