aboutsummaryrefslogtreecommitdiff
path: root/tests/docker
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2016-07-19 21:20:40 +0800
committerFam Zheng <famz@redhat.com>2016-07-20 19:19:43 +0800
commit6e733da676a5483314d86f1bcb14950a165b0e6f (patch)
treebed329bf9fcb3c87ad8ba51cc8d17b3f461f8d22 /tests/docker
parent95c975013a15405a5ab257deae843ecd2eea20ec (diff)
downloadqemu-6e733da676a5483314d86f1bcb14950a165b0e6f.zip
qemu-6e733da676a5483314d86f1bcb14950a165b0e6f.tar.gz
qemu-6e733da676a5483314d86f1bcb14950a165b0e6f.tar.bz2
tests/docker/docker.py: add update operation
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> Message-id: 1468934445-32183-6-git-send-email-famz@redhat.com Signed-off-by: Fam Zheng <famz@redhat.com>
Diffstat (limited to 'tests/docker')
-rwxr-xr-xtests/docker/docker.py59
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 76750c4..40bda9d 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)
@@ -245,6 +254,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"