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

Commit 2da8577

Browse files
committed
Add --verbose flag to show puller progress
Add minimal prints to indicate puller progress if --verbose 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 fd3f9fc commit 2da8577

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
@@ -260,6 +260,9 @@ def _tags(self):
260260
def tags(self):
261261
return self._tags().get('tags', [])
262262

263+
def name(self):
264+
return self._name
265+
263266
def manifests(self):
264267
payload = self._tags()
265268
if 'manifest' not in payload:

client/v2_2/save_.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import hashlib
2121
import json
2222
import os
23+
import sys
2324
import tarfile
2425

2526
import concurrent.futures
@@ -121,7 +122,8 @@ def tarball(
121122
def fast(
122123
image,
123124
directory,
124-
threads = 1
125+
threads = 1,
126+
verbose = False
125127
):
126128
"""Produce a FromDisk compatible file layout under the provided directory.
127129
@@ -151,8 +153,11 @@ def fast(
151153
def write_file(
152154
name,
153155
accessor,
154-
arg
156+
arg,
157+
message=None
155158
):
159+
if verbose and message is not None:
160+
sys.stderr.write(message + "\n")
156161
with open(name, 'wb') as f:
157162
f.write(accessor(arg))
158163

@@ -164,6 +169,7 @@ def write_file(
164169
future_to_params[f] = config_file
165170

166171
idx = 0
172+
num_layers = len(image.fs_layers())
167173
layers = []
168174
for blob in reversed(image.fs_layers()):
169175
# Create a local copy
@@ -174,7 +180,8 @@ def write_file(
174180
future_to_params[f] = digest_name
175181

176182
layer_name = os.path.join(directory, '%03d.tar.gz' % idx)
177-
f = executor.submit(write_file, layer_name, image.blob, blob)
183+
message = 'Downloading from {} ({}/{})'.format(image.name(), idx+1, num_layers)
184+
f = executor.submit(write_file, layer_name, image.blob, blob, message)
178185
future_to_params[f] = layer_name
179186

180187
layers.append((digest_name, layer_name))

tools/fast_puller_.py

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

51+
parser.add_argument('--verbose', action='store_true',
52+
help='Print something as the pull progresses.')
53+
5154
_THREADS = 8
5255

5356
_PROCESSOR_ARCHITECTURE = 'amd64'
@@ -107,13 +110,13 @@ def main():
107110
logging.info('Pulling v2.2 image from %r ...', name)
108111
with v2_2_image.FromRegistry(name, creds, transport, accept) as v2_2_img:
109112
if v2_2_img.exists():
110-
save.fast(v2_2_img, args.directory, threads=_THREADS)
113+
save.fast(v2_2_img, args.directory, threads=_THREADS, verbose=args.verbose)
111114
return
112115

113116
logging.info('Pulling v2 image from %r ...', name)
114117
with v2_image.FromRegistry(name, creds, transport) as v2_img:
115118
with v2_compat.V22FromV2(v2_img) as v2_2_img:
116-
save.fast(v2_2_img, args.directory, threads=_THREADS)
119+
save.fast(v2_2_img, args.directory, threads=_THREADS, verbose=args.verbose)
117120
return
118121
# pylint: disable=broad-except
119122
except Exception as e:

0 commit comments

Comments
 (0)