From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: famz@redhat.com, riku.voipio@linaro.org,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: [Qemu-devel] [PATCH v2 2/3] tests/docker/docker.py: support --include-executable
Date: Wed, 8 Jun 2016 17:35:51 +0100 [thread overview]
Message-ID: <1465403752-30348-3-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1465403752-30348-1-git-send-email-alex.bennee@linaro.org>
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 <alex.bennee@linaro.org>
---
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(+)
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: <tag> <dockerfile>"""
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)
--
2.7.4
next prev parent reply other threads:[~2016-06-08 16:35 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-08 16:35 [Qemu-devel] [PATCH v2 0/3] Support building qemu-user powered docker test images Alex Bennée
2016-06-08 16:35 ` [Qemu-devel] [PATCH v2 1/3] tests/docker/docker.py: docker_dir outside build Alex Bennée
2016-06-12 6:39 ` Fam Zheng
2016-06-08 16:35 ` Alex Bennée [this message]
2016-06-12 6:47 ` [Qemu-devel] [PATCH v2 2/3] tests/docker/docker.py: support --include-executable Fam Zheng
2016-06-13 9:24 ` Alex Bennée
2016-06-13 12:24 ` Riku Voipio
2016-06-08 16:35 ` [Qemu-devel] [PATCH v2 3/3] add debian-bootstrap.docker target (and pre script) Alex Bennée
2016-06-12 7:05 ` Fam Zheng
2016-06-13 9:23 ` Alex Bennée
2016-06-12 8:16 ` [Qemu-devel] [PATCH v2 0/3] Support building qemu-user powered docker test images Fam Zheng
2016-06-13 9:22 ` Alex Bennée
2016-06-13 11:11 ` Fam Zheng
2016-06-13 11:38 ` Riku Voipio
2016-06-13 12:30 ` Alex Bennée
2016-06-13 12:39 ` Riku Voipio
2016-06-13 14:19 ` Alex Bennée
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1465403752-30348-3-git-send-email-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=famz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).