}
sub find_docker_hash {
- # Given a Keep locator, search for a matching link to find the Docker hash
- # of the stored image.
+ # Given a Keep locator, return the hash of the image inside it.
my $locator = shift;
- my $links_result = $arv->{links}->{list}->execute(
- filters => [["head_uuid", "=", $locator],
- ["link_class", "=", "docker_image_hash"]],
- limit => 1);
my $docker_hash;
- foreach my $link (@{$links_result->{items}}) {
- $docker_hash = lc($link->{name});
+ 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 $docker_hash;
}
joins("JOIN collections ON links.head_uuid = collections.uuid").
order("links.created_at DESC")
- # If the search term is a Collection locator with an associated
- # Docker image hash link, return that Collection.
- coll_matches = base_search.
- where(link_class: "docker_image_hash", collections: {uuid: search_term})
- if match = coll_matches.first
- return [match.head_uuid]
+ # If the search term is a Collection locator that contains one file
+ # that looks like a Docker image, return it.
+ 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
+ end
end
# Find Collections with matching Docker image repository+tag pairs.
# hint-content ::= [A-Za-z0-9@_-]+
#
# Individual hints may have their own required format:
-#
+#
# sign-hint ::= "+A" <40 lowercase hex digits> "@" sign-timestamp
# sign-timestamp ::= <8 lowercase hex digits>
Locator.new(@hash, @size, @hints.reject { |o| o.start_with?("A") })
end
+ def strip_hints
+ Locator.new(@hash, @size, [])
+ end
+
+ def strip_hints!
+ @hints = []
+ self
+ end
+
def hash
@hash
end
updated_at: 2014-06-11T17:22:54Z
manifest_text: ". d21353cfe035e3e384563ee55eadbb2f+67108864 5c77a43e329b9838cbec18ff42790e57+55605760 0:122714624:d8309758b8fe2c81034ffc8a10c36460b77db7bc5e7b448c4e5b684f9d95a678.tar\n"
+unlinked_docker_image:
+ # This Collection contains a file that looks like a Docker image,
+ # but has no Docker metadata links pointing to it.
+ uuid: 9ae44d5792468c58bcf85ce7353c7027+124
+ owner_uuid: qr1hi-tpzed-000000000000000
+ created_at: 2014-06-11T17:22:54Z
+ modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+ modified_by_user_uuid: zzzzz-tpzed-d9tiejq69daie8f
+ modified_at: 2014-06-11T17:22:54Z
+ updated_at: 2014-06-11T17:22:54Z
+ manifest_text: ". fca529cfe035e3e384563ee55eadbb2f+67108863 0:67108863:bcd02158b8fe2c81034ffc8a10c36460b77db7bc5e7b448c4e5b684f9d95a678.tar\n"
+
empty:
# Empty collection owned by anonymous_group is added with rake db:seed.
uuid: d41d8cd98f00b204e9800998ecf8427e+0
head_uuid: fa3c1a9cb6783f85f2ecda037e07b8c3+167
properties: {}
+active_user_permission_to_unlinked_docker_image_collection:
+ uuid: zzzzz-o0j2j-g5i0sa8cr3b1psf
+ owner_uuid: zzzzz-tpzed-000000000000000
+ created_at: 2014-01-24 20:42:26 -0800
+ modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+ modified_by_user_uuid: zzzzz-tpzed-000000000000000
+ modified_at: 2014-01-24 20:42:26 -0800
+ updated_at: 2014-01-24 20:42:26 -0800
+ tail_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+ link_class: permission
+ name: can_read
+ head_uuid: 9ae44d5792468c58bcf85ce7353c7027+124
+ properties: {}
+
docker_image_collection_hash:
uuid: zzzzz-o0j2j-dockercollhasha
owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
assert(job.invalid?, "non-Docker Collection constraint was valid")
end
+ test "can create Job with Docker image Collection without Docker links" do
+ image_uuid = collections(:unlinked_docker_image).uuid
+ job = Job.new job_attrs(runtime_constraints: {"docker_image" => image_uuid})
+ assert(job.valid?, "Job created with unlinked Docker image was invalid")
+ assert_equal(image_uuid, job.docker_image_locator)
+ end
+
test "can't create Job with Docker image locator" do
begin
job = Job.new job_attrs(docker_image_locator: BAD_COLLECTION)