From patchwork Tue Jun 28 15:42:40 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: 641606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rf9T95GXZz9s5J for ; Wed, 29 Jun 2016 01:58:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=J9slZVEZ; dkim-atps=neutral Received: from localhost ([::1]:37762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHvPH-0000yz-Ka for incoming@patchwork.ozlabs.org; Tue, 28 Jun 2016 11:58:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHvA9-0008Bg-AE for qemu-devel@nongnu.org; Tue, 28 Jun 2016 11:42:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHvA4-0002Tb-LK for qemu-devel@nongnu.org; Tue, 28 Jun 2016 11:42:57 -0400 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]:36149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHvA4-0002TL-Ez for qemu-devel@nongnu.org; Tue, 28 Jun 2016 11:42:52 -0400 Received: by mail-wm0-x229.google.com with SMTP id f126so145700786wma.1 for ; Tue, 28 Jun 2016 08:42:52 -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=5IU6EvFZH3+hoiQMXNWiosa2pF5SdOlz4P4str8RTZQ=; b=J9slZVEZQGpb/5mjMC0NVXWYdoOgOTNT2KUDtkcFOjE2vLe9tEBJFCYBGKk/P61Y4o MqJ762k+bnNYxDTnG3RWB2yO98Xb7RGlAbbnwHP7hSLj4edYVAEfmPtBzokI8eVr0iGZ aeupEiRFBTWYFo4PFAUgcNkQwTWNcq57J5s0A= 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=5IU6EvFZH3+hoiQMXNWiosa2pF5SdOlz4P4str8RTZQ=; b=R0R6gX/y27qkveXJaONAxapGFVubwV1WwWzFKFG7KeLcRfJnjWstUHOSSy/5qeNmtc Y6NTo1cBMcQJ5appD3v9IDZYZKE6/fGWJ+wJoklH4CD7yJclVApSBjzRJAiUa41GFhaL mvE+Z2xb+ehsagyS1RcVUCdWQN1L9PUONzsUmvrBlC3ojqjK5EO4CZY/AzDKMq8D8z66 Slo/lCc66dwLHAMXYGlfi1kHBRUUUJ3xXkdc4RUh/4xh7GWwAVjTQmE941K4qDqcBTmc ONWxv0umUzSeOQJwPMp31/z/FkGHEu2uTVP4VNwzT+lId0CcHW2wKjn6DHUy3icO/omc FkGg== X-Gm-Message-State: ALyK8tIceLiXbznrhSLxQ5oxkd+ye955YRwygZZNNmPR4SbVCvZp+NviEShmyXXdcA+dX30J X-Received: by 10.28.30.23 with SMTP id e23mr5331091wme.66.1467128570841; Tue, 28 Jun 2016 08:42:50 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j4sm1206805wjg.20.2016.06.28.08.42.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jun 2016 08:42:48 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id EC50A3E04BB; Tue, 28 Jun 2016 16:42:53 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 28 Jun 2016 16:42:40 +0100 Message-Id: <1467128564-13476-2-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467128564-13476-1-git-send-email-alex.bennee@linaro.org> References: <1467128564-13476-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::229 Subject: [Qemu-devel] [PATCH v3 1/5] 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+incoming=patchwork.ozlabs.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 Reviewed-by: Fam Zheng --- v2 - new for v2 v3 - add r-b tag --- 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):