From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHvA8-00089r-L2 for qemu-devel@nongnu.org; Tue, 28 Jun 2016 11:42:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHvA6-0002UK-MA for qemu-devel@nongnu.org; Tue, 28 Jun 2016 11:42:55 -0400 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:38589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHvA6-0002UC-C9 for qemu-devel@nongnu.org; Tue, 28 Jun 2016 11:42:54 -0400 Received: by mail-wm0-x22e.google.com with SMTP id r201so33914016wme.1 for ; Tue, 28 Jun 2016 08:42:54 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Tue, 28 Jun 2016 16:42:44 +0100 Message-Id: <1467128564-13476-6-git-send-email-alex.bennee@linaro.org> 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v3 5/5] 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: famz@redhat.com, riku.voipio@linaro.org, =?UTF-8?q?Alex=20Benn=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ée --- v3 - new in v3 --- 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 244901d..a8753f8 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 def _text_checksum(text): @@ -94,9 +96,11 @@ class Docker(object): self._instances = [] atexit.register(self._kill_instances) - def _do(self, cmd, quiet=True, **kwargs): + def _do(self, cmd, quiet=True, infile=None, **kwargs): if quiet: kwargs["stdout"] = subprocess.PIPE + if infile: + kwargs["stdin"] = infile return subprocess.call(self._command + cmd, **kwargs) def _do_kill_instances(self, only_known, only_active=True): @@ -152,6 +156,11 @@ class Docker(object): [docker_dir], quiet=quiet) + def update_image(self, tag, tarball, quiet=True): + "Update a tagged image using " + + self._do(["build", "-t", tag, "-"], quiet=quiet, infile=tarball) + def image_matches_dockerfile(self, tag, dockerfile): try: checksum = self.get_image_dockerfile_checksum(tag) @@ -239,6 +248,54 @@ class BuildCommand(SubCommand): return 0 +class UpdateCommand(SubCommand): + """ Update a docker image with new executables. Arguments: """ + name = "update" + def args(self, parser): + parser.add_argument("tag", + help="Image Tag") + parser.add_argument("executable", + help="Executable to copy") + + def run(self, args, argv): + # Create a temporary tarball with our whole build context and + # dockerfile for the update + tmp = tempfile.NamedTemporaryFile(suffix="dckr.tar.gz") + tmp_tar = TarFile(fileobj=tmp, mode='w') + + # Add the executable to the tarball + bn = os.path.basename(args.executable) + ff = "/usr/bin/%s" % bn + tmp_tar.add(args.executable, arcname=ff) + + # Add any associated libraries + libs = _get_so_libs(args.executable) + if libs: + for l in libs: + tmp_tar.add(os.path.realpath(l), arcname=l) + + # Create a Docker buildfile + df = StringIO() + df.write("FROM %s\n" % args.tag) + df.write("ADD . /\n") + df.seek(0) + + df_tar = TarInfo(name="Dockerfile") + df_tar.size = len(df.buf) + tmp_tar.addfile(df_tar, fileobj=df) + + tmp_tar.close() + + # reset the file pointers + tmp.flush() + tmp.seek(0) + + # Run the build with our tarball context + dkr = Docker() + dkr.update_image(args.tag, tmp, quiet=args.quiet) + + return 0 + class CleanCommand(SubCommand): """Clean up docker instances""" name = "clean" -- 2.7.4