From patchwork Wed Jun 8 16:35:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 69674 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2589332qgf; Wed, 8 Jun 2016 09:37:44 -0700 (PDT) X-Received: by 10.55.217.24 with SMTP id u24mr5266653qki.93.1465403863826; Wed, 08 Jun 2016 09:37:43 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 102si1118794qkt.150.2016.06.08.09.37.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 08 Jun 2016 09:37:43 -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; dkim=fail header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAgUB-0003Kh-CA for patch@linaro.org; Wed, 08 Jun 2016 12:37:43 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UpEVJG0SdRO1/V0LUPZhtV4J/JxesH00O9xPdPzXLI8=; b=HIXYOz7rxVrFRvhNXjSE9jLACo92XThaXlWHtjlW/jADEN6p0Uzql9PXfLTAWEK3SX /D76pJKMiHXVj7ytAX4J/Bph8NoVWgcrIA+/ZuOFafC7cxEoWwgHgMcjv9KW5gfI+q18 iBQsJktTjr95IYsgyp+M28wvQmtm6lAq40JF8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UpEVJG0SdRO1/V0LUPZhtV4J/JxesH00O9xPdPzXLI8=; b=CEwlej31y8T/T+vqsMA0QUI0ai46KMpe3V8bSNEacf97wgWnrBqnaUb0Mzili1NtRX Yx6pCjxiVZGYJhBgM+JS3UVKM4L06okIHhrPPnr428cOgPP5EjBanGDEthGx+O8MUaiU CB9EKJ7aeO4zRWrc9BxCAmRMS5klk9g/8c5CXa4mJG2X5nriysr5EI1Rv2/B7mM/RUNY pEKo25yq1cesw9GUqBRiCD1I8PDYxqTfGTppxgS58zvmWT1pnlA8p0EkcHbVCw81iTjz DImnPyADuxf1dXbSglUGBYWNh8eTRsmiB8D8iY8LWfOHRW0AdOBph8lkJqRcXQrFQcXs 0rXg== X-Gm-Message-State: ALyK8tLDuAI6d+tplw5YszQ5j6YJEdUMQBl8YXXDFzhLf+7TJ11vqNr7Xq562OwEeEqAEkZc X-Received: by 10.194.110.234 with SMTP id id10mr5472542wjb.30.1465403740297; Wed, 08 Jun 2016 09:35:40 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p9sm2362806wjv.21.2016.06.08.09.35.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jun 2016 09:35:37 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A7B6C3E0358; Wed, 8 Jun 2016 17:35:55 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 8 Jun 2016 17:35:50 +0100 Message-Id: <1465403752-30348-2-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 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 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::234 Subject: [Qemu-devel] [PATCH v2 1/3] 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: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , riku.voipio@linaro.org, famz@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 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):