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

Commit 830df69

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 (1/12) Downloading from gcr.io/tensorflow/tensorflow:latest (2/12) Downloading from gcr.io/tensorflow/tensorflow:latest (3/12) Downloading from gcr.io/tensorflow/tensorflow:latest (4/12) Downloading from gcr.io/tensorflow/tensorflow:latest (5/12) ...
1 parent 1b7d4a4 commit 830df69

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

client/v2_2/docker_image_.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ def _tags(self):
255255
def tags(self):
256256
return self._tags().get('tags', [])
257257

258+
def name(self):
259+
return self._name
260+
258261
def manifests(self):
259262
payload = self._tags()
260263
if 'manifest' not in payload:

client/v2_2/save_.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import hashlib
2020
import json
2121
import os
22+
import sys
2223
import tarfile
2324

2425
import concurrent.futures
@@ -116,7 +117,7 @@ def tarball(name, image,
116117

117118

118119
def fast(image, directory,
119-
threads = 1):
120+
threads = 1, print_progress = False):
120121
"""Produce a FromDisk compatible file layout under the provided directory.
121122
122123
After calling this, the following filesystem will exist:
@@ -143,7 +144,9 @@ def fast(image, directory,
143144
"""
144145

145146
def write_file(name, accessor,
146-
arg):
147+
arg, message = None):
148+
if print_progress and message is not None:
149+
sys.stderr.write(message + "\n")
147150
with open(name, 'wb') as f:
148151
f.write(accessor(arg))
149152

@@ -155,6 +158,7 @@ def write_file(name, accessor,
155158
future_to_params[f] = config_file
156159

157160
idx = 0
161+
num_layers = len(image.fs_layers())
158162
layers = []
159163
for blob in reversed(image.fs_layers()):
160164
# Create a local copy
@@ -168,7 +172,8 @@ def write_file(name, accessor,
168172
future_to_params[f] = digest_name
169173

170174
layer_name = os.path.join(directory, '%03d.tar.gz' % idx)
171-
f = executor.submit(write_file, layer_name, image.blob, blob)
175+
message = 'Downloading from {} ({}/{})'.format(image.name(), idx+1, num_layers)
176+
f = executor.submit(write_file, layer_name, image.blob, blob, message)
172177
future_to_params[f] = layer_name
173178

174179
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)