From patchwork Tue Jul 19 08:16:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 72269 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp548491qga; Tue, 19 Jul 2016 01:20:53 -0700 (PDT) X-Received: by 10.55.176.130 with SMTP id z124mr51783085qke.55.1468916453643; Tue, 19 Jul 2016 01:20:53 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m190si574536qkf.253.2016.07.19.01.20.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 19 Jul 2016 01:20:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:53652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQGr-00060T-4g for patch@linaro.org; Tue, 19 Jul 2016 04:20:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQD6-0002oD-1v for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:17:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPQD2-0007mk-2v for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:16:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54576) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQD1-0007mf-R2 for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:16:56 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7EA8C3B723 for ; Tue, 19 Jul 2016 08:16:55 +0000 (UTC) Received: from ad.usersys.redhat.com (dhcp-14-122.nay.redhat.com [10.66.14.122]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6J8Gqt1015076 for ; Tue, 19 Jul 2016 04:16:54 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 16:16:41 +0800 Message-Id: <1468916208-18668-2-git-send-email-famz@redhat.com> In-Reply-To: <1468916208-18668-1-git-send-email-famz@redhat.com> References: <1468916208-18668-1-git-send-email-famz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 19 Jul 2016 08:16:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 1/8] tests/docker/docker.py: docker_dir outside build X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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 Reviewed-by: Fam Zheng Message-id: 1468335639-24582-2-git-send-email-alex.bennee@linaro.org --- tests/docker/docker.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) -- 2.7.4 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):