From patchwork Tue Jun 28 15:42:44 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: 71099 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1665278qgy; Tue, 28 Jun 2016 08:55:14 -0700 (PDT) X-Received: by 10.200.39.66 with SMTP id h2mr2868709qth.7.1467129314596; Tue, 28 Jun 2016 08:55:14 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t36si4430565qtb.55.2016.06.28.08.55.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Jun 2016 08:55:14 -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]:37741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHvM1-0004o2-Pe for patch@linaro.org; Tue, 28 Jun 2016 11:55:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHvA8-00089r-L2 for qemu-devel@nongnu.org; Tue, 28 Jun 2016 11:42:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHvA6-0002UK-MA for qemu-devel@nongnu.org; Tue, 28 Jun 2016 11:42:55 -0400 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:38589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHvA6-0002UC-C9 for qemu-devel@nongnu.org; Tue, 28 Jun 2016 11:42:54 -0400 Received: by mail-wm0-x22e.google.com with SMTP id r201so33914016wme.1 for ; Tue, 28 Jun 2016 08:42:54 -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=gN6cso0K3LcHSPjg7dvqCLO1WmOnzmkZp9VjVj0tHGkpUeW63Cnau+YQOtcxp5CcAy i+Y/8ufQd+S54EDxrQYfQqdx/344xee6A/RQCYGW51xLXqqHUhCVMn+5odhTtipVeNBG 82LLJwk6KEHMKZRHlS7isKGJ1WymTHhc2QnQM= 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=cTBx7IF7hUxHZS/MY1e0PJbdQFoAsSvvRy/ykFaIjCglC+m9aQt5zadARso+etqU/s tJTg7GvNmgeYlhMlaU3TSDXbsj0cf8MAryFTUajXJv2H+KsXFu2rYRw+80ovpYcdhQ1U xUiLs4On/y+WLY2gO2hDxGvaSiAV3XL9c8VjgL09/QJieoqscrVi0I+wcyKQwQ1v1+1E lZbWA7hjiv2z8b9b+7z+gjFDOvaDkVo39b71nqnX2dAJy4u1i72ASMjLeb9Kfjh2bU48 JXDP/JL+PBFzn2e0ItdzxH/OZV+8LK85unyUeH6FvIwY6P6TYKPvkm8u+ay8oV1r+s03 obFQ== X-Gm-Message-State: ALyK8tLriPm6dmpLodFJRRjFwdQlw4JaUrWm0nq5IjaQOYAJ5P3v+XMXGM1l0edwQMhAsR7b X-Received: by 10.28.136.195 with SMTP id k186mr16642947wmd.13.1467128573616; Tue, 28 Jun 2016 08:42:53 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id c142sm9665578wme.18.2016.06.28.08.42.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jun 2016 08:42:52 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 593F23E0516; Tue, 28 Jun 2016 16:42:54 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 28 Jun 2016 16:42:44 +0100 Message-Id: <1467128564-13476-6-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467128564-13476-1-git-send-email-alex.bennee@linaro.org> References: <1467128564-13476-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::22e Subject: [Qemu-devel] [PATCH v3 5/5] 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"