mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ecs): launch task images for the task definition's runtimePlatform architecture (#6952)
This commit is contained in:
1 parent
a5254bdc0c
commit
4364310b95
19 files changed
+283
-127
No files matched your search
+26
-3
@@ -138,9 +138,29 @@ public class ContainerLifecycleManager {
|
||||
return createAndStart(spec, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a disposable container for a specific Docker platform, reclaiming its anonymous
|
||||
* volumes if startup fails.
|
||||
*
|
||||
* @param platform Docker platform, such as {@code linux/amd64}, or null for the daemon's own
|
||||
*/
|
||||
public ContainerInfo createAndStartEphemeral(ContainerSpec spec, String platform) {
|
||||
return createAndStart(spec, platform, true);
|
||||
}
|
||||
|
||||
private ContainerInfo createAndStart(ContainerSpec spec, boolean removeAnonymousVolumes) {
|
||||
String resolvedImage = imageCacheService.ensureImageExists(spec.image());
|
||||
String containerId = create(spec, resolvedImage, null, removeAnonymousVolumes);
|
||||
return createAndStart(spec, resolvedImage, null, removeAnonymousVolumes);
|
||||
}
|
||||
|
||||
private ContainerInfo createAndStart(ContainerSpec spec, String platform, boolean removeAnonymousVolumes) {
|
||||
String resolvedImage = imageCacheService.ensureImageExists(spec.image(), platform);
|
||||
return createAndStart(spec, resolvedImage, platform, removeAnonymousVolumes);
|
||||
}
|
||||
|
||||
private ContainerInfo createAndStart(ContainerSpec spec, String resolvedImage, String platform,
|
||||
boolean removeAnonymousVolumes) {
|
||||
String containerId = create(spec, resolvedImage, platform, removeAnonymousVolumes);
|
||||
try {
|
||||
return withPublishedHostPorts(startCreated(containerId, spec), spec);
|
||||
} catch (RuntimeException failure) {
|
||||
@@ -165,9 +185,12 @@ 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.
|
||||
*
|
||||
* @param platform the Docker platform the container runs, such as {@code linux/amd64}, or null
|
||||
* for the daemon's own
|
||||
*/
|
||||
public LaunchImage resolveImageForLaunch(String image, ImagePullBehavior behavior) {
|
||||
return imageCacheService.resolveForLaunch(image, behavior);
|
||||
public LaunchImage resolveImageForLaunch(String image, ImagePullBehavior behavior, String platform) {
|
||||
return imageCacheService.resolveForLaunch(image, behavior, platform);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-3
@@ -271,6 +271,9 @@ public class EcsContainerManager {
|
||||
|
||||
List<ContainerDefinition> launchOrder = orderForDependencies(
|
||||
launchOrder(taskDef.getContainerDefinitions(), firelensRouter), firelensRouter);
|
||||
String platform = taskDef.getRuntimePlatform() != null
|
||||
? taskDef.getRuntimePlatform().dockerPlatform()
|
||||
: null;
|
||||
|
||||
// Task-level volumes consumed by per-container mountPoints: host volumes map their
|
||||
// name -> absolute host source path; efsVolumeConfiguration volumes map their
|
||||
@@ -326,7 +329,7 @@ public class EcsContainerManager {
|
||||
// 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());
|
||||
config.services().ecs().imagePullBehavior(), platform);
|
||||
imagesByContainer.put(def, launchImage.imageId());
|
||||
if (launchImage.manifestDigest() != null) {
|
||||
imageDigestsByContainer.put(def.getName(), launchImage.manifestDigest());
|
||||
@@ -558,7 +561,7 @@ public class EcsContainerManager {
|
||||
|
||||
String dockerId;
|
||||
if (def == firelensRouter) {
|
||||
dockerId = lifecycleManager.create(spec);
|
||||
dockerId = lifecycleManager.create(spec, platform);
|
||||
try {
|
||||
copyFirelensConfig(dockerId, firelensConfig, isFluentdRouter(firelensRouter),
|
||||
firelensExternalConfig, firelensBackoffMillis);
|
||||
@@ -569,7 +572,7 @@ public class EcsContainerManager {
|
||||
}
|
||||
fluentHost = inspectContainerIp(dockerId);
|
||||
} else {
|
||||
ContainerInfo info = lifecycleManager.createAndStartEphemeral(spec);
|
||||
ContainerInfo info = lifecycleManager.createAndStartEphemeral(spec, platform);
|
||||
dockerId = info.containerId();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,25 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
*
|
||||
* <p>Modelled for RegisterTaskDefinition/DescribeTaskDefinition round-trip fidelity — a client that
|
||||
* reads back what it registered (Terraform, or a deploy tool verifying its own write) must see the
|
||||
* platform it asked for. Floci runs every task on the host's own architecture, so the value has no
|
||||
* effect on where a local task is placed.
|
||||
* platform it asked for. A task launch also runs its images for the architecture named here, so an
|
||||
* {@code X86_64} task runs an amd64 image on an arm64 Docker host under emulation, as it would run on
|
||||
* an x86_64 Fargate host.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public record RuntimePlatform(String cpuArchitecture, String operatingSystemFamily) {
|
||||
|
||||
/**
|
||||
* The Docker platform a task with this runtime platform runs its images for, or null when no
|
||||
* architecture is named and the task runs on the Docker host's own.
|
||||
*/
|
||||
public String dockerPlatform() {
|
||||
if (cpuArchitecture == null) {
|
||||
return null;
|
||||
}
|
||||
return switch (cpuArchitecture) {
|
||||
case "X86_64" -> "linux/amd64";
|
||||
case "ARM64" -> "linux/arm64";
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
+17
-10
@@ -105,19 +105,26 @@ public class ImageCacheService {
|
||||
* 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.
|
||||
*
|
||||
* @param platform the Docker platform the launch runs, such as {@code linux/amd64}, or null for
|
||||
* the daemon's own. A local image of another platform is never reused for it.
|
||||
*/
|
||||
public LaunchImage resolveForLaunch(String imageUri, ImagePullBehavior behavior) {
|
||||
public LaunchImage resolveForLaunch(String imageUri, ImagePullBehavior behavior, String platform) {
|
||||
if (isImageId(imageUri)) {
|
||||
return new LaunchImage(existingImageId(imageUri), null);
|
||||
}
|
||||
ImageKey imageKey = new ImageKey(imageUri, daemonPlatform());
|
||||
boolean explicitPlatform = platform != null && !platform.isBlank();
|
||||
ImageKey imageKey = new ImageKey(imageUri, explicitPlatform ? platform.trim() : daemonPlatform());
|
||||
String pullPlatform = explicitPlatform ? imageKey.platform() : null;
|
||||
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);
|
||||
case DEFAULT -> pullOrUseCached(imageKey, pullPlatform);
|
||||
case ALWAYS -> pull(imageKey, pullPlatform);
|
||||
case ONCE -> pulledImages.contains(imageKey)
|
||||
? cachedOrPull(imageKey, pullPlatform)
|
||||
: pull(imageKey, pullPlatform);
|
||||
case PREFER_CACHED -> cachedOrPull(imageKey, pullPlatform);
|
||||
};
|
||||
String imageId = resolvedImageReference(imageUri, image.image());
|
||||
resolvedImages.put(imageKey, imageId);
|
||||
@@ -150,9 +157,9 @@ public class ImageCacheService {
|
||||
return resolvedImageReference(imageId, image);
|
||||
}
|
||||
|
||||
private LocalImage pullOrUseCached(ImageKey imageKey) {
|
||||
private LocalImage pullOrUseCached(ImageKey imageKey, String platform) {
|
||||
try {
|
||||
return pull(imageKey, null);
|
||||
return pull(imageKey, platform);
|
||||
} catch (RuntimeException e) {
|
||||
InspectImageResponse cached = Thread.currentThread().isInterrupted() ? null : cachedImage(imageKey);
|
||||
if (cached == null) {
|
||||
@@ -164,9 +171,9 @@ public class ImageCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
private LocalImage cachedOrPull(ImageKey imageKey) {
|
||||
private LocalImage cachedOrPull(ImageKey imageKey, String platform) {
|
||||
InspectImageResponse cached = cachedImage(imageKey);
|
||||
return cached != null ? new LocalImage(cached, null) : pull(imageKey, null);
|
||||
return cached != null ? new LocalImage(cached, null) : pull(imageKey, platform);
|
||||
}
|
||||
|
||||
private InspectImageResponse cachedImage(ImageKey imageKey) {
|
||||
|
||||
Reference in new issue
Block a user