From patchwork Tue Jul 19 14:31:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 72330 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp114289qga; Tue, 19 Jul 2016 07:35:22 -0700 (PDT) X-Received: by 10.55.120.7 with SMTP id t7mr54002558qkc.131.1468938922892; Tue, 19 Jul 2016 07:35:22 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z24si19760526qtb.68.2016.07.19.07.35.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 19 Jul 2016 07:35:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:56436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPW7G-0002Tf-F7 for patch@linaro.org; Tue, 19 Jul 2016 10:35:22 -0400 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 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 7FA94796F3; Tue, 19 Jul 2016 14:31:31 +0000 (UTC) Received: from ad.usersys.redhat.com (dhcp-14-122.nay.redhat.com [10.66.14.122]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6JEVLVi004350; Tue, 19 Jul 2016 10:31:30 -0400 From: Fam Zheng To: qemu-devel@nongnu.org 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 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 19 Jul 2016 14:31:31 +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] [PULL 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: peter.maydell@linaro.org, famz@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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: 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(-) -- 2.7.4 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"