2015-03-28 11:28 GMT+01:00 Mathieu Parent <math.par...@gmail.com>: > Hello, > > I have attached the current version. > > Martin, can you review it? The manpage is missing.
Here's an improved version with th manpage. Regards -- Mathieu
From e5b3a94f7808cfd180a0e57007d36d27633a90a5 Mon Sep 17 00:00:00 2001 From: Mathieu Parent <math.par...@gmail.com> Date: Sat, 28 Mar 2015 11:25:32 +0100 Subject: [PATCH] Add adt-virt-docker (Closes: #747909) --- virt-subproc/adt-virt-docker | 141 +++++++++++++++++++++++++++++++++++++++++ virt-subproc/adt-virt-docker.1 | 81 +++++++++++++++++++++++ 2 files changed, 222 insertions(+) create mode 100755 virt-subproc/adt-virt-docker create mode 100644 virt-subproc/adt-virt-docker.1 diff --git a/virt-subproc/adt-virt-docker b/virt-subproc/adt-virt-docker new file mode 100755 index 0000000..2442200 --- /dev/null +++ b/virt-subproc/adt-virt-docker @@ -0,0 +1,141 @@ +#!/usr/bin/python3 +# +# adt-virt-docker is part of autopkgtest +# autopkgtest is a tool for testing Debian binary packages +# +# autopkgtest is Copyright (C) 2006-2015 Canonical Ltd. +# +# adt-virt-docker was derived from adt-virt-lxc and modified to suit Docker by +# Mathieu Parent <math.par...@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# See the file CREDITS for a full list of credits information (often +# installed as /usr/share/doc/autopkgtest/CREDITS). + +import sys +import os +import subprocess +import tempfile +import shutil +import argparse + +try: + our_base = os.environ['AUTOPKGTEST_BASE'] + '/lib' +except KeyError: + our_base = '/usr/share/autopkgtest/python' +sys.path.insert(1, our_base) + +import VirtSubproc +import adtlog + + +capabilities = ['revert-full-system', 'root-on-testbed', + 'isolation-container'] + +args = None +docker_container_id = None +shared_dir = None + + +def parse_args(): + global args + + parser = argparse.ArgumentParser(fromfile_prefix_chars='@') + + parser.add_argument('-d', '--debug', action='store_true', + help='Enable debugging output') + parser.add_argument('image', help='Base image') + parser.add_argument('dockerargs', nargs=argparse.REMAINDER, + help='Additional arguments to pass to docker run ') + args = parser.parse_args() + if args.debug: + adtlog.verbosity = 2 + + +def hook_open(): + global args, docker_container_id, shared_dir + + if shared_dir is None: + shared_dir = tempfile.mkdtemp(prefix='adt-virt-docker.shared.') + else: + # don't change the name between resets, to provide stable downtmp paths + os.makedirs(shared_dir) + os.chmod(shared_dir, 0o755) + docker_container_id = VirtSubproc.check_exec(['docker', 'run', '--detach=true', + '--volume', "{0}:{0}".format(shared_dir)] + args.dockerargs + [args.image, 'sh', '-c', 'while true; do sleep 600; done'], + outp=True) + adtlog.debug('hook_open: got docker container id %s' % docker_container_id) + VirtSubproc.auxverb = [ + 'docker', 'exec', docker_container_id + ] + (status, out, err) = VirtSubproc.execute_timeout(None, 0, VirtSubproc.auxverb + ['false'], stdout=subprocess.PIPE) + if status == 0: + # In Docker < 1.4, docker exec doesn't pass the return value + # We use nsenter which pass return value + # See https://github.com/duglin/docker/commit/90928eb1140fc0394e2 + adtlog.debug('hook_open: using nsenter workaround') + docker_container_pid = VirtSubproc.check_exec(['docker', 'inspect', + '--format', '{{.State.Pid}}', docker_container_id], outp=True) + VirtSubproc.auxverb = [ + 'sudo', 'nsenter', '--target', docker_container_pid, '--mount', '--uts', '--ipc', '--net', + '--pid', '--root', '--wd' # '--user' + ] + (status, out, err) = VirtSubproc.execute_timeout(None, 0, VirtSubproc.auxverb + ['apt-get', 'update'], stdout=subprocess.PIPE) + + +def hook_downtmp(path): + global capabilities, shared_dir + + if shared_dir: + d = os.path.join(shared_dir, 'downtmp') + # these permissions are ugly, but otherwise we can't clean up files + # written by the testbed when running as user + VirtSubproc.check_exec(['mkdir', '-m', '777', d], downp=True) + capabilities.append('downtmp-host=' + d) + else: + d = VirtSubproc.downtmp_mktemp(path) + return d + + +def hook_revert(): + hook_cleanup() + hook_open() + + +def hook_cleanup(): + global capabilities, docker_container_id, shared_dir + + VirtSubproc.downtmp_remove() + capabilities = [c for c in capabilities if not c.startswith('downtmp-host')] + if shared_dir: + shutil.rmtree(shared_dir) + + stop_outp = VirtSubproc.check_exec(['docker', 'stop', docker_container_id], outp=True) + adtlog.debug('hook_cleanup: %s stopped' % stop_outp) + rm_outp = VirtSubproc.check_exec(['docker', 'rm', docker_container_id], outp=True) + adtlog.debug('hook_cleanup: %s removed' % rm_outp) + + +def hook_forked_inchild(): + pass + + +def hook_capabilities(): + return capabilities + + +parse_args() +VirtSubproc.main() diff --git a/virt-subproc/adt-virt-docker.1 b/virt-subproc/adt-virt-docker.1 new file mode 100644 index 0000000..3391213 --- /dev/null +++ b/virt-subproc/adt-virt-docker.1 @@ -0,0 +1,81 @@ +.TH adt\-virt-docker 1 2015 "Linux Programmer's Manual" +.SH NAME +adt\-virt\-docker \- autopkgtest virtualisation server using Docker + +.SH SYNOPSYS +.B adt\-virt\-docker +.RI [ options ] +.I docker\-image +.RI [ "-- extra docker-run args..." ] + +.SH DESCRIPTION +.B adt-virt-docker +provides an autopkgtest virtualisation server using Docker. It adapts the +functionality provided by the +.BR docker +command line for use by autopkgtest. + +Normally +.B adt-virt-docker +will be invoked by +.BR adt-run . + +.SH REQUIREMENTS +.B adt-virt-docker +needs the docker client (in the docker.io package). + +.SH OPTIONS + +.TP +.BR \-d " | " \-\-debug +Enables debugging output. + +.PP +You can pass additional options to Docker: Anything after a +.B -- +gets passed verbatim to \fBdocker-run\fR(1). + +.SH INPUT, OUTPUT AND EXIT STATUS +The behaviour of +.B adt-virt-docker +is as described by the AutomatedTesting virtualisation regime +specification. + +.SH NOTES + +Read \fB/usr/share/doc/docker.io/README.Debian\fR first to communicate to the +daemon. + +\fBadt-virt-docker\fR try to use \fBdocker-exec\fR(1), but fall back to +\fBsudo\fR(1) \fBnsenter\fR(1) on Docker < 1.4 which doesn't return status. + +\fBadt-virt-docker\fR does run \fBapt-get update\fR at the start of a package +build, as most images needs it. + +.SH EXAMPLE + +You can use "(Semi) Official Debian base images" like \fBdebian:jessie\fR, +or "Official Ubuntu base images", like \fBubuntu:trusty\fR. + +Run tests against \fIhello_2.8\-4.dsc\fR, using the Docker image \fIdebian:jessie\fR: + +.RS +.EX +adt-run \fIhello_2.8\-4.dsc\fR --- adt-virt-docker \fIdebian:jessie\fR +.EE +.RE + +.SH SEE ALSO +\fBadt\-run\fR(1), +\fBdocker\-run\fR(1), +\fB/usr/share/doc/autopkgtest/\fR. + +.SH AUTHORS AND COPYRIGHT +.B adt-virt-docker +was written by Mathieu Parent <math.par...@gmail.com>. + +This manpage is part of autopkgtest, a tool for testing Debian binary +packages. autopkgtest is Copyright (C) 2006-2015 Canonical Ltd and others. + +See \fB/usr/share/doc/autopkgtest/CREDITS\fR for the list of +contributors and full copying conditions. -- 2.1.4