From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBzBb-0003ZN-HU for qemu-devel@nongnu.org; Sun, 12 Jun 2016 02:47:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bBzBX-0003p0-Bd for qemu-devel@nongnu.org; Sun, 12 Jun 2016 02:47:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46525) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBzBX-0003oG-3j for qemu-devel@nongnu.org; Sun, 12 Jun 2016 02:47:51 -0400 Date: Sun, 12 Jun 2016 14:47:45 +0800 From: Fam Zheng Message-ID: <20160612064745.GM27167@ad.usersys.redhat.com> References: <1465403752-30348-1-git-send-email-alex.bennee@linaro.org> <1465403752-30348-3-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1465403752-30348-3-git-send-email-alex.bennee@linaro.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 2/3] tests/docker/docker.py: support --include-executable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex =?iso-8859-1?Q?Benn=E9e?= Cc: qemu-devel@nongnu.org, riku.voipio@linaro.org On Wed, 06/08 17:35, Alex Benn=E9e wrote: > 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: >=20 > # Copy all of context into container > ADD . / >=20 > 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. >=20 > Signed-off-by: Alex Benn=E9e >=20 > --- > 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(+) >=20 > 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 > =20 > def _text_checksum(text): > @@ -38,6 +39,38 @@ def _guess_docker_command(): > raise Exception("Cannot find working docker command. Tried:\n%s" %= \ > commands_txt) > =20 > +def _copy_with_mkdir(src, root_dir, sub_path): > + """Copy src into root_dir, creating sub_path as needed.""" > + dest_dir =3D os.path.normpath("%s/%s" % (root_dir, sub_path)) > + try: > + os.makedirs(dest_dir) > + except OSError: > + print "%s already created" % (dest_dir) Is this error necessary? If it doesn't hurt (i.e. multiple libraries are = copied into it), I think we can safely say "pass". Or, add "if not os.path.isdir(dest_dir):" above os.makedirs. > + > + dest_file =3D "%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 =3D re.compile(r"(/.*/)(\S*)") > + ldd_output =3D subprocess.check_output(["ldd", src]) > + for line in ldd_output.split("\n"): > + search =3D ldd_re.search(line) > + if search and len(search.groups()) =3D=3D 2: > + so_path =3D search.groups()[0] > + so_lib =3D 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 =3D "build" > def args(self, parser): > + parser.add_argument("--include-executable", "-e", > + help=3D"""Specify a binary that will be co= pied to the > + container together with all its dependent > + libraries""") > parser.add_argument("tag", > help=3D"Image Tag") > parser.add_argument("dockerfile", > @@ -168,6 +205,11 @@ class BuildCommand(SubCommand): > # Create a docker context directory for the build > docker_dir =3D tempfile.mkdtemp(prefix=3D"docker_build") > =20 > + # Do we include a extra binary? s/a extra/an extra/ > + if args.include_executable: > + _copy_binary_with_libs(args.include_executable, > + docker_dir) > + > dkr.build_image(tag, docker_dir, dockerfile, > quiet=3Dargs.quiet, argv=3Dargv) > =20 > --=20 > 2.7.4 >=20