Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft] DockerSandboxedSpawnRunner: support custom container runtimes (like sysbox-runc) #23614

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class DockerCommandLineBuilder {
private Path dockerClient;
private String imageName;
private List<String> commandArguments;
private String containerRuntime;
private Path sandboxExecRoot;
private Map<String, String> environmentVariables;
private Duration timeout;
Expand Down Expand Up @@ -66,6 +67,12 @@ public DockerCommandLineBuilder setCommandArguments(List<String> commandArgument
return this;
}

@CanIgnoreReturnValue
public DockerCommandLineBuilder setContainerRuntime(String containerRuntime) {
this.containerRuntime = containerRuntime;
return this;
}

@CanIgnoreReturnValue
public DockerCommandLineBuilder setSandboxExecRoot(Path sandboxExecRoot) {
this.sandboxExecRoot = sandboxExecRoot;
Expand Down Expand Up @@ -137,6 +144,9 @@ public ImmutableList<String> build() {

dockerCmdLine.add(dockerClient.getPathString());
dockerCmdLine.add("run");
if (!containerRuntime.isEmpty()) {
dockerCmdLine.add("--runtime=" + containerRuntime);
}
dockerCmdLine.add("--rm");
if (createNetworkNamespace) {
dockerCmdLine.add("--network=none");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import com.google.devtools.build.lib.util.ProcessUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;

import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -147,6 +149,8 @@ public static boolean isSupported(CommandEnvironment cmdEnv, Path dockerClient)
private final ProcessWrapper processWrapper;
private final Path sandboxBase;
private final String defaultImage;
@Nullable
private final String containerRuntime;
private final LocalEnvProvider localEnvProvider;
private final String commandId;
private final Reporter reporter;
Expand Down Expand Up @@ -174,6 +178,8 @@ public static boolean isSupported(CommandEnvironment cmdEnv, Path dockerClient)
Path dockerClient,
Path sandboxBase,
String defaultImage,
@Nullable
String containerRuntime,
boolean useCustomizedImages,
TreeDeleter treeDeleter) {
super(cmdEnv);
Expand All @@ -184,6 +190,7 @@ public static boolean isSupported(CommandEnvironment cmdEnv, Path dockerClient)
this.processWrapper = ProcessWrapper.fromCommandEnvironment(cmdEnv);
this.sandboxBase = sandboxBase;
this.defaultImage = defaultImage;
this.containerRuntime = containerRuntime;
this.localEnvProvider = LocalEnvProvider.forCurrentOs(cmdEnv.getClientEnv());
this.commandId = cmdEnv.getCommandId().toString();
this.reporter = cmdEnv.getReporter();
Expand Down Expand Up @@ -259,6 +266,9 @@ protected SandboxedSpawn prepareSpawn(Spawn spawn, SpawnExecutionContext context
|| Spawns.requiresNetwork(spawn, getSandboxOptions().defaultSandboxAllowNetwork)))
.setCommandId(commandId)
.setUuid(uuid);
if (containerRuntime != null) {
cmdLine.setContainerRuntime(containerRuntime);
}
// If uid / gid are -1, we are on an operating system that doesn't require us to set them on the
// Docker invocation. If they're 0, it means we are running as root and don't need to set them.
if (uid > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ private void setup(CommandEnvironment cmdEnv, SpawnStrategyRegistry.Builder buil
pathToDocker,
sandboxBase,
defaultImage,
options.containerRuntime,
useCustomizedImages,
treeDeleter));
spawnRunners.add(spawnRunner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ public ImmutableSet<Path> getInaccessiblePaths(FileSystem fs) {
+ " run', so it supports the same syntax and mechanisms as Docker itself.")
public String dockerImage;

@Option(
name = "experimental_container_runtime",
defaultValue = "",
documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY,
effectTags = {OptionEffectTag.EXECUTION},
help = "specify a custom container runtime like sysbox-runc")
public String containerRuntime;

@Option(
name = "experimental_docker_use_customized_images",
defaultValue = "true",
Expand Down