mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(lambda): honor platform-specific runtime image overrides (#6786)
Select runtime images with the effective Docker platform while preserving runtime-wide defaults, explicit platform precedence and code-volume helper platform. Signed-off-by: Andre Kurait <akurait@amazon.com> Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
80dbdbc0f8
commit
a46a2b32fd
10 files changed
+144
-30
No files matched your search
@@ -3021,7 +3021,7 @@ public interface EmulatorConfig {
|
||||
@WithDefault("public.ecr.aws") // partition-literal: configurable; ECR Public exists only in the commercial partition
|
||||
String ecrBaseUri();
|
||||
|
||||
/** Full image references for individual runtimes, keyed by Lambda runtime identifier. */
|
||||
/** Full image references keyed by runtime, or runtime.os.arch for a selected Docker platform. */
|
||||
Map<String, String> runtimeImages();
|
||||
|
||||
@WithDefault("128")
|
||||
|
||||
+14
-12
@@ -221,10 +221,11 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
Optional<SessionCreds> roleCredentials = Optional.empty();
|
||||
try {
|
||||
|
||||
// Resolve image
|
||||
LambdaDockerFlags dockerFlags = configuredDockerFlags();
|
||||
// Resolve the image for the same platform used by container creation.
|
||||
String image = "Image".equals(fn.getPackageType()) && fn.getImageUri() != null
|
||||
? fn.getImageUri()
|
||||
: imageResolver.resolve(fn.getRuntime());
|
||||
: imageResolver.resolve(fn.getRuntime(), requestedDockerPlatform(fn, dockerFlags).orElse(null));
|
||||
|
||||
// If this is an AWS-shaped ECR URI, rewrite it to Floci's loopback registry
|
||||
image = ecrRegistryManager.rewriteImageUri(image);
|
||||
@@ -244,7 +245,6 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
+ LambdaLogDestinations.logStreamSuffix(fn, shortId);
|
||||
String lambdaRegion = extractRegionFromArn(fn.getFunctionArn(), config.defaultRegion());
|
||||
String lambdaAccountId = AwsArnUtils.accountOrDefault(fn.getFunctionArn(), config.defaultAccountId());
|
||||
LambdaDockerFlags dockerFlags = configuredDockerFlags();
|
||||
|
||||
// Build env vars
|
||||
List<String> env = new ArrayList<>();
|
||||
@@ -551,19 +551,21 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
};
|
||||
}
|
||||
|
||||
private String createContainer(ContainerSpec spec, LambdaFunction fn, LambdaDockerFlags dockerFlags) {
|
||||
private Optional<String> requestedDockerPlatform(LambdaFunction fn, LambdaDockerFlags dockerFlags) {
|
||||
if (dockerFlags.platform() != null) {
|
||||
return lifecycleManager.create(spec, dockerFlags.platform());
|
||||
return Optional.of(dockerFlags.platform());
|
||||
}
|
||||
if (!config.services().lambda().honourArchitectures()) {
|
||||
return lifecycleManager.create(spec);
|
||||
}
|
||||
Optional<String> platform = dockerPlatform(fn);
|
||||
if (platform.isEmpty()) {
|
||||
return config.services().lambda().honourArchitectures() ? dockerPlatform(fn) : Optional.empty();
|
||||
}
|
||||
|
||||
private String createContainer(ContainerSpec spec, LambdaFunction fn, LambdaDockerFlags dockerFlags) {
|
||||
Optional<String> platform = requestedDockerPlatform(fn, dockerFlags);
|
||||
if (platform.isEmpty() && config.services().lambda().honourArchitectures()) {
|
||||
throw new IllegalStateException("Invalid persisted architectures "
|
||||
+ fn.getArchitectures() + " for function '" + fn.getFunctionName() + "'");
|
||||
}
|
||||
return lifecycleManager.create(spec, platform.get());
|
||||
return platform.map(value -> lifecycleManager.create(spec, value))
|
||||
.orElseGet(() -> lifecycleManager.create(spec));
|
||||
}
|
||||
|
||||
private LambdaDockerFlags configuredDockerFlags() {
|
||||
@@ -1017,7 +1019,7 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
acquirePopulatePermit(fn.getFunctionName());
|
||||
String helperId = null;
|
||||
try {
|
||||
helperId = createContainer(helperSpec, fn, LambdaDockerFlags.parse(null));
|
||||
helperId = createContainer(helperSpec, fn, configuredDockerFlags());
|
||||
lifecycleManager.startCreated(helperId, helperSpec);
|
||||
copyDirToContainerStrict(lifecycleManager.getDockerClient(), helperId,
|
||||
Path.of(fn.getCodeLocalPath()), TASK_DIR, fn.getFunctionName());
|
||||
|
||||
+15
-2
@@ -53,6 +53,11 @@ public class ImageResolver {
|
||||
}
|
||||
|
||||
public String resolve(String runtime) {
|
||||
return resolve(runtime, null);
|
||||
}
|
||||
|
||||
/** A platform-specific override precedes the runtime-wide image when a launcher selects a platform. */
|
||||
public String resolve(String runtime, String platform) {
|
||||
if (runtime == null || runtime.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValueException", "Runtime is required", 400);
|
||||
}
|
||||
@@ -65,8 +70,16 @@ public class ImageResolver {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"The runtime parameter " + runtime + " is not supported.", 400);
|
||||
}
|
||||
if (runtimeImages != null && runtimeImages.containsKey(runtime)) {
|
||||
return runtimeImages.get(runtime);
|
||||
if (runtimeImages != null) {
|
||||
if (platform != null) {
|
||||
String override = runtimeImages.get(runtime + "." + platform.replace('/', '.'));
|
||||
if (override != null) {
|
||||
return override;
|
||||
}
|
||||
}
|
||||
if (runtimeImages.containsKey(runtime)) {
|
||||
return runtimeImages.get(runtime);
|
||||
}
|
||||
}
|
||||
return baseUri + "/lambda/" + image;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user