From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPW3e-0006pj-DK for qemu-devel@nongnu.org; Tue, 19 Jul 2016 10:31:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPW3Y-0002Pr-6x for qemu-devel@nongnu.org; Tue, 19 Jul 2016 10:31:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43959) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPW3X-0002Pe-V6 for qemu-devel@nongnu.org; Tue, 19 Jul 2016 10:31:32 -0400 From: Fam Zheng Date: Tue, 19 Jul 2016 22:31:12 +0800 Message-Id: <1468938677-15607-6-git-send-email-famz@redhat.com> In-Reply-To: <1468938677-15607-1-git-send-email-famz@redhat.com> References: <1468938677-15607-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] [PULL 05/10] tests/docker/docker.py: add update operation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, famz@redhat.com From: Alex Benn=C3=A9e This adds a new operation to the docker script to allow updating of binaries in an existing container. This is because it would be inefficient to re-build the whole container just for an update to the QEMU binary. To update the executable run: ./tests/docker/docker.py update \ debian:armhf ./arm-linux-user/qemu-arm Signed-off-by: Alex Benn=C3=A9e Message-id: 1468934445-32183-6-git-send-email-famz@redhat.com Signed-off-by: Fam Zheng --- tests/docker/docker.py | 59 ++++++++++++++++++++++++++++++++++++++++++++= +++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/tests/docker/docker.py b/tests/docker/docker.py index 76750c4..40bda9d 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -21,6 +21,8 @@ import uuid import argparse import tempfile import re +from tarfile import TarFile, TarInfo +from StringIO import StringIO from shutil import copy, rmtree =20 def _text_checksum(text): @@ -94,9 +96,11 @@ class Docker(object): self._instances =3D [] atexit.register(self._kill_instances) =20 - def _do(self, cmd, quiet=3DTrue, **kwargs): + def _do(self, cmd, quiet=3DTrue, infile=3DNone, **kwargs): if quiet: kwargs["stdout"] =3D subprocess.PIPE + if infile: + kwargs["stdin"] =3D infile return subprocess.call(self._command + cmd, **kwargs) =20 def _do_kill_instances(self, only_known, only_active=3DTrue): @@ -152,6 +156,11 @@ class Docker(object): [docker_dir], quiet=3Dquiet) =20 + def update_image(self, tag, tarball, quiet=3DTrue): + "Update a tagged image using " + + self._do(["build", "-t", tag, "-"], quiet=3Dquiet, infile=3Dtarb= all) + def image_matches_dockerfile(self, tag, dockerfile): try: checksum =3D self.get_image_dockerfile_checksum(tag) @@ -245,6 +254,54 @@ class BuildCommand(SubCommand): =20 return 0 =20 +class UpdateCommand(SubCommand): + """ Update a docker image with new executables. Arguments: """ + name =3D "update" + def args(self, parser): + parser.add_argument("tag", + help=3D"Image Tag") + parser.add_argument("executable", + help=3D"Executable to copy") + + def run(self, args, argv): + # Create a temporary tarball with our whole build context and + # dockerfile for the update + tmp =3D tempfile.NamedTemporaryFile(suffix=3D"dckr.tar.gz") + tmp_tar =3D TarFile(fileobj=3Dtmp, mode=3D'w') + + # Add the executable to the tarball + bn =3D os.path.basename(args.executable) + ff =3D "/usr/bin/%s" % bn + tmp_tar.add(args.executable, arcname=3Dff) + + # Add any associated libraries + libs =3D _get_so_libs(args.executable) + if libs: + for l in libs: + tmp_tar.add(os.path.realpath(l), arcname=3Dl) + + # Create a Docker buildfile + df =3D StringIO() + df.write("FROM %s\n" % args.tag) + df.write("ADD . /\n") + df.seek(0) + + df_tar =3D TarInfo(name=3D"Dockerfile") + df_tar.size =3D len(df.buf) + tmp_tar.addfile(df_tar, fileobj=3Ddf) + + tmp_tar.close() + + # reset the file pointers + tmp.flush() + tmp.seek(0) + + # Run the build with our tarball context + dkr =3D Docker() + dkr.update_image(args.tag, tmp, quiet=3Dargs.quiet) + + return 0 + class CleanCommand(SubCommand): """Clean up docker instances""" name =3D "clean" --=20 2.7.4