Commit b0f17e8e authored by David Johnson's avatar David Johnson

Add more docker clientside tools.

Especially libvnode_docker::analyzeImageWithBusyboxCommand, which runs
the busybox-static binary from the root context in the container with
the given command (and extra container run API configuration).
parent f0b36cb7
......@@ -516,7 +516,10 @@ docker-install: dir-install
$(BINDIR)/run/rcmanifest.d
$(INSTALL) -m 755 $(SRCDIR)/docker/create-docker-image $(LBINDIR)/
$(INSTALL) -m 755 $(SRCDIR)/docker/emulabize-image $(LBINDIR)/
$(INSTALL) -m 755 $(SRCDIR)/docker/analyze-image $(LBINDIR)/
$(INSTALL) -m 755 $(SRCDIR)/docker/analyze-image-with-busybox $(LBINDIR)/
$(INSTALL) -m 755 $(SRCDIR)/vnodectl $(BINDIR)/
$(INSTALL) -m 755 $(SRCDIR)/docker/cleanup-docker-vnodes.sh $(BINDIR)/
# Note that we install this, but do not enable it. It is dynamically
# started and stopped as needed by libvnode_docker.pm .
$(INSTALL) -m 644 -o root -g $(DIRGROUP) \
......
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use English;
use POSIX;
use Data::Dumper;
#
# A simple CLI wrapper around libvnode_docker::analyzeImage.
#
sub usage()
{
print "Usage: analyze-image [-d <level>] [-f] <image>\n".
"\n".
" -d <level> Debug mode\n".
" -f Analyze the image even if it has already been done\n";
exit(1);
}
my $optlist = "hd:f";
my $debug = 0;
my $force = 0;
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (!getopts($optlist,\%options)) {
usage();
}
if (defined($options{"h"})) {
usage();
}
if (defined($options{"d"})) {
$debug = $options{"d"};
}
if (defined($options{"f"})) {
$force = 1;
}
usage()
if (@ARGV > 1);
#
# Must be root.
#
if ($UID != 0) {
die("*** $0:\n".
" Must be root to run this script!\n");
}
#
# Turn off line buffering on output
#
$| = 1;
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
use libsetup;
use libvnode_docker;
if ($debug) {
TBDebugTimeStampsOn();
libvnode_docker::setDebug($debug);
}
my %rethash = ();
my $image = $ARGV[0];
my $rc = libvnode_docker::analyzeImage($image,\%rethash,$force);
if ($rc) {
fatal("ERROR: failed to analyze $image!\n");
}
else {
print "Successfully analyzed $image:\n";
for my $k (keys(%rethash)) {
my $v = '';
if (defined($rethash{$k})) {
$v = $rethash{$k};
}
print "$k=$v\n";
}
}
exit(0);
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use English;
use POSIX;
use Data::Dumper;
use JSON::PP;
#
# A simple CLI wrapper around libvnode_docker::analyzeImageWithBusyboxCommand.
#
sub usage()
{
print "Usage: analyze-image-with-busybox [-d <level>] [-c] <image> [command... ]\n".
"\n".
" -d <level> Debug mode\n".
" -c <json> Customize the temporary container config according".
" to JSON passed to the Docker run API command.\n";
exit(1);
}
my $optlist = "hd:c:";
my $debug = 0;
my $config = {};
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (!getopts($optlist,\%options)) {
usage();
}
if (defined($options{"h"})) {
usage();
}
if (defined($options{"d"})) {
$debug = $options{"d"};
}
if (defined($options{"c"})) {
$config = decode_json($options{"c"});
}
usage()
if (@ARGV < 2);
#
# Must be root.
#
if ($UID != 0) {
die("*** $0:\n".
" Must be root to run this script!\n");
}
#
# Turn off line buffering on output
#
$| = 1;
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
use libsetup;
use libvnode_docker;
if ($debug) {
TBDebugTimeStampsOn();
libvnode_docker::setDebug($debug);
}
my $ret;
my $image = shift(@ARGV);
my $rc = libvnode_docker::analyzeImageWithBusyboxCommand(
$image,$config,\$ret,@ARGV);
if ($rc) {
fatal("ERROR: failed to analyze $image with busybox!\n");
}
else {
print "Successfully analyzed $image with busybox:\n$ret";
}
exit(0);
#!/bin/sh
#
# Cleans up *everything* related to the specified vnode, or to all
# vnodes if -a is specified instead of a vnode.
#
usage() {
if [ -n "$1" ]; then
echo "ERROR: $1"
fi
echo "USAGE: $0 [-h] [-a | vnode... ]"
echo " -a Remove all vnodes"
echo " vnode... A space-separated list of vnodes to remove"
exit 1
}
cleanupvnode() {
vnode=$1
echo "Cleaning up vnode $vnode..."
/usr/local/etc/emulab/vnodesetup -d -k -j $vnode
if [ -d /var/emulab/boot/tmcc.$vnode ]; then
echo "WARNING: /var/emulab/boot/tmcc.$vnode exists; removing!"
fi
rm -rf /var/emulab/boot/tmcc.$vnode
}
doall=0
VNODES=""
count="$#"
i=0
if [ "$#" -eq 0 ]; then
usage "no arguments specified"
fi
while [ $i -lt $count ]; do
arg="$1"
case "$arg" in
-h|--help)
usage
;;
-a)
doall=1
if [ -n "$VNODES" ]; then
usage "cannot specify both -a and specific vnodes"
fi
;;
*)
if [ $doall -eq 1 ]; then
usage "cannot specify both specific vnodes and -a ($arg)"
fi
VNODES="$VNODES $arg"
;;
esac
shift
i=`expr $i + 1`
done
if [ $doall -eq 1 ]; then
VNODES=`cat /var/emulab/boot/tmcc/vnodelist | sed -e 's/^VNODEID=\([^ ]*\).*/\1/' | sort | xargs`
fi
for vnode in $VNODES; do
cleanupvnode $vnode
done
......@@ -38,7 +38,7 @@ sub usage()
exit(1);
}
my $optlist = "hfd:e:P:u:p:D";
my $debug = 1;
my $debug = 0;
my $emulabization;
my $pullpolicy;
my $update = 0;
......
......@@ -4306,6 +4306,55 @@ sub vnodeDestroy($$$$)
## Utility and helper functions.
##
sub analyzeImageWithBusyboxCommand($$$@)
{
my ($image,$configref,$outputref,@bargv) = @_;
TBDebugTimeStamp("running static busybox (".join('',@bargv).")".
" for image $image...");
my $args = {
'HostConfig' => {
'Binds' => [ "/bin/busybox:/tmp/busybox:ro" ]
},
'Entrypoint' => '',
};
my @argv = ('/tmp/busybox',@bargv);
if (defined($configref)) {
require Hash::Merge;
$args = Hash::Merge::merge($args,$configref);
if ($debug) {
print STDERR "DEBUG: merged args = ".Dumper($args)."\n";
}
}
my $tmpname = "busybox-analyzer-".int(rand(POSIX::INT_MAX));
our $buf = '';
my ($code,$json,$resp,$retval) = getClient->container_run(
$tmpname,$image,\@argv,1,$args,sub { $buf .= $_[0]; });
if ($code) {
warn("failed to run busybox analysis container $tmpname for $image");
return $code;
}
# Santize the output. For whatever reason(s), under heavy load, it
# comes with non-printable chars occasionally, and with CRLF. Odd.
$buf =~ s/[\000-\011\014\015-\037\176-\255]//g;
TBDebugTimeStamp("busybox analyze output:\n$buf");
open(FD,">/vms/contexts/$tmpname.log");
print FD $buf;
close(FD);
if (defined($outputref)) {
if (ref($$outputref) eq 'ARRAY') {
$$outputref = split("\n",$buf);
}
else {
$$outputref = $buf;
}
}
return 0;
}
#
# Analyze an existing Docker image to extra image metadata,
# distro/version, and so on.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment