Commit eebbe96f authored by Elijah Grubb's avatar Elijah Grubb

Emulab Docker CMD and Entrypoint to runit services

This adds to the preparation of Docker images running
on the Emulab system by creating a new runit service
handling the details of their CMD and Entrypoint capabilities.
This scripting also sets the scaffolding for custom
CMDs and environment variables to be set by the user
as a part of their profile parameters.

Squashed commit of the following:

commit 50ad95137f138f663ff826a16857911296686cf6
Merge: 24f72ab86 38f254fd
Author: Elijah Grubb <u0894728@utah.edu>
Date:   Wed Apr 18 03:35:09 2018 -0600

    Merge branch 'master' into docker-entrypoint

commit 24f72ab86ae9ef2cf91af57279bcc4fa0ce50d9c
Author: Elijah Grubb <u0894728@utah.edu>
Date:   Wed Apr 4 02:30:10 2018 -0600

    Implemented piping of docker profile parameters

commit 52ad871ba22fb90af374baa1fb951210fbb1c0be
Merge: ce34a36c1 b4679058
Author: Elijah Grubb <u0894728@utah.edu>
Date:   Wed Mar 28 10:01:45 2018 -0600

    Merge remote-tracking branch 'origin/master' into docker-entrypoint

commit ce34a36c17ad0654bc52c075a4c52fe330eb6e35
Author: Elijah Grubb <u0894728@utah.edu>
Date:   Mon Mar 26 08:49:15 2018 -0600

    Implemented runit service for docker entrypoint
parent 38f254fd
......@@ -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.
......@@ -4513,6 +4531,84 @@ sub emulabizeImage($;$$$$$$$$)
}
}
mkdir("$hdir/etc/service/dockerentrypoint");
open(my $runitfile, ">", "$hdir/etc/service/dockerentrypoint/run");
print $runitfile "#!/bin/sh\n";
print $runitfile "\n";
print $runitfile "# This is an automatically generated runit file based on the docker image's entrypoint and cmd\n\n";
my $dockerenvironmentvars;
if (exists($iattrs{DOCKER_ENV})) {
$dockerenvironmentvars = $iattrs{DOCKER_ENV};
foreach my $elem (@$dockerenvironmentvars) {
print $runitfile $elem;
print $runitfile "\n";
}
}
# 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
if ($dockerentrypoint->[0] ne "/bin/sh") {
print $runitfile "exec ";
}
# print whole thing to file
# need to be careful about variables to be expanded
foreach my $elem (@$dockerentrypoint) {
print $runitfile $elem;
print $runitfile " ";
}
}
if (exists($iattrs{DOCKER_CMD})) {
$dockercmd = $iattrs{DOCKER_CMD};
if ($dockercmd->[0] ne "/bin/sh" and !defined($dockerentrypoint)) {
print $runitfile "exec ";
}
foreach my $elem (@$dockercmd) {
print $runitfile $elem;
print $runitfile " ";
}
}
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;
#
# Before we start setting up the new image Dockerfile, run
# all the artifact build scripts.
......
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