From patchwork Tue Jul 19 08:16:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 9236365 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 5CF116075D for ; Tue, 19 Jul 2016 08:26:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49E8C205AF for ; Tue, 19 Jul 2016 08:26:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EB4A2094F; Tue, 19 Jul 2016 08:26:19 +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 8A300205AF for ; Tue, 19 Jul 2016 08:26:18 +0000 (UTC) Received: from localhost ([::1]:53700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQM5-0006kd-QU for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 04:26:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQD8-0002qn-0y for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:17:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPQD6-0007oO-O4 for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:17:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41262) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQD6-0007oG-Ft for qemu-devel@nongnu.org; Tue, 19 Jul 2016 04:17:00 -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 06A6F6333A for ; Tue, 19 Jul 2016 08:17:00 +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 u6J8Gqt5015076 for ; Tue, 19 Jul 2016 04:16:59 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 16:16:45 +0800 Message-Id: <1468916208-18668-6-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 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 19 Jul 2016 08:17:00 +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 v6 5/8] 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: , 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 Message-id: 1468335639-24582-6-git-send-email-alex.bennee@linaro.org --- 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 b61d934..fd162c0 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"