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/incremental_load.sh.tpl | |
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/incremental_load.sh.tpl')
-rw-r--r-- | tools/build_defs/docker/incremental_load.sh.tpl | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/tools/build_defs/docker/incremental_load.sh.tpl b/tools/build_defs/docker/incremental_load.sh.tpl index 2db031d478..5ca164df05 100644 --- a/tools/build_defs/docker/incremental_load.sh.tpl +++ b/tools/build_defs/docker/incremental_load.sh.tpl @@ -14,12 +14,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This is a generated files that loads all docker layer built by "docker_build". +# This is a generated file that loads all docker layers built by "docker_build". RUNFILES="${PYTHON_RUNFILES:-${BASH_SOURCE[0]}.runfiles}" DOCKER="${DOCKER:-docker}" +FULL_DOCKER_VERSION=$(docker version -f {{.Server.Version}} 2> /dev/null \ + || echo "1.10.0") +DOCKER_MAJOR_VERSION=$(echo "$FULL_DOCKER_VERSION" | sed -r 's#^([0-9]+)\..*#\1#') +DOCKER_MINOR_VERSION=$(echo "$FULL_DOCKER_VERSION" | sed -r 's#^[0-9]+\.([0-9]+).*#\1#') +if [ "$DOCKER_MAJOR_VERSION" -eq "1" ] && [ "$DOCKER_MINOR_VERSION" -lt "10" ]; then + LEGACY_DOCKER=true +else + LEGACY_DOCKER=false +fi + # List all images identifier (only the identifier) from the local # docker registry. IMAGES="$("${DOCKER}" images -aq)" @@ -30,12 +40,17 @@ IMAGE_LEN=$(for i in $IMAGES; do echo -n $i | wc -c; done | sort -g | head -1 | function incr_load() { # Load a layer if and only if the layer is not in "$IMAGES", that is # in the local docker registry. - name=$(cat ${RUNFILES}/$1) + if [ "$LEGACY_DOCKER" = true ]; then + name=$(cat ${RUNFILES}/$1) + else + name=$(cat ${RUNFILES}/$2) + fi + if (echo "$IMAGES" | grep -q ^${name:0:$IMAGE_LEN}$); then echo "Skipping $name, already loaded." else echo "Loading $name..." - "${DOCKER}" load -i ${RUNFILES}/$2 + "${DOCKER}" load -i ${RUNFILES}/$3 fi } @@ -47,5 +62,9 @@ function incr_load() { if [ -n "${name}" ]; then TAG="${1:-%{repository}:%{tag}}" echo "Tagging ${name} as ${TAG}" - "${DOCKER}" tag -f ${name} ${TAG} + if [ "$LEGACY_DOCKER" = true ]; then + "${DOCKER}" tag -f ${name} ${TAG} + else + "${DOCKER}" tag ${name} ${TAG} + fi fi |