From fcd56bc28981f4f8292894ac7d43805ebe01646c Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Mon, 12 Jun 2017 11:38:23 -0700 Subject: [PATCH] Update image local build script (#14599) * Use the full image name for local image build FROM When we are writing the `FROM` statement for the local image build Dockerfile, we need to use the fully qualified name of the image we are building on top of. Signed-off-by: Steve Kuznetsov * Ensure local image tmp dirs are cleaned up on error When the script fails to build an image, we need to ensure that the temp directory we created for context is cleaned up anyway. Trapping the functionality on exit is the appropriate way to acheive this. Signed-off-by: Steve Kuznetsov * Removed extraneous comma from local build debugging output Signed-off-by: Steve Kuznetsov --- hack/build-local-images.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hack/build-local-images.py b/hack/build-local-images.py index 6b419ca02535..4c3f2b0b7c78 100755 --- a/hack/build-local-images.py +++ b/hack/build-local-images.py @@ -5,6 +5,7 @@ from subprocess import call from tempfile import mkdtemp +from atexit import register from os import getenv, mkdir, remove from os.path import abspath, dirname, exists, join @@ -105,7 +106,7 @@ def add_to_context(context_dir, source, destination, container_destination): to place it in the container file- sytem at the correct destination. """ - debug("Adding file:\n\tfrom {}\n\tto {},\n\tincluding in container at {}".format( + debug("Adding file:\n\tfrom {}\n\tto {}\n\tincluding in container at {}".format( source, join(context_dir, destination), container_destination) @@ -127,6 +128,8 @@ def debug(message): os_image_path = join(os_root, "images") context_dir = mkdtemp() +register(rmtree, context_dir) + debug("Created temporary context dir at {}".format(context_dir)) mkdir(join(context_dir, "bin")) mkdir(join(context_dir, "src")) @@ -137,7 +140,7 @@ def debug(message): print "[INFO] Building {}...".format(image) with open(join(context_dir, "Dockerfile"), "w+") as dockerfile: - dockerfile.write("FROM {}\n".format(image)) + dockerfile.write("FROM {}\n".format(full_name(image))) config = image_config[image] for binary in config.get("binaries", []): @@ -148,6 +151,7 @@ def debug(message): container_destination=config["binaries"][binary] ) + mkdir(join(context_dir, "src", image)) for file in config.get("files", []): add_to_context( context_dir, @@ -161,5 +165,3 @@ def debug(message): remove(join(context_dir, "Dockerfile")) rmtree(join(context_dir, "src", image)) - -rmtree(context_dir)