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

Commit

Permalink
Fix the glob issue.
Browse files Browse the repository at this point in the history
Expose a `fast_importer` for folks looking to check in a Docker image.

Fixes #11
  • Loading branch information
mattmoor committed Jun 30, 2017
1 parent b745512 commit 91540a3
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 24 deletions.
58 changes: 36 additions & 22 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,57 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
package(default_visibility=["//visibility:public"])
package(default_visibility = ["//visibility:public"])

py_library(
name = "containerregistry",
srcs = glob(["**/*.py"]),
deps = [
"@httplib2//:httplib2",
"@oauth2client//:oauth2client",
"@concurrent//:concurrent",
]
name = "containerregistry",
srcs = glob([
"__init__.py",
"client/**/*.py",
"tools/**/*.py",
"transform/**/*.py",
"transport/**/*.py",
]),
deps = [
"@concurrent//:concurrent",
"@httplib2//:httplib2",
"@oauth2client//:oauth2client",
],
)

load("@subpar//:subpar.bzl", "par_binary")

par_binary(
name = "puller",
srcs = ["tools/fast_puller_.py"],
main = "tools/fast_puller_.py",
visibility = ["//visibility:public"],
deps = [":containerregistry"]
name = "puller",
srcs = ["tools/fast_puller_.py"],
main = "tools/fast_puller_.py",
visibility = ["//visibility:public"],
deps = [":containerregistry"],
)

par_binary(
name = "importer",
srcs = ["tools/fast_importer_.py"],
main = "tools/fast_importer_.py",
visibility = ["//visibility:public"],
deps = [":containerregistry"],
)

par_binary(
name = "pusher",
srcs = ["tools/fast_pusher_.py"],
main = "tools/fast_pusher_.py",
visibility = ["//visibility:public"],
deps = [":containerregistry"]
name = "pusher",
srcs = ["tools/fast_pusher_.py"],
main = "tools/fast_pusher_.py",
visibility = ["//visibility:public"],
deps = [":containerregistry"],
)

sh_test(
name = "puller_test",
size = "large",
srcs = ["puller_test.sh"],
data = [
":puller.par",
"testenv.sh",
"testenv.sh",
":puller.par",
],
)

Expand All @@ -56,7 +70,7 @@ sh_test(
size = "large",
srcs = ["pusher_test.sh"],
data = [
":pusher.par",
"testenv.sh",
"testenv.sh",
":pusher.par",
],
)
2 changes: 1 addition & 1 deletion client/v2/docker_image_.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def blob(self, digest):
if digest != computed:
raise DigestMismatchedError(
'The returned content\'s digest did not match its content-address, '
'%s vs. %s' % (digest, computed))
'%s vs. %s' % (digest, computed if c else '(content was empty)'))
return c

def catalog(self, page_size=100):
Expand Down
2 changes: 1 addition & 1 deletion client/v2_2/docker_image_.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def blob(self, digest):
if digest != computed:
raise DigestMismatchedError(
'The returned content\'s digest did not match its content-address, '
'%s vs. %s' % (digest, computed))
'%s vs. %s' % (digest, computed if c else '(content was empty)'))
return c

def catalog(self, page_size=100):
Expand Down
4 changes: 4 additions & 0 deletions tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
setattr(x, 'fast_puller', fast_puller_)


from containerregistry.tools import fast_importer_
setattr(x, 'fast_importer', fast_importer_)


from containerregistry.tools import fast_pusher_
setattr(x, 'fast_pusher', fast_pusher_)

Expand Down
52 changes: 52 additions & 0 deletions tools/fast_importer_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This package imports images from a 'docker save' tarball.
Unlike 'docker save' the format this uses is proprietary.
"""



import argparse

from containerregistry.client.v2_2 import docker_image as v2_2_image
from containerregistry.client.v2_2 import save
from containerregistry.tools import patched

parser = argparse.ArgumentParser(
description='Import images from a tarball into our faaaaaast format.')

parser.add_argument('--tarball', action='store',
help=('The tarball containing the docker image to rewrite '
'into our fast on-disk format.'))

parser.add_argument('--directory', action='store',
help='Where to save the image\'s files.')

_THREADS = 8


def main():
args = parser.parse_args()

if not args.tarball or not args.directory:
raise Exception('--tarball and --directory are required arguments.')

with v2_2_image.FromTarball(args.tarball) as v2_2_img:
save.fast(v2_2_img, args.directory, threads=_THREADS)


if __name__ == '__main__':
with patched.Httplib2():
main()

0 comments on commit 91540a3

Please sign in to comment.