From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBz3r-0000vg-NY for qemu-devel@nongnu.org; Sun, 12 Jun 2016 02:39:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bBz3n-0002vm-IP for qemu-devel@nongnu.org; Sun, 12 Jun 2016 02:39:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBz3n-0002vR-9p for qemu-devel@nongnu.org; Sun, 12 Jun 2016 02:39:51 -0400 Date: Sun, 12 Jun 2016 14:39:42 +0800 From: Fam Zheng Message-ID: <20160612063942.GL27167@ad.usersys.redhat.com> References: <1465403752-30348-1-git-send-email-alex.bennee@linaro.org> <1465403752-30348-2-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1465403752-30348-2-git-send-email-alex.bennee@linaro.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [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: Alex =?iso-8859-1?Q?Benn=E9e?= Cc: qemu-devel@nongnu.org, riku.voipio@linaro.org On Wed, 06/08 17:35, Alex Benn=E9e wrote: > 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. >=20 > We also ensure we remove the build context after we are done (mkdtemp > doesn't do this automatically for you). >=20 > Signed-off-by: Alex Benn=E9e >=20 > --- > v2 > - new for v2 > --- > tests/docker/docker.py | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) >=20 > 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= =3DNone): > + def build_image(self, tag, docker_dir, dockerfile, quiet=3DTrue, a= rgv=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, suffi= x=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) Maybe we could use a "finally" here to make sure docker_dir is always rem= oved, but that is not a duty of this patch. Reviewed-by: Fam Zheng > =20 > - dkr.build_image(tag, dockerfile, args.dockerfile, > - quiet=3Dargs.quiet, argv=3Dargv) > return 0 > =20 > class CleanCommand(SubCommand): > --=20 > 2.7.4 >=20