Просмотр исходного кода

Support docker-py 3.0.x

master
Ricardo Branco 6 лет назад
Родитель
Сommit
f28887db63
2 измененных файлов: 11 добавлений и 10 удалений
  1. 1
    1
      Dockerfile
  2. 10
    9
      clean_registry.py

+ 1
- 1
Dockerfile Просмотреть файл

2
 
2
 
3
 RUN	apk --no-cache add python3 python3-dev
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
 COPY	clean_registry.py /usr/local/bin/clean_registry.py
7
 COPY	clean_registry.py /usr/local/bin/clean_registry.py
8
 
8
 

+ 10
- 9
clean_registry.py Просмотреть файл

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.2 by Ricardo Branco
14
+# v1.2.1 by Ricardo Branco
15
 #
15
 #
16
 # MIT License
16
 # MIT License
17
 #
17
 #
32
 from requests import exceptions
32
 from requests import exceptions
33
 from docker.errors import APIError, NotFound, TLSParameterError
33
 from docker.errors import APIError, NotFound, TLSParameterError
34
 
34
 
35
-VERSION = "1.2"
35
+VERSION = "1.2.1"
36
 REGISTRY_DIR = "REGISTRY_STORAGE_FILESYSTEM_ROOTREGISTRY_DIR"
36
 REGISTRY_DIR = "REGISTRY_STORAGE_FILESYSTEM_ROOTREGISTRY_DIR"
37
 
37
 
38
 
38
 
200
     def get_file(self, filename):
200
     def get_file(self, filename):
201
         '''Returns the contents of the specified file from the container'''
201
         '''Returns the contents of the specified file from the container'''
202
         try:
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
         except NotFound as err:
209
         except NotFound as err:
209
             error(err)
210
             error(err)
210
         return data
211
         return data
240
     def get_image_version(self):
241
     def get_image_version(self):
241
         '''Gets the Docker distribution version running on the container'''
242
         '''Gets the Docker distribution version running on the container'''
242
         if self.info['State']['Running']:
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
         else:
245
         else:
245
             data = self.docker.containers.run(self.info["Image"], command="--version", remove=True)
246
             data = self.docker.containers.run(self.info["Image"], command="--version", remove=True)
246
         return data.decode('utf-8').split()[2]
247
         return data.decode('utf-8').split()[2]
260
             if not args.quiet:
261
             if not args.quiet:
261
                 for line in cli.logs(stream=True):
262
                 for line in cli.logs(stream=True):
262
                     print(line.decode('utf-8'), end="")
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
             cli.remove()
265
             cli.remove()
265
         return status
266
         return status
266
 
267
 

Загрузка…
Отмена
Сохранить