fix(lambda): preserve Docker provided runtime bootstrap paths (#5974)

Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-19 10:47:58 -04:00
1 parent 4c9deed379
commit ca47df9ec5
6 files changed
+199 -84

No files matched your search

@@ -37,6 +37,7 @@ import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -383,16 +384,6 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
copyDirToContainer(dockerClient, containerId, codePath, TASK_DIR, fn.getFunctionName());
}
// For provided runtimes, also copy the 'bootstrap' file to /var/runtime (RUNTIME_DIR)
if (isProvidedRuntime(fn.getRuntime())) {
Path bootstrapPath = codePath.resolve("bootstrap");
if (Files.exists(bootstrapPath)) {
copyFileToContainer(dockerClient, containerId, bootstrapPath, RUNTIME_DIR, "bootstrap", fn.getFunctionName());
} else {
LOG.warnv("Provided runtime function {0} is missing 'bootstrap' file in {1}",
fn.getFunctionName(), fn.getCodeLocalPath());
}
}
}
// 3. Copy layer contents into /opt (layers are merged in order)
@@ -413,6 +404,15 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
}
}
// The base image invokes /var/runtime/bootstrap. Delegate to the original
// package bootstrap, or the merged layers when the package has none.
// This also works with hot-reload and read-only code-volume mounts.
if (isProvidedRuntime(fn.getRuntime()) && !"Image".equals(fn.getPackageType())) {
RetryingTarCopier.copyBytes(dockerClient, containerId, RUNTIME_DIR, "bootstrap",
ProvidedRuntimeBootstrap.SCRIPT.getBytes(StandardCharsets.UTF_8), 0755,
COPY_MAX_ATTEMPTS, COPY_RETRY_BACKOFF_MS);
}
// Now start the container with code in place
lifecycleManager.startCreated(containerId, spec);
watchForUnexpectedExit(dockerClient, containerId, runtimeApiServer);
@@ -1325,20 +1325,6 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
return false;
}
private void copyFileToContainer(DockerClient dockerClient, String containerId,
Path sourceFile, String remotePath, String entryName, String functionName) {
copyFileToContainer(dockerClient, containerId, sourceFile, remotePath, entryName, functionName,
COPY_MAX_ATTEMPTS, COPY_RETRY_BACKOFF_MS);
}
void copyFileToContainer(DockerClient dockerClient, String containerId,
Path sourceFile, String remotePath, String entryName, String functionName,
int maxAttempts, long backoffMillis) {
RetryingTarCopier.copyFile(dockerClient, containerId, remotePath, entryName, sourceFile,
0755, maxAttempts, backoffMillis);
LOG.debugv("Copied file {0} as {1} into container {2} at {3}", sourceFile, entryName, containerId, remotePath);
}
private static boolean isProvidedRuntime(String runtime) {
return runtime != null && runtime.startsWith("provided");
}
@@ -0,0 +1,25 @@
package io.github.hectorvent.floci.services.lambda.launcher;
/**
* Keeps the image's runtime entrypoint while executing the supplied bootstrap in
* its package or layer directory. Moving the supplied file changes its {@code $0}
* and breaks runtimes that locate companion files relative to that path.
*/
final class ProvidedRuntimeBootstrap {
static final String SCRIPT = """
#!/bin/sh
set -eu
if [ -e /var/task/bootstrap ]; then
exec /var/task/bootstrap "$@"
fi
if [ -e /opt/bootstrap ]; then
exec /opt/bootstrap "$@"
fi
echo 'no bootstrap found at /var/task/bootstrap or /opt/bootstrap' >&2
exit 127
""";
private ProvidedRuntimeBootstrap() {
}
}