From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAgSK-0002Yb-01 for qemu-devel@nongnu.org; Wed, 08 Jun 2016 12:35:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAgSD-0005yU-6W for qemu-devel@nongnu.org; Wed, 08 Jun 2016 12:35:45 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:38682) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAgSC-0005yI-Vg for qemu-devel@nongnu.org; Wed, 08 Jun 2016 12:35:41 -0400 Received: by mail-wm0-x234.google.com with SMTP id m124so25010095wme.1 for ; Wed, 08 Jun 2016 09:35:40 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Wed, 8 Jun 2016 17:35:50 +0100 Message-Id: <1465403752-30348-2-git-send-email-alex.bennee@linaro.org> In-Reply-To: <1465403752-30348-1-git-send-email-alex.bennee@linaro.org> References: <1465403752-30348-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v2 1/3] tests/docker/docker.py: docker_dir outside build List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: famz@redhat.com, riku.voipio@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Instead of letting the build_image create the temporary working dir we move the creation to the build command. This is preparation for the later patches where additional files can be added to the build context before the build step is run. We also ensure we remove the build context after we are done (mkdtemp doesn't do this automatically for you). Signed-off-by: Alex Bennée --- v2 - new for v2 --- tests/docker/docker.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/docker/docker.py b/tests/docker/docker.py index 0151362..ae40bb3 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -20,7 +20,7 @@ import atexit import uuid import argparse import tempfile -from shutil import copy +from shutil import copy, rmtree def _text_checksum(text): """Calculate a digest string unique to the text content""" @@ -87,20 +87,20 @@ class Docker(object): labels = json.loads(resp)[0]["Config"].get("Labels", {}) return labels.get("com.qemu.dockerfile-checksum", "") - def build_image(self, tag, dockerfile, df_path, quiet=True, argv=None): + def build_image(self, tag, docker_dir, dockerfile, quiet=True, argv=None): if argv == None: argv = [] - tmp_dir = tempfile.mkdtemp(prefix="docker_build") - tmp_df = tempfile.NamedTemporaryFile(dir=tmp_dir, suffix=".docker") + tmp_df = tempfile.NamedTemporaryFile(dir=docker_dir, suffix=".docker") tmp_df.write(dockerfile) tmp_df.write("\n") tmp_df.write("LABEL com.qemu.dockerfile-checksum=%s" % _text_checksum(dockerfile)) tmp_df.flush() + self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \ - [tmp_dir], + [docker_dir], quiet=quiet) def image_matches_dockerfile(self, tag, dockerfile): @@ -164,10 +164,15 @@ class BuildCommand(SubCommand): if dkr.image_matches_dockerfile(tag, dockerfile): if not args.quiet: print "Image is up to date." - return 0 + else: + # Create a docker context directory for the build + docker_dir = tempfile.mkdtemp(prefix="docker_build") + + dkr.build_image(tag, docker_dir, dockerfile, + quiet=args.quiet, argv=argv) + + rmtree(docker_dir) - dkr.build_image(tag, dockerfile, args.dockerfile, - quiet=args.quiet, argv=argv) return 0 class CleanCommand(SubCommand): -- 2.7.4