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

Commit

Permalink
Add --verbose flag to show puller progress
Browse files Browse the repository at this point in the history
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)
   ...
  • Loading branch information
scele committed Feb 14, 2018
1 parent fd3f9fc commit 2da8577
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions client/v2_2/docker_image_.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def _tags(self):
def tags(self):
return self._tags().get('tags', [])

def name(self):
return self._name

def manifests(self):
payload = self._tags()
if 'manifest' not in payload:
Expand Down
13 changes: 10 additions & 3 deletions client/v2_2/save_.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import hashlib
import json
import os
import sys
import tarfile

import concurrent.futures
Expand Down Expand Up @@ -121,7 +122,8 @@ def tarball(
def fast(
image,
directory,
threads = 1
threads = 1,
verbose = False
):
"""Produce a FromDisk compatible file layout under the provided directory.
Expand Down Expand Up @@ -151,8 +153,11 @@ def fast(
def write_file(
name,
accessor,
arg
arg,
message=None
):
if verbose and message is not None:
sys.stderr.write(message + "\n")
with open(name, 'wb') as f:
f.write(accessor(arg))

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

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

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

layers.append((digest_name, layer_name))
Expand Down
7 changes: 5 additions & 2 deletions tools/fast_puller_.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
parser.add_argument('--directory', action='store',
help='Where to save the image\'s files.')

parser.add_argument('--verbose', action='store_true',
help='Print something as the pull progresses.')

_THREADS = 8

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

logging.info('Pulling v2 image from %r ...', name)
with v2_image.FromRegistry(name, creds, transport) as v2_img:
with v2_compat.V22FromV2(v2_img) as v2_2_img:
save.fast(v2_2_img, args.directory, threads=_THREADS)
save.fast(v2_2_img, args.directory, threads=_THREADS, verbose=args.verbose)
return
# pylint: disable=broad-except
except Exception as e:
Expand Down

0 comments on commit 2da8577

Please sign in to comment.