List of usage examples for com.amazonaws.services.ecr AmazonECR describeImages
DescribeImagesResult describeImages(DescribeImagesRequest describeImagesRequest);
Returns metadata about the images in a repository, including image size, image tags, and creation date.
From source file:com.netflix.spinnaker.clouddriver.ecs.provider.view.EcrImageProvider.java
License:Apache License
@Override public List<EcsDockerImage> findImage(String url) { // HTTP(S) part is not needed. url = url.replace("http://", "").replace("https://", ""); String accountId = extractAwsAccountId(url); String repository = extractEcrRepositoryName(url); String identifier = extractEcrIdentifier(repository, url); boolean isTag = !(identifier.startsWith("sha256:") && identifier.length() == ("sha256:".length() + 64)); String region = extractAwsRegion(url); NetflixAmazonCredentials credentials = getCredentials(accountId); if (!isValidRegion(credentials, region)) { throw new IllegalArgumentException( "The repository URI provided does not belong to a region that the credentials have access to or the region is not valid."); }/* w w w . j a v a 2 s. c o m*/ AmazonECR amazonECR = amazonClientProvider.getAmazonEcr(credentials.getName(), credentials.getCredentialsProvider(), region); ListImagesResult result = amazonECR .listImages(new ListImagesRequest().withRegistryId(accountId).withRepositoryName(repository)); DescribeImagesResult imagesResult = amazonECR.describeImages(new DescribeImagesRequest() .withRegistryId(accountId).withRepositoryName(repository).withImageIds(result.getImageIds())); // TODO - what is the user interface we want to have here? We should discuss with Lars and Ethan from the community as this whole thing will undergo a big refactoring List<ImageDetail> imagesWithThisIdentifier = imagesResult.getImageDetails().stream() .filter(imageDetail -> imageFilter(imageDetail, identifier, isTag)).collect(Collectors.toList()); if (imagesWithThisIdentifier.size() > 1) { throw new IllegalArgumentException("More than 1 image has this " + (isTag ? "tag" : "digest") + "! This is currently not supported."); } else if (imagesWithThisIdentifier.size() == 0) { throw new IllegalArgumentException(String .format("No image with the " + (isTag ? "tag" : "digest") + " %s was found.", identifier)); } ImageDetail matchedImage = imagesWithThisIdentifier.get(0); EcsDockerImage ecsDockerImage = new EcsDockerImage(); ecsDockerImage.setRegion(region); ecsDockerImage.addAmiForRegion(region, matchedImage.getImageDigest()); ecsDockerImage.setAttribute("creationDate", matchedImage.getImagePushedAt()); ecsDockerImage.setImageName(buildFullDockerImageUrl(matchedImage.getImageDigest(), matchedImage.getRegistryId(), matchedImage.getRepositoryName(), region)); return Collections.singletonList(ecsDockerImage); }