mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ecs): pull task images at launch so a moved tag reaches the next task (#4583)
* fix(ecs): pull task images at launch so a moved tag reaches the next task Floci resolved an image reference to an image id the first time it saw it and reused that id for the life of the process, so a rebuilt :latest pushed to the registry never reached a new task, even through a new task definition revision and a forced deployment, and nothing reported the mismatch. ECS now pulls every container image when a task starts, before creating any of its containers, following the agent's ECS_IMAGE_PULL_BEHAVIOR (configurable as floci.services.ecs.image-pull-behavior, default "default": pull, and fall back to the cached image when the pull fails). The cached image is whatever the local tag names at launch rather than a remembered id. Each container reports the manifest digest it runs as containers[].imageDigest. * fix(ecs): create task containers from the image id their pull resolved to An overlapping RunTask could pull the same moved tag between this task's pull and its container creation, so the container was created from whatever the shared tag cache named by then while reporting the digest this task pulled. resolveForLaunch now returns the resolved image id with its digest, and ECS builds each container from that id, so the image a task runs and the digest it reports always come from the same pull. The pull also now uses the reference the container is created from, including floci.docker.image-registry-base, instead of the unprefixed name. * fix(ecs): launch image ids without a pull and report the digest the pull resolved A bare sha256 image id under always, or on the first once launch, went to the registry as if it were a repository reference and failed the task although the image was local. resolveForLaunch now runs an image id as it is, like ensureImageExists. The reported digest took the first RepoDigests entry for the repository, which is not necessarily the manifest the tag resolved to when the image holds more than one (an index and a platform manifest). It now comes from the Digest line the daemon streams for the pull, kept while the tag still names that image; a cached image falls back to its repo digest only when there is exactly one. The shared test config uses prefer-cached so the other ECS Docker suites stop adding a registry round trip per launch; the image pull integration test pins default in its own profile. ContainerBuilder imports are back in order. * fix(ecs): report a pull's digest only for the launch that pulled The digest a pull reported was kept per reference and reused while the tag still named the same image id, but on the classic image store an id is the config digest and several manifests can share it, so an outside pull could move the tag to another manifest and leave the reused digest stale. Only the launch that pulled now uses the streamed digest. A cached launch uses the image's repo digest for the repository when there is one, or the one equal to the id (the containerd store names an image by its manifest), and otherwise none. Also sorts the ContainerLifecycleManager imports. * fix(ecs): pull the image-pull test's busybox and registry from Docker Hub EcsImagePullDockerIntegrationTest pulled both images through the public.ecr.aws/docker/library mirror, whose anonymous quota is shared per runner IP; shard 3 failed on toomanyrequests: Data limit exceeded. Take them from TestImages like the other Docker-backed tests, pinning the registry image there, and prefetch both for the shard that runs the class. * test(ecs): name the registry readiness probe's tolerated exception expected
This commit is contained in:
1 parent
bc42cee767
commit
d73e33fe4b
26 files changed
+1051
-28
No files matched your search
@@ -2122,7 +2122,30 @@ public interface EmulatorConfig {
|
||||
@WithDefault("true")
|
||||
boolean reconcileContainersOnStartup();
|
||||
|
||||
/**
|
||||
* How a task's container images are pulled when the task starts, with the values and
|
||||
* semantics of the ECS agent's {@code ECS_IMAGE_PULL_BEHAVIOR}. The default pulls on every
|
||||
* launch, so a tag moved in its registry (a rebuilt {@code :latest}) is what the next task
|
||||
* runs.
|
||||
*/
|
||||
@WithDefault("default")
|
||||
ImagePullBehavior imagePullBehavior();
|
||||
|
||||
EcsTaskRoleCredentialsConfig taskRoleCredentials();
|
||||
|
||||
enum ImagePullBehavior {
|
||||
/** Pull on every launch; when the pull fails, run the cached image if there is one. */
|
||||
DEFAULT,
|
||||
/** Pull on every launch; when the pull fails, the task fails. */
|
||||
ALWAYS,
|
||||
/**
|
||||
* Pull when Floci has not pulled the image since it started or the cached image is
|
||||
* gone; otherwise run the cached image.
|
||||
*/
|
||||
ONCE,
|
||||
/** Pull only when there is no cached image. */
|
||||
PREFER_CACHED
|
||||
}
|
||||
}
|
||||
|
||||
interface EcsTaskRoleCredentialsConfig {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package io.github.hectorvent.floci.core.common.docker;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
|
||||
import com.github.dockerjava.api.model.AccessMode;
|
||||
import com.github.dockerjava.api.model.Bind;
|
||||
import com.github.dockerjava.api.model.DeviceRequest;
|
||||
@@ -10,6 +8,9 @@ import com.github.dockerjava.api.model.Mount;
|
||||
import com.github.dockerjava.api.model.MountType;
|
||||
import com.github.dockerjava.api.model.Volume;
|
||||
import com.github.dockerjava.api.model.VolumesFrom;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.ImageCacheService;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@@ -92,7 +93,7 @@ public class ContainerBuilder {
|
||||
}
|
||||
|
||||
static String resolveImage(String image, Optional<String> imageRegistryBase) {
|
||||
if (image == null || image.isBlank()) {
|
||||
if (image == null || image.isBlank() || ImageCacheService.isImageId(image)) {
|
||||
return image;
|
||||
}
|
||||
return normalizeImageRegistryBase(imageRegistryBase)
|
||||
|
||||
+14
-3
@@ -1,8 +1,5 @@
|
||||
package io.github.hectorvent.floci.core.common.docker;
|
||||
|
||||
import io.github.hectorvent.floci.config.ContainerCaBundle;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.ImageCacheService;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import com.github.dockerjava.api.command.CreateContainerCmd;
|
||||
@@ -22,6 +19,11 @@ import com.github.dockerjava.api.model.Mount;
|
||||
import com.github.dockerjava.api.model.MountType;
|
||||
import com.github.dockerjava.api.model.Ports;
|
||||
import com.github.dockerjava.core.command.WaitContainerResultCallback;
|
||||
import io.github.hectorvent.floci.config.ContainerCaBundle;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig.EcsServiceConfig.ImagePullBehavior;
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.ImageCacheService;
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.ImageCacheService.LaunchImage;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -114,6 +116,15 @@ public class ContainerLifecycleManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the image a container launch is about to run, pulling it as the ECS agent does
|
||||
* under {@code behavior}. A spec built from the returned image id runs exactly that image,
|
||||
* whatever a later pull of the same reference moves its tag to.
|
||||
*/
|
||||
public LaunchImage resolveImageForLaunch(String image, ImagePullBehavior behavior) {
|
||||
return imageCacheService.resolveForLaunch(image, behavior);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a container without starting it. Use {@link #startCreated} to
|
||||
* start it after any pre-start setup (e.g. copying files into the
|
||||
|
||||
+17
-1
@@ -38,6 +38,7 @@ import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskNetworkInterface;
|
||||
import io.github.hectorvent.floci.services.ecs.model.Volume;
|
||||
import io.github.hectorvent.floci.services.ecs.model.VolumeFrom;
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.ImageCacheService.LaunchImage;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
@@ -249,6 +250,7 @@ public class EcsContainerManager {
|
||||
Map<ContainerDefinition, List<String>> envVarsByContainer = new LinkedHashMap<>();
|
||||
// Resolved before any container is created, so a registry-startup failure can't leak one already started.
|
||||
Map<ContainerDefinition, String> imagesByContainer = new LinkedHashMap<>();
|
||||
Map<String, String> imageDigestsByContainer = new LinkedHashMap<>();
|
||||
// The task metadata id has to exist before the container does: its own environment carries
|
||||
// the URI, so it cannot be derived from the Docker id the daemon hands back afterwards.
|
||||
Map<String, String> metadataIdsByContainer = new LinkedHashMap<>();
|
||||
@@ -262,7 +264,20 @@ public class EcsContainerManager {
|
||||
metadataIdsByContainer.put(def.getName(), metadataId);
|
||||
envVarsByContainer.put(def, buildEnvVars(def, overridesByName.get(def.getName()), region,
|
||||
metadataId, taskRoleEndpoint.vending()));
|
||||
imagesByContainer.put(def, ecrRegistryManager.rewriteImageUri(def.getImage()));
|
||||
imagesByContainer.put(def,
|
||||
containerBuilder.resolveImage(ecrRegistryManager.rewriteImageUri(def.getImage())));
|
||||
}
|
||||
// Pulled for every container before any is created, as the ECS agent does, so a tag
|
||||
// moved in its registry since the last launch is what this task runs. Each container is
|
||||
// created from the image id its pull resolved to, so a concurrent launch that moves the
|
||||
// tag again cannot swap the image under this task's reported digest.
|
||||
for (ContainerDefinition def : launchOrder) {
|
||||
LaunchImage launchImage = lifecycleManager.resolveImageForLaunch(imagesByContainer.get(def),
|
||||
config.services().ecs().imagePullBehavior());
|
||||
imagesByContainer.put(def, launchImage.imageId());
|
||||
if (launchImage.manifestDigest() != null) {
|
||||
imageDigestsByContainer.put(def.getName(), launchImage.manifestDigest());
|
||||
}
|
||||
}
|
||||
|
||||
if (firelensRouter != null) {
|
||||
@@ -489,6 +504,7 @@ public class EcsContainerManager {
|
||||
// Build ECS container model
|
||||
Container container = buildContainer(task.getTaskArn(), def, dockerId, networkBindings, region,
|
||||
metadataIdsByContainer.get(def.getName()));
|
||||
container.setImageDigest(imageDigestsByContainer.get(def.getName()));
|
||||
runtimeContainers.add(container);
|
||||
containerIds.put(def.getName(), dockerId);
|
||||
|
||||
|
||||
+204
-19
@@ -8,19 +8,27 @@ import com.github.dockerjava.api.exception.DockerClientException;
|
||||
import com.github.dockerjava.api.exception.InternalServerErrorException;
|
||||
import com.github.dockerjava.api.model.AuthConfig;
|
||||
import com.github.dockerjava.api.model.Info;
|
||||
import com.github.dockerjava.api.model.PullResponseItem;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig.EcsServiceConfig.ImagePullBehavior;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Ensures each Docker image is pulled only once per platform.
|
||||
* Ensures each Docker image is pulled only once per platform, except for launches that ask
|
||||
* for the ECS agent's pull behaviour through {@link #resolveForLaunch}.
|
||||
* Thread-safe using ConcurrentHashMap for double-checked locking per image.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@@ -30,10 +38,14 @@ public class ImageCacheService {
|
||||
|
||||
static final int MAX_PULL_ATTEMPTS = 3;
|
||||
static final long INITIAL_BACKOFF_MS = 500L;
|
||||
private static final List<String> DOCKER_HUB_PREFIXES = List.of("docker.io/", "index.docker.io/", "library/");
|
||||
private static final Pattern IMAGE_ID = Pattern.compile("sha256:[0-9a-f]{64}");
|
||||
private static final String DIGEST_STATUS = "Digest: ";
|
||||
|
||||
private final DockerClient dockerClient;
|
||||
private final List<EmulatorConfig.DockerConfig.RegistryCredential> registryCredentials;
|
||||
private final Map<ImageKey, String> resolvedImages = new ConcurrentHashMap<>();
|
||||
private final Set<ImageKey> pulledImages = ConcurrentHashMap.newKeySet();
|
||||
private final ConcurrentHashMap<String, Object> locks = new ConcurrentHashMap<>();
|
||||
private volatile String daemonPlatform;
|
||||
|
||||
@@ -48,6 +60,9 @@ public class ImageCacheService {
|
||||
}
|
||||
|
||||
public String ensureImageExists(String imageUri, String platform) {
|
||||
if (isImageId(imageUri)) {
|
||||
return existingImageId(imageUri);
|
||||
}
|
||||
boolean explicitPlatform = platform != null && !platform.isBlank();
|
||||
String requestedPlatform = explicitPlatform ? platform.trim() : daemonPlatform();
|
||||
ImageKey imageKey = new ImageKey(imageUri, requestedPlatform);
|
||||
@@ -68,26 +83,174 @@ public class ImageCacheService {
|
||||
LOG.infov("Image already present locally, skipping pull: {0}", imageUri);
|
||||
return resolvedImage;
|
||||
}
|
||||
LOG.infov("Pulling image: {0}", imageUri);
|
||||
try {
|
||||
runWithRetry(imageUri, MAX_PULL_ATTEMPTS, INITIAL_BACKOFF_MS, () -> {
|
||||
PullImageCmd pullImage = dockerClient.pullImageCmd(imageUri)
|
||||
.withAuthConfig(resolveAuth(imageUri));
|
||||
if (explicitPlatform) {
|
||||
pullImage.withPlatform(requestedPlatform);
|
||||
}
|
||||
pullImage.exec(new PullImageResultCallback())
|
||||
.awaitCompletion(5, TimeUnit.MINUTES);
|
||||
});
|
||||
resolvedImage = resolvedImageReference(imageUri, inspectLocalImage(imageUri));
|
||||
resolvedImages.put(imageKey, resolvedImage);
|
||||
LOG.infov("Image pulled successfully: {0}", imageUri);
|
||||
return resolvedImage;
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException("Interrupted while pulling image: " + imageUri, e);
|
||||
resolvedImage = resolvedImageReference(imageUri,
|
||||
pull(imageKey, explicitPlatform ? requestedPlatform : null).image());
|
||||
resolvedImages.put(imageKey, resolvedImage);
|
||||
return resolvedImage;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the image a container launch runs, pulling it as the ECS agent does under
|
||||
* {@code ECS_IMAGE_PULL_BEHAVIOR}.
|
||||
*
|
||||
* <p>Unlike {@link #ensureImageExists}, this never reuses the id a reference named the first
|
||||
* time it was seen: the local tag is read again on every call, so a tag moved by a pull (this
|
||||
* one or anyone else's) is what the next launch runs. The launch creates its container from the
|
||||
* returned image id rather than from the reference, so a pull by an overlapping launch that
|
||||
* moves the tag again cannot change what this one runs.
|
||||
*/
|
||||
public LaunchImage resolveForLaunch(String imageUri, ImagePullBehavior behavior) {
|
||||
if (isImageId(imageUri)) {
|
||||
return new LaunchImage(existingImageId(imageUri), null);
|
||||
}
|
||||
ImageKey imageKey = new ImageKey(imageUri, daemonPlatform());
|
||||
Object lock = locks.computeIfAbsent(imageUri, k -> new Object());
|
||||
synchronized (lock) {
|
||||
LocalImage image = switch (behavior) {
|
||||
case DEFAULT -> pullOrUseCached(imageKey);
|
||||
case ALWAYS -> pull(imageKey, null);
|
||||
case ONCE -> pulledImages.contains(imageKey) ? cachedOrPull(imageKey) : pull(imageKey, null);
|
||||
case PREFER_CACHED -> cachedOrPull(imageKey);
|
||||
};
|
||||
String imageId = resolvedImageReference(imageUri, image.image());
|
||||
resolvedImages.put(imageKey, imageId);
|
||||
String digest = image.pulledDigest() != null && imageUri.indexOf('@') < 0
|
||||
? image.pulledDigest()
|
||||
: manifestDigest(imageUri, image.image()).orElse(null);
|
||||
return new LaunchImage(imageId, digest);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The image a launch resolved a reference to.
|
||||
*
|
||||
* @param imageId the immutable id of the image the launch runs
|
||||
* @param manifestDigest the image's manifest digest in the repository it was named by, null when
|
||||
* the image was never pulled from or pushed to that repository (a locally built image)
|
||||
*/
|
||||
public record LaunchImage(String imageId, String manifestDigest) {}
|
||||
|
||||
/** Whether a reference is an image id, which names one immutable image and never needs a pull. */
|
||||
public static boolean isImageId(String reference) {
|
||||
return reference != null && IMAGE_ID.matcher(reference).matches();
|
||||
}
|
||||
|
||||
private String existingImageId(String imageId) {
|
||||
InspectImageResponse image = inspectLocalImage(imageId);
|
||||
if (image == null) {
|
||||
throw new DockerClientException("Image no longer exists: " + imageId);
|
||||
}
|
||||
return resolvedImageReference(imageId, image);
|
||||
}
|
||||
|
||||
private LocalImage pullOrUseCached(ImageKey imageKey) {
|
||||
try {
|
||||
return pull(imageKey, null);
|
||||
} catch (RuntimeException e) {
|
||||
InspectImageResponse cached = Thread.currentThread().isInterrupted() ? null : cachedImage(imageKey);
|
||||
if (cached == null) {
|
||||
throw e;
|
||||
}
|
||||
LOG.warnv("Could not pull image {0}, using the cached image {1}: {2}",
|
||||
imageKey.imageUri(), cached.getId(), e.getMessage());
|
||||
return new LocalImage(cached, null);
|
||||
}
|
||||
}
|
||||
|
||||
private LocalImage cachedOrPull(ImageKey imageKey) {
|
||||
InspectImageResponse cached = cachedImage(imageKey);
|
||||
return cached != null ? new LocalImage(cached, null) : pull(imageKey, null);
|
||||
}
|
||||
|
||||
private InspectImageResponse cachedImage(ImageKey imageKey) {
|
||||
InspectImageResponse local = inspectLocalImage(imageKey.imageUri());
|
||||
return matchesPlatform(local, imageKey.platform()) ? local : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls the image and inspects what the reference names afterwards.
|
||||
*
|
||||
* @param platform the platform to ask the registry for, or null for the daemon's own
|
||||
*/
|
||||
private LocalImage pull(ImageKey imageKey, String platform) {
|
||||
String imageUri = imageKey.imageUri();
|
||||
LOG.infov("Pulling image: {0}", imageUri);
|
||||
AtomicReference<ManifestDigestCallback> lastAttempt = new AtomicReference<>();
|
||||
try {
|
||||
runWithRetry(imageUri, MAX_PULL_ATTEMPTS, INITIAL_BACKOFF_MS, () -> {
|
||||
PullImageCmd pullImage = dockerClient.pullImageCmd(imageUri)
|
||||
.withAuthConfig(resolveAuth(imageUri));
|
||||
if (platform != null) {
|
||||
pullImage.withPlatform(platform);
|
||||
}
|
||||
ManifestDigestCallback callback = new ManifestDigestCallback();
|
||||
lastAttempt.set(callback);
|
||||
pullImage.<PullImageResultCallback>exec(callback)
|
||||
.awaitCompletion(5, TimeUnit.MINUTES);
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException("Interrupted while pulling image: " + imageUri, e);
|
||||
}
|
||||
InspectImageResponse pulled = inspectLocalImage(imageUri);
|
||||
pulledImages.add(imageKey);
|
||||
LOG.infov("Image pulled successfully: {0}", imageUri);
|
||||
return new LocalImage(pulled, lastAttempt.get().digest);
|
||||
}
|
||||
|
||||
/**
|
||||
* The digest of the manifest the reference resolved to, from the repository it names. A
|
||||
* reference pinned by digest is its own answer; otherwise it is the image's repo digest for
|
||||
* that repository, which Docker records when it pulls or pushes the image. An image can hold
|
||||
* several digests for one repository: on the classic image store, manifests that share one
|
||||
* image config; on the containerd store, an index and its platform manifest. The containerd
|
||||
* store's image id is the digest of the manifest the tag names, so a digest equal to the id
|
||||
* is the answer there. Otherwise nothing local says which one the tag names, and a launch that
|
||||
* did not pull reports none rather than a digest the tag may no longer name.
|
||||
*/
|
||||
static Optional<String> manifestDigest(String imageUri, InspectImageResponse image) {
|
||||
int at = imageUri.indexOf('@');
|
||||
if (at >= 0) {
|
||||
return Optional.of(imageUri.substring(at + 1));
|
||||
}
|
||||
List<String> repoDigests = image.getRepoDigests();
|
||||
if (repoDigests == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String repository = normalizedRepository(imageUri);
|
||||
Set<String> digests = new LinkedHashSet<>();
|
||||
for (String repoDigest : repoDigests) {
|
||||
int separator = repoDigest.indexOf('@');
|
||||
if (separator > 0 && normalizedRepository(repoDigest.substring(0, separator)).equals(repository)) {
|
||||
digests.add(repoDigest.substring(separator + 1));
|
||||
}
|
||||
}
|
||||
if (digests.size() > 1) {
|
||||
if (digests.contains(image.getId())) {
|
||||
return Optional.of(image.getId());
|
||||
}
|
||||
LOG.debugv("Image {0} holds several digests for {1}, reporting none: {2}",
|
||||
image.getId(), imageUri, digests);
|
||||
return Optional.empty();
|
||||
}
|
||||
return digests.stream().findFirst();
|
||||
}
|
||||
|
||||
/** The repository a reference names, without its tag and with Docker Hub's implied prefixes. */
|
||||
private static String normalizedRepository(String reference) {
|
||||
String repository = reference;
|
||||
int lastSlash = repository.lastIndexOf('/');
|
||||
int tagSeparator = repository.lastIndexOf(':');
|
||||
if (tagSeparator > lastSlash) {
|
||||
repository = repository.substring(0, tagSeparator);
|
||||
}
|
||||
for (String prefix : DOCKER_HUB_PREFIXES) {
|
||||
if (repository.startsWith(prefix)) {
|
||||
repository = repository.substring(prefix.length());
|
||||
}
|
||||
}
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,6 +383,28 @@ public class ImageCacheService {
|
||||
|
||||
private record ImageKey(String imageUri, String platform) {}
|
||||
|
||||
/**
|
||||
* The image a reference names locally.
|
||||
*
|
||||
* @param pulledDigest the manifest digest the registry reported when this launch pulled the
|
||||
* image, null when the image came from the cache
|
||||
*/
|
||||
private record LocalImage(InspectImageResponse image, String pulledDigest) {}
|
||||
|
||||
/** Records the manifest digest the daemon reports once a pull has resolved the reference. */
|
||||
private static final class ManifestDigestCallback extends PullImageResultCallback {
|
||||
private volatile String digest;
|
||||
|
||||
@Override
|
||||
public void onNext(PullResponseItem item) {
|
||||
String status = item.getStatus();
|
||||
if (status != null && status.startsWith(DIGEST_STATUS)) {
|
||||
digest = status.substring(DIGEST_STATUS.length()).trim();
|
||||
}
|
||||
super.onNext(item);
|
||||
}
|
||||
}
|
||||
|
||||
private AuthConfig resolveAuth(String imageUri) {
|
||||
String host = extractRegistryHost(imageUri);
|
||||
for (EmulatorConfig.DockerConfig.RegistryCredential cred : registryCredentials) {
|
||||
|
||||
Reference in new issue
Block a user