aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/build_defs/docker/incremental_load.sh.tpl
diff options
context:
space:
mode:
Diffstat (limited to 'tools/build_defs/docker/incremental_load.sh.tpl')
-rw-r--r--tools/build_defs/docker/incremental_load.sh.tpl49
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/build_defs/docker/incremental_load.sh.tpl b/tools/build_defs/docker/incremental_load.sh.tpl
new file mode 100644
index 0000000000..7217fccd77
--- /dev/null
+++ b/tools/build_defs/docker/incremental_load.sh.tpl
@@ -0,0 +1,49 @@
+#!/bin/bash -eu
+#
+# Copyright 2015 The Bazel Authors. 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 is a generated files that load all docker layer built by "docker_build".
+
+RUNFILES=${BASH_SOURCE[0]}.runfiles
+
+# List all images identifier (only the identifier) from the local
+# docker registry.
+IMAGES="$(docker images -aq)"
+IMAGE_LEN=$(for i in $IMAGES; do echo -n $i | wc -c; done | sort -g | head -1 | xargs)
+
+[ -n "$IMAGE_LEN" ] || IMAGE_LEN=64
+
+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 (echo "$IMAGES" | grep -q ^${name:0:$IMAGE_LEN}$); then
+ echo "Skipping $name, already loaded."
+ else
+ echo "Loading $name..."
+ docker load -i ${RUNFILES}/$2
+ fi
+}
+
+# List of 'incr_load' statements for all layers.
+# This generated and injected by docker_build.
+%{load_statements}
+
+# Tag the last layer.
+if [ -n "${name}" ]; then
+ TAG="${1:-%{repository}:%{tag}}"
+ echo "Tagging ${name} as ${TAG}"
+ docker tag -f ${name} ${TAG}
+fi