fix(ecr): paginate image listings (#6544)

* fix(ecr): paginate image listings

* fix(ecr): fetch digests only for the selected page

* fix(test): await ECR tag release after stream reset

* refactor(ecr): remove unused image listing overload
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-25 21:37:26 -04:00
1 parent 671e4bfb7c
commit b29c8f8a60
7 files changed
+339 -23

No files matched your search

@@ -315,14 +315,27 @@ public class EcrJsonHandler {
private Response handleListImages(JsonNode request, String region) {
String repo = request.path("repositoryName").asText(null);
String registryId = request.path("registryId").asText(null);
List<ImageIdentifier> ids = service.listImages(repo, registryId, region);
JsonNode limit = request.get("maxResults");
if (limit != null && !limit.isNull() && (!limit.isIntegralNumber() || !limit.canConvertToInt())) {
throw new AwsException("InvalidParameterException", "maxResults must be between 1 and 1000", 400);
}
JsonNode token = request.get("nextToken");
if (token != null && !token.isNull() && !token.isTextual()) {
throw new AwsException("InvalidParameterException", "Invalid nextToken", 400);
}
Integer maxResults = request.hasNonNull("maxResults") ? limit.asInt() : null;
PaginatedResult<ImageIdentifier> page = service.listImages(repo, registryId, region,
maxResults, request.path("nextToken").asText(null));
ObjectNode response = objectMapper.createObjectNode();
ArrayNode arr = objectMapper.createArrayNode();
for (ImageIdentifier id : ids) {
for (ImageIdentifier id : page.items()) {
arr.add(buildImageIdentifier(id));
}
response.set("imageIds", arr);
if (page.nextToken() != null) {
response.put("nextToken", page.nextToken());
}
return Response.ok(response).build();
}
@@ -33,6 +33,7 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
@@ -513,25 +514,37 @@ public class EcrService implements ResourceProvider {
// ListImages / DescribeImages / BatchGetImage / BatchDeleteImage
// ============================================================
public List<ImageIdentifier> listImages(String repositoryName, String registryId, String region) {
public PaginatedResult<ImageIdentifier> listImages(String repositoryName, String registryId, String region,
Integer maxResults, String nextToken) {
int limit = maxResults != null ? maxResults : 100;
if (limit < 1 || limit > 1000) {
throw new AwsException("InvalidParameterException", "maxResults must be between 1 and 1000", 400);
}
String namespace = "ListImages:" + region + ":" + effectiveAccount(registryId) + ":" + repositoryName;
Repository repo = requireRepo(repositoryName, registryId, region);
requireRegistry();
String internal = resolveRegistryRepoName(repo.getRegistryId(), region, repositoryName);
try {
RegistryHttpClient http = registryManager.httpClient();
List<String> tags = http.listTags(internal);
List<ImageIdentifier> out = new ArrayList<>();
for (String tag : tags) {
String digest = http.headManifestDigest(internal, tag, null);
out.add(new ImageIdentifier(tag, digest));
}
return out;
} catch (Exception e) {
PaginatedResult<String> page = Pagination.paginate(http.listTags(internal), Function.identity(),
limit, nextToken, namespace,
token -> new AwsException("InvalidParameterException", "Invalid nextToken", 400));
return new PaginatedResult<>(imageIdentifiers(http, internal, page.items()), page.nextToken());
} catch (IOException | InterruptedException e) {
LOG.warnv("ListImages registry query failed for {0}: {1}", repositoryName, e.getMessage());
return List.of();
return new PaginatedResult<>(List.of(), null);
}
}
private static List<ImageIdentifier> imageIdentifiers(RegistryHttpClient http, String internal, List<String> tags)
throws IOException, InterruptedException {
List<ImageIdentifier> identifiers = new ArrayList<>();
for (String tag : tags) {
identifiers.add(new ImageIdentifier(tag, http.headManifestDigest(internal, tag, null)));
}
return identifiers;
}
public DescribeImagesResult describeImages(String repositoryName,
List<ImageIdentifier> requested,
String registryId,