diff options
author | 2016-06-08 11:26:46 +0000 | |
---|---|---|
committer | 2016-06-08 11:56:53 +0000 | |
commit | 6e3e48ee51e8174f89da853d3618baa87d7ae812 (patch) | |
tree | 53c1cac6286973dec569e0d55bdb1c40c52ea959 /tools/build_defs/docker/rewrite_json.py | |
parent | 08820c76246b249d52dc35af941ea52c2ffb1320 (diff) |
Update 'docker_build' to support 1.10 image format
Docker 1.10 updated the format of images moving layers to just being
tarballs referenced by a configuration file. A new manifest.json file
aggregates images and handles parent and tagging references. Layers and
images are now identified by their sha256 hash. An image configuration
file must reference all layers that belong to it by this identifier,
including all layers in any parent images.
Image configuration is generated the same way but now allows multiple
layer sha256 hashes to be provided. The base image configuration is read
to find config defaults and the layer identifiers that need to be
present.
Image creation now requires the layer identifier and file and can accept
multiple layers. A manifest with a single entry is created that points
at the image configuration, its layers and tags. If a base image is
provided its layers are added to the begining of the layer section and a
parent reference to the base image is added. Multiple tags can be
provided which are applied when the image is loaded.
The joining of partial images now consists of merging their contents
minus the manifest which is concatentated together.
These changes have been made in a backwards compatible way so versions
of docker below 1.10 will still work as before.
Fixes #1113
--
Change-Id: I0075decc48d8846ad16431948192db196ad702ee
Reviewed-on: https://bazel-review.googlesource.com/3730
MOS_MIGRATED_REVID=124339578
Diffstat (limited to 'tools/build_defs/docker/rewrite_json.py')
-rw-r--r-- | tools/build_defs/docker/rewrite_json.py | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/tools/build_defs/docker/rewrite_json.py b/tools/build_defs/docker/rewrite_json.py index 933a640d2e..38fd01def0 100644 --- a/tools/build_defs/docker/rewrite_json.py +++ b/tools/build_defs/docker/rewrite_json.py @@ -18,8 +18,8 @@ import json import os import os.path import sys -import tarfile +from tools.build_defs.docker import utils from third_party.py import gflags gflags.DEFINE_string( @@ -237,27 +237,6 @@ def RewriteMetadata(data, options): return output -def GetTarFile(f, name): - """Return the content of a file inside a tar file. - - This method looks for ./f, /f and f file entry in a tar file and if found, - return its content. This allows to read file with various path prefix. - - Args: - f: The tar file to read. - name: The name of the file inside the tar file. - - Returns: - The content of the file, or None if not found. - """ - with tarfile.open(f, 'r') as tar: - members = [tarinfo.name for tarinfo in tar.getmembers()] - for i in ['', './', '/']: - if i + name in members: - return tar.extractfile(i + name).read() - return None - - def GetParentIdentifier(f): """Try to look at the parent identifier from a docker image. @@ -272,10 +251,10 @@ def GetParentIdentifier(f): The identifier of the docker image, or None if no identifier was found. """ # TODO(dmarting): Maybe we could drop the 'top' file all together? - top = GetTarFile(f, 'top') + top = utils.GetTarFile(f, 'top') if top: return top.strip() - repositories = GetTarFile(f, 'repositories') + repositories = utils.GetTarFile(f, 'repositories') if repositories: data = json.loads(repositories) for k1 in data: @@ -291,7 +270,7 @@ def main(unused_argv): if FLAGS.base: parent = GetParentIdentifier(FLAGS.base) if parent: - base_json = GetTarFile(FLAGS.base, '%s/json' % parent) + base_json = utils.GetTarFile(FLAGS.base, '%s/json' % parent) data = json.loads(base_json) name = FLAGS.name |