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 v3 5/5] tests/docker/docker.py: add update operation
Date: Tue, 28 Jun 2016 16:42:44 +0100 [thread overview]
Message-ID: <1467128564-13476-6-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1467128564-13476-1-git-send-email-alex.bennee@linaro.org>
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 <alex.bennee@linaro.org>
---
v3
- new in v3
---
tests/docker/docker.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
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: <tag> <executable>"""
+ 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"
--
2.7.4
next prev parent reply other threads:[~2016-06-28 15:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-28 15:42 [Qemu-devel] [PATCH v3 0/5] Support building qemu-user powered docker test images Alex Bennée
2016-06-28 15:42 ` [Qemu-devel] [PATCH v3 1/5] tests/docker/docker.py: docker_dir outside build Alex Bennée
2016-06-28 15:42 ` [Qemu-devel] [PATCH v3 2/5] tests/docker/docker.py: support --include-executable Alex Bennée
2016-06-28 15:42 ` [Qemu-devel] [PATCH v3 3/5] tests/docker/docker.py: check and run .pre script Alex Bennée
2016-06-28 15:42 ` [Qemu-devel] [PATCH v3 4/5] tests/docker/dockerfiles: new debian-bootstrap.docker Alex Bennée
2016-06-28 15:42 ` Alex Bennée [this message]
2016-07-08 6:15 ` [Qemu-devel] [PATCH v3 0/5] Support building qemu-user powered docker test images Fam Zheng
2016-07-08 7:53 ` Alex Bennée
2016-07-08 9:14 ` Fam Zheng
2016-07-08 10:10 ` 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=1467128564-13476-6-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).