3527: Support using a Docker image from any stream in a Collection.
authorBrett Smith <brett@curoverse.com>
Fri, 8 Aug 2014 17:44:00 +0000 (13:44 -0400)
committerBrett Smith <brett@curoverse.com>
Fri, 8 Aug 2014 17:51:10 +0000 (13:51 -0400)
This makes Docker image detection more consistent between crunch-job
and the API server, and is more user-friendly.

sdk/cli/bin/crunch-job
services/api/app/models/collection.rb

index ad4330313e64ae058badd4497c05e15086bdd3ff..06b3da99a9929823bdc6b91ca4d315bb46878bc0 100755 (executable)
@@ -499,16 +499,17 @@ if (!$have_slurm)
 
 # 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();
@@ -1466,18 +1467,19 @@ sub must_lock_now
   }
 }
 
-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__
index 2601a27a1a27d4da98bb683e3cc4bb9c143b2360..50dd42cd1cce1cccaa4c5fa0145e37eea22d583f 100644 (file)
@@ -164,11 +164,9 @@ class Collection < ArvadosModel
     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