From patchwork Wed Jun 8 16:35:51 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: 69676 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2589381qgf; Wed, 8 Jun 2016 09:37:50 -0700 (PDT) X-Received: by 10.141.23.6 with SMTP id z6mr5701930qhd.52.1465403870710; Wed, 08 Jun 2016 09:37:50 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id y67si1128256qhc.47.2016.06.08.09.37.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 08 Jun 2016 09:37:50 -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]:58375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAgUI-0003Pn-3g for patch@linaro.org; Wed, 08 Jun 2016 12:37:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAgSK-0002Yf-S9 for qemu-devel@nongnu.org; Wed, 08 Jun 2016 12:35:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAgSE-0005yo-QA for qemu-devel@nongnu.org; Wed, 08 Jun 2016 12:35:47 -0400 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:37515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAgSE-0005yi-9q for qemu-devel@nongnu.org; Wed, 08 Jun 2016 12:35:42 -0400 Received: by mail-wm0-x22a.google.com with SMTP id k204so25044864wmk.0 for ; Wed, 08 Jun 2016 09:35:42 -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=Ft1s+4cGA6n7O/AVAeO+Ot7q4C3/5BkJfYws/f+e8os=; b=BRNGqYrR/V/pdnOLULwYrqbU4CVijq5E/alC1EM8azcFSWp8c1E2RK89WkmX/8AMx7 Xh+2pT8SbC9U4uvYDKd6T+A7Gb3Hofrc7/mGse8D1YGVWhEi+2qkO595bKGhuU9uaaKh vtEFNv4ylZ4ZQUbpzHFzFxLag0Dihy0JFitQo= 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=Ft1s+4cGA6n7O/AVAeO+Ot7q4C3/5BkJfYws/f+e8os=; b=aH0x8FHbVEVsV3BuK7B7eGer5L972Kzpabz6ZSQ0rNSLv8TKY9wkCJebEsFF7N7QIE XqEdPr4rlyBeVC7u2zwHHCPYqi53cqdxEvYrIdwTtvDXQ1WwePYmZfTJTJvjf16Exr91 PbqSWNaUglTEKdycmISS1H6UUId6a0Kuu2c5MENOZ/uJrKg8mF5cve9WEMsgvKydPkQ0 ubFsYwB/odeQk8NV1ICLMDKoHOG9QyczqqzxtBiu7B0X0V8NrWoxkfhGUev76ZdAuuSN tY0l3aHQtiZL5tv6xP6o5uIg2tc5ycKvEgqgVIQR/+wsSWATIJlvodmxoaryuVOIJAhf 7LXQ== X-Gm-Message-State: ALyK8tL3BhTJ1ShN7g73GvR6QOeYpDjZcWrEZqlN8cVXZBCpVfWBMAtvueuM5xV6oAXQUJ9x X-Received: by 10.28.157.71 with SMTP id g68mr5879387wme.29.1465403741530; Wed, 08 Jun 2016 09:35:41 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id q194sm25738006wme.18.2016.06.08.09.35.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jun 2016 09:35:37 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id B7C173E0407; Wed, 8 Jun 2016 17:35:55 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 8 Jun 2016 17:35:51 +0100 Message-Id: <1465403752-30348-3-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465403752-30348-1-git-send-email-alex.bennee@linaro.org> References: <1465403752-30348-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::22a Subject: [Qemu-devel] [PATCH v2 2/3] tests/docker/docker.py: support --include-executable 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" When passed the path to a binary we copy it and any linked libraries into the docker build context. These can then be included by a dockerfile with the line: # Copy all of context into container ADD . / This is mainly intended for setting up foreign architecture docker images which use qemu-$arch to do cross-architecture linux-user execution. It also relies on the host and guest file-system following reasonable multi-arch layouts so the copied libraries don't clash with the guest ones. Signed-off-by: Alex Bennée --- v2 - change name of option - require full path to executable - clean-up the copy code --- tests/docker/docker.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) -- 2.7.4 diff --git a/tests/docker/docker.py b/tests/docker/docker.py index ae40bb3..ed6fa45 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -20,6 +20,7 @@ import atexit import uuid import argparse import tempfile +import re from shutil import copy, rmtree def _text_checksum(text): @@ -38,6 +39,38 @@ def _guess_docker_command(): raise Exception("Cannot find working docker command. Tried:\n%s" % \ commands_txt) +def _copy_with_mkdir(src, root_dir, sub_path): + """Copy src into root_dir, creating sub_path as needed.""" + dest_dir = os.path.normpath("%s/%s" % (root_dir, sub_path)) + try: + os.makedirs(dest_dir) + except OSError: + print "%s already created" % (dest_dir) + + dest_file = "%s/%s" % (dest_dir, os.path.basename(src)) + copy(src, dest_file) + + +def _copy_binary_with_libs(src, dest_dir): + """Copy a binary executable and all its dependant libraries. + + This does rely on the host file-system being fairly multi-arch + aware so the file don't clash with the guests layout.""" + + _copy_with_mkdir(src, dest_dir, "/usr/bin") + + # do ldd bit here + ldd_re = re.compile(r"(/.*/)(\S*)") + ldd_output = subprocess.check_output(["ldd", src]) + for line in ldd_output.split("\n"): + search = ldd_re.search(line) + if search and len(search.groups()) == 2: + so_path = search.groups()[0] + so_lib = search.groups()[1] + _copy_with_mkdir("%s/%s" % (so_path, so_lib), + dest_dir, so_path) + + class Docker(object): """ Running Docker commands """ def __init__(self): @@ -151,6 +184,10 @@ class BuildCommand(SubCommand): """ Build docker image out of a dockerfile. Arguments: """ name = "build" def args(self, parser): + parser.add_argument("--include-executable", "-e", + help="""Specify a binary that will be copied to the + container together with all its dependent + libraries""") parser.add_argument("tag", help="Image Tag") parser.add_argument("dockerfile", @@ -168,6 +205,11 @@ class BuildCommand(SubCommand): # Create a docker context directory for the build docker_dir = tempfile.mkdtemp(prefix="docker_build") + # Do we include a extra binary? + if args.include_executable: + _copy_binary_with_libs(args.include_executable, + docker_dir) + dkr.build_image(tag, docker_dir, dockerfile, quiet=args.quiet, argv=argv)