# If this job requires a Docker image, install that.
my $docker_bin = "/usr/bin/docker.io";
-my ($docker_locator, $docker_hash);
+my ($docker_locator, $docker_stream, $docker_hash);
if ($docker_locator = $Job->{docker_image_locator}) {
- $docker_hash = find_docker_hash($docker_locator);
+ ($docker_stream, $docker_hash) = find_docker_image($docker_locator);
if (!$docker_hash)
{
croak("No Docker image hash found from locator $docker_locator");
}
+ $docker_stream =~ s/^\.//;
my $docker_install_script = qq{
if ! $docker_bin images -q --no-trunc | grep -qxF \Q$docker_hash\E; then
- arv-get \Q$docker_locator/$docker_hash.tar\E | $docker_bin load
+ arv-get \Q$docker_locator$docker_stream/$docker_hash.tar\E | $docker_bin load
fi
};
my $docker_pid = fork();
}
}
-sub find_docker_hash {
- # Given a Keep locator, return the hash of the image inside it.
+sub find_docker_image {
+ # Given a Keep locator, check to see if it contains a Docker image.
+ # If so, return its stream name and Docker hash.
+ # If not, return undef for both values.
my $locator = shift;
- my $docker_hash;
if (my $image = $arv->{collections}->{get}->execute(uuid => $locator)) {
my @file_list = @{$image->{files}};
if ((scalar(@file_list) == 1) &&
($file_list[0][1] =~ /^([0-9A-Fa-f]{64})\.tar$/)) {
- $docker_hash = $1;
+ return ($file_list[0][0], $1);
}
}
- return $docker_hash;
+ return (undef, undef);
}
__DATA__
if loc = Locator.parse(search_term)
loc.strip_hints!
coll_match = readable_by(*readers).where(uuid: loc.to_s).first
- if coll_match.andand.files.andand.size == 1
- dirname, basename = coll_match.files.first[0, 2]
- if (dirname == ".") and (basename =~ /^[0-9A-Fa-f]{64}\.tar$/)
- return [loc.to_s]
- end
+ if coll_match and (coll_match.files.size == 1) and
+ (coll_match.files[0][1] =~ /^[0-9A-Fa-f]{64}\.tar$/)
+ return [loc.to_s]
end
end