From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v6 1/8] 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 From: Alex Benn=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=C3=A9e 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(-) 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 =20 def _text_checksum(text): """Calculate a digest string unique to the text content""" @@ -87,20 +87,20 @@ class Docker(object): labels =3D json.loads(resp)[0]["Config"].get("Labels", {}) return labels.get("com.qemu.dockerfile-checksum", "") =20 - def build_image(self, tag, dockerfile, df_path, quiet=3DTrue, argv=3D= None): + def build_image(self, tag, docker_dir, dockerfile, quiet=3DTrue, arg= v=3DNone): if argv =3D=3D None: argv =3D [] - tmp_dir =3D tempfile.mkdtemp(prefix=3D"docker_build") =20 - tmp_df =3D tempfile.NamedTemporaryFile(dir=3Dtmp_dir, suffix=3D"= .docker") + tmp_df =3D tempfile.NamedTemporaryFile(dir=3Ddocker_dir, suffix=3D= ".docker") tmp_df.write(dockerfile) =20 tmp_df.write("\n") tmp_df.write("LABEL com.qemu.dockerfile-checksum=3D%s" % _text_checksum(dockerfile)) tmp_df.flush() + self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \ - [tmp_dir], + [docker_dir], quiet=3Dquiet) =20 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 =3D tempfile.mkdtemp(prefix=3D"docker_build") + + dkr.build_image(tag, docker_dir, dockerfile, + quiet=3Dargs.quiet, argv=3Dargv) + + rmtree(docker_dir) =20 - dkr.build_image(tag, dockerfile, args.dockerfile, - quiet=3Dargs.quiet, argv=3Dargv) return 0 =20 class CleanCommand(SubCommand): --=20 2.7.4