From patchwork Tue Jul 19 13:20:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 9237383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 12520602F0 for ; Tue, 19 Jul 2016 13:31:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 021C726D19 for ; Tue, 19 Jul 2016 13:31:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB0A926E81; Tue, 19 Jul 2016 13:31:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8925326D19 for ; Tue, 19 Jul 2016 13:31:26 +0000 (UTC) Received: from localhost ([::1]:55984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPV7N-0007Hb-Ci for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 09:31:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPUxM-0001xH-Um for qemu-devel@nongnu.org; Tue, 19 Jul 2016 09:21:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPUxI-0001gS-Be for qemu-devel@nongnu.org; Tue, 19 Jul 2016 09:21:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPUxI-0001gE-2v for qemu-devel@nongnu.org; Tue, 19 Jul 2016 09:21:00 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 B5B7860C8; Tue, 19 Jul 2016 13:20:59 +0000 (UTC) Received: from ad.usersys.redhat.com (dhcp-14-122.nay.redhat.com [10.66.14.122]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6JDKoXF023275; Tue, 19 Jul 2016 09:20:58 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 21:20:40 +0800 Message-Id: <1468934445-32183-6-git-send-email-famz@redhat.com> In-Reply-To: <1468934445-32183-1-git-send-email-famz@redhat.com> References: <1468934445-32183-1-git-send-email-famz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 19 Jul 2016 13:20:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 05/10] tests/docker/docker.py: add update operation 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: famz@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alex Bennée 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 --- 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 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) @@ -245,6 +254,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"