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: 72273 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp550822qga; Tue, 19 Jul 2016 01:27:25 -0700 (PDT) X-Received: by 10.55.150.195 with SMTP id y186mr48119370qkd.7.1468916845512; Tue, 19 Jul 2016 01:27:25 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 37si10846651qty.156.2016.07.19.01.27.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 19 Jul 2016 01:27:25 -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]:53708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPQNB-0007Ng-5U for patch@linaro.org; Tue, 19 Jul 2016 04:27:25 -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+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: 1468335639-24582-6-git-send-email-alex.bennee@linaro.org --- 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 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"