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

Commit b962cd8

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 5b4a2cd commit b962cd8

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io
2323
import json
2424
import os
25+
import sys
2526
import tarfile
2627

2728
import concurrent.futures
@@ -144,7 +145,8 @@ def tarball(name, image,
144145
def fast(image,
145146
directory,
146147
threads = 1,
147-
cache_directory = None):
148+
cache_directory = None,
149+
print_progress = False):
148150
"""Produce a FromDisk compatible file layout under the provided directory.
149151
150152
After calling this, the following filesystem will exist:
@@ -166,6 +168,7 @@ def fast(image,
166168
directory: an existing empty directory under which to save the layout.
167169
threads: the number of threads to use when performing the upload.
168170
cache_directory: directory that stores file cache.
171+
print_progress: whether to print pull status messages to stderr.
169172
170173
Returns:
171174
A tuple whose first element is the path to the config file, and whose second
@@ -174,13 +177,15 @@ def fast(image,
174177
"""
175178

176179
def write_file(name, accessor,
177-
arg):
180+
arg, message = None):
181+
if print_progress and message is not None:
182+
sys.stderr.write(message + "\n")
178183
with io.open(name, u'wb') as f:
179184
f.write(accessor(arg))
180185

181186
def write_file_and_store(name, accessor,
182-
arg, cached_layer):
183-
write_file(cached_layer, accessor, arg)
187+
arg, cached_layer, message = None):
188+
write_file(cached_layer, accessor, arg, message)
184189
link(cached_layer, name)
185190

186191
def link(source, dest):
@@ -225,11 +230,13 @@ def valid(cached_layer, digest):
225230
'unused')
226231

227232
idx = 0
233+
num_layers = len(image.fs_layers())
228234
layers = []
229235
for blob in reversed(image.fs_layers()):
230236
# Create a local copy
231237
layer_name = os.path.join(directory, '%03d.tar.gz' % idx)
232238
digest_name = os.path.join(directory, '%03d.sha256' % idx)
239+
message = 'Downloading from {} (layer {}/{})'.format(image.name(), idx+1, num_layers)
233240
# Strip the sha256: prefix
234241
digest = blob[7:].encode('utf8')
235242
f = executor.submit(
@@ -247,10 +254,10 @@ def valid(cached_layer, digest):
247254
future_to_params[f] = layer_name
248255
else:
249256
f = executor.submit(write_file_and_store, layer_name, image.blob,
250-
blob, cached_layer)
257+
blob, cached_layer, message)
251258
future_to_params[f] = layer_name
252259
else:
253-
f = executor.submit(write_file, layer_name, image.blob, blob)
260+
f = executor.submit(write_file, layer_name, image.blob, blob, message)
254261
future_to_params[f] = layer_name
255262

256263
layers.append((digest_name, layer_name))

tools/fast_puller_.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
'located. Overiddes the value from DOCKER_CONFIG')
6363
parser.add_argument(
6464
'--cache', action='store', help='Image\'s files cache directory.')
65+
parser.add_argument(
66+
'--print-progress', action='store_true', help='Print pull progresses to stderr.')
67+
6568

6669
_THREADS = 8
6770

@@ -125,7 +128,8 @@ def main():
125128
v2_2_img,
126129
args.directory,
127130
threads=_THREADS,
128-
cache_directory=args.cache)
131+
cache_directory=args.cache,
132+
print_progress=args.print_progress)
129133
return
130134

131135
logging.info('Pulling v2 image from %r ...', name)
@@ -135,7 +139,8 @@ def main():
135139
v2_2_img,
136140
args.directory,
137141
threads=_THREADS,
138-
cache_directory=args.cache)
142+
cache_directory=args.cache,
143+
print_progress=args.print_progress)
139144
return
140145
# pylint: disable=broad-except
141146
except Exception as e:

0 commit comments

Comments
 (0)