From patchwork Tue Jul 12 15:00:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 71860 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp524445qga; Tue, 12 Jul 2016 08:06:45 -0700 (PDT) X-Received: by 10.129.121.7 with SMTP id u7mr1979228ywc.237.1468336004883; Tue, 12 Jul 2016 08:06:44 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id i6si164092qkd.111.2016.07.12.08.06.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Jul 2016 08:06:44 -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; dkim=fail header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMzGm-0007FB-Ct for patch@linaro.org; Tue, 12 Jul 2016 11:06:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMzB9-0008KX-Bd for qemu-devel@nongnu.org; Tue, 12 Jul 2016 11:00:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMzB7-0007ln-9W for qemu-devel@nongnu.org; Tue, 12 Jul 2016 11:00:54 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:38783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMzB7-0007lf-0R for qemu-devel@nongnu.org; Tue, 12 Jul 2016 11:00:53 -0400 Received: by mail-wm0-x234.google.com with SMTP id o80so29045010wme.1 for ; Tue, 12 Jul 2016 08:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tE98T/eX4Zr6rwkgeL0S+XuZsUywZBaXoHrWxRUK1jE=; b=ktjUhlAggTiHvx7rbcn+RBprFEn+PPPCAg+AFPjAZHDf4QB6opWLp1trrQb3XBe/qF YOvWoGj/IItoj8JSWwAF92C229F+wuJVBGdWzvYQg8g4gNRci2KyObpDj6PD9Xd6MxlU hhF0sZdWJceoIpjuB+durZmDRWLwlsGL4Pvo8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tE98T/eX4Zr6rwkgeL0S+XuZsUywZBaXoHrWxRUK1jE=; b=VBsvci+/j4CVcFlrGi6XDOxfO8YcoilPyHKtcXbG7pIT9v2t3cLxXRTCuEYPLO7ppy ZBqcOTa9ja/Nb14S8pYsCCCfzxoxcYbH7qlOfKU2DsXA0QqdaY3NbWynkoSIcoAt2nmU 8sOLnyaAJtMlXVeUuhpRCY9HwHmIPB/05qODhkAQxW8lNH4Lx/3n6HRPcwQ9Ky/fdxtK 9nsOFDZFAedTqUmHMq4456s4Drj44R+Pv+GIaAyNIivP3zQk7SCfqeVeuJvumyXpnuBP MOq52Ctvjl1P3mt29EQLwM1BgIoPAAe+hbeZ18a57XgsZCS0jB8qwFtYI3420VJFIsWT XWkA== X-Gm-Message-State: ALyK8tJMS+eSS4iumIUzjvtaqfjhV7Lp6BjlJQxn8a+eDhSaARSRLtRW9UHkv0eVzC+vcwKI X-Received: by 10.28.169.82 with SMTP id s79mr20126933wme.87.1468335652236; Tue, 12 Jul 2016 08:00:52 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f4sm6813645wmf.8.2016.07.12.08.00.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2016 08:00:48 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 45AD33E042E; Tue, 12 Jul 2016 16:00:49 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 12 Jul 2016 16:00:37 +0100 Message-Id: <1468335639-24582-6-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468335639-24582-1-git-send-email-alex.bennee@linaro.org> References: <1468335639-24582-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::234 Subject: [Qemu-devel] [PATCH v5 5/7] 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , riku.voipio@linaro.org, famz@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.7.4 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"