Commit 24f72ab8 authored by Elijah Grubb's avatar Elijah Grubb

Implemented piping of docker profile parameters

parent 52ad871b
......@@ -2798,6 +2798,24 @@ sub vnodeCreate($$$$)
push(@{$args{"HostConfig"}{"Binds"}},
"/etc/emulab/emulab.pem:/etc/emulab/emulab.pem:ro");
# piping through custom CMD and PATH variables for users of the docker
# images. Just have to write them to a file and let the runit utility
# do the rest
my $dockerenvdir = "$mntdir/etc.emulabdocker";
mkdir($dockerenvdir);
if (exists($attributes->{'DOCKER_ENV'})) {
open(FD, ">$dockerenvdir/dockerenv");
print FD $attributes->{'DOCKER_ENV'};
close(FD);
push(@{$args{"HostConfig"}{"Binds"}}, "$dockerenvdir/dockerenv:/etc/emulab/docker/dockerenv:ro");
}
if (exists($attributes->{'DOCKER_CMD'})) {
open(FD, ">$dockerenvdir/dockercmd");
print FD $attributes->{'DOCKER_CMD'};
close(FD);
push(@{$args{"HostConfig"}{"Binds"}}, "$dockerenvdir/dockercmd:/etc/emulab/docker/dockercmd:ro");
}
#
# We allow the server to tell us how many VCPUs to allocate to the
# guest.
......@@ -4523,7 +4541,6 @@ sub emulabizeImage($;$$$$$$$$)
my $dockerenvironmentvars;
# TODO: print out environment variables?
if (exists($iattrs{DOCKER_ENV})) {
$dockerenvironmentvars = $iattrs{DOCKER_ENV};
foreach my $elem (@$dockerenvironmentvars) {
......@@ -4532,11 +4549,19 @@ sub emulabizeImage($;$$$$$$$$)
}
}
# handle if a user enters in extra environment variables using the
# profile parameters section
print $runitfile "if [ -f /etc/emulab/docker/dockerenv ]; then\n";
print $runitfile " . /etc/emulab/docker/dockerenv\n";
print $runitfile "fi\n";
print $runitfile "\n";
my $dockerentrypoint;
my $dockercmd;
print $runitfile "if [ ! -f /etc/emulab/docker/dockercmd ]; then\n";
if (exists($iattrs{DOCKER_ENTRYPOINT})) {
$dockerentrypoint = $iattrs{DOCKER_ENTRYPOINT};
# check if first arg is /bin/sh
......@@ -4563,6 +4588,23 @@ sub emulabizeImage($;$$$$$$$$)
}
}
print $runitfile "\n";
print $runitfile "else\n";
print $runitfile "exec ";
if (exists($iattrs{DOCKER_ENTRYPOINT})) {
$dockerentrypoint = $iattrs{DOCKER_ENTRYPOINT};
# print whole thing to file
# need to be careful about variables to be expanded
foreach my $elem (@$dockerentrypoint) {
print $runitfile $elem;
print $runitfile " ";
}
}
print $runitfile '"$(cat /var/emulab/docker/dockercmd)"';
print $runitfile "\n";
print $runitfile "fi\n";
print $runitfile "\n\n";
print $runitfile "exit 0";
close $runitfile;
......
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