Skip to content
This repository was archived by the owner on Jun 4, 2021. It is now read-only.

Commit 895c594

Browse files
committed
Add --print-progress flag to show puller progress
Add minimal prints to indicate puller progress if --print-progress flag is passed to fast puller. The intention is that the bazel container_pull workspace rules could eventually output something, instead of bazel getting seemingly stuck for 10 minutes when pulling an image that is many gigabytes in size. We are intentionally not using the logging facility and the existing --stderrthreshold argument to display these prints, because that will produce log-formatted output that looks too detailed when inlined with other bazel output. The intention is to show user-friendly progress instead: Downloading from gcr.io/tensorflow/tensorflow:latest (layer 1/12) Downloading from gcr.io/tensorflow/tensorflow:latest (layer 2/12) Downloading from gcr.io/tensorflow/tensorflow:latest (layer 3/12) Downloading from gcr.io/tensorflow/tensorflow:latest (layer 4/12) Downloading from gcr.io/tensorflow/tensorflow:latest (layer 5/12) ...
1 parent 63ff239 commit 895c594

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

client/v2_2/docker_image_.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ def _tags(self):
277277
def tags(self):
278278
return self._tags().get('tags', [])
279279

280+
def name(self):
281+
return self._name
282+
280283
def manifests(self):
281284
payload = self._tags()
282285
if 'manifest' not in payload:

client/v2_2/save_.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io
2222
import json
2323
import os
24+
import sys
2425
import tarfile
2526

2627
import concurrent.futures
@@ -141,7 +142,7 @@ def tarball(name, image,
141142

142143

143144
def fast(image, directory,
144-
threads = 1):
145+
threads = 1, print_progress = False):
145146
"""Produce a FromDisk compatible file layout under the provided directory.
146147
147148
After calling this, the following filesystem will exist:
@@ -160,6 +161,7 @@ def fast(image, directory,
160161
image: a docker image to save.
161162
directory: an existing empty directory under which to save the layout.
162163
threads: the number of threads to use when performing the upload.
164+
print_progress: whether to print messages about progress to stderr.
163165
164166
Returns:
165167
A tuple whose first element is the path to the config file, and whose second
@@ -168,7 +170,9 @@ def fast(image, directory,
168170
"""
169171

170172
def write_file(name, accessor,
171-
arg):
173+
arg, message = None):
174+
if print_progress and message is not None:
175+
sys.stderr.write(message + "\n")
172176
with io.open(name, u'wb') as f:
173177
f.write(accessor(arg))
174178

@@ -181,6 +185,7 @@ def write_file(name, accessor,
181185
future_to_params[f] = config_file
182186

183187
idx = 0
188+
num_layers = len(image.fs_layers())
184189
layers = []
185190
for blob in reversed(image.fs_layers()):
186191
# Create a local copy
@@ -194,7 +199,8 @@ def write_file(name, accessor,
194199
future_to_params[f] = digest_name
195200

196201
layer_name = os.path.join(directory, '%03d.tar.gz' % idx)
197-
f = executor.submit(write_file, layer_name, image.blob, blob)
202+
message = 'Downloading from {} (layer {}/{})'.format(image.name(), idx+1, num_layers)
203+
f = executor.submit(write_file, layer_name, image.blob, blob, message)
198204
future_to_params[f] = layer_name
199205

200206
layers.append((digest_name, layer_name))

tools/fast_puller_.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
parser.add_argument(
5151
'--directory', action='store', help='Where to save the image\'s files.')
5252

53+
parser.add_argument('--print-progress', action='store_true',
54+
help='Print something as the pull progresses.')
55+
5356
_THREADS = 8
5457

5558
_PROCESSOR_ARCHITECTURE = 'amd64'
@@ -109,13 +112,15 @@ def main():
109112
logging.info('Pulling v2.2 image from %r ...', name)
110113
with v2_2_image.FromRegistry(name, creds, transport, accept) as v2_2_img:
111114
if v2_2_img.exists():
112-
save.fast(v2_2_img, args.directory, threads=_THREADS)
115+
save.fast(v2_2_img, args.directory, threads=_THREADS,
116+
print_progress=args.print_progress)
113117
return
114118

115119
logging.info('Pulling v2 image from %r ...', name)
116120
with v2_image.FromRegistry(name, creds, transport) as v2_img:
117121
with v2_compat.V22FromV2(v2_img) as v2_2_img:
118-
save.fast(v2_2_img, args.directory, threads=_THREADS)
122+
save.fast(v2_2_img, args.directory, threads=_THREADS,
123+
print_progress=args.print_progress)
119124
return
120125
# pylint: disable=broad-except
121126
except Exception as e:

0 commit comments

Comments
 (0)