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

Add uid to docker config #1167

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -18,7 +18,8 @@ public record DockerEnvDescription(
List<String> envVars, // In format <NAME>=<value>
@Nullable
String networkMode,
DockerClientConfig dockerClientConfig
DockerClientConfig dockerClientConfig,
String uid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's name it user as in the docker config

) {

public static Builder newBuilder() {
Expand All @@ -45,13 +46,16 @@ public record MountDescription(
) {}

public static class Builder {
private static final String ROOT_USER_UID = "0";

String name = null;
String image = null;
boolean gpu = false;
List<MountDescription> mounts = new ArrayList<>();
List<String> envVars = new ArrayList<>();
String networkMode = null;
DockerClientConfig dockerClientConfig;
String uid = ROOT_USER_UID;

public Builder withName(String name) {
this.name = name;
Expand Down Expand Up @@ -93,11 +97,16 @@ public Builder withDockerClientConfig(DockerClientConfig dockerClientConfig) {
return this;
}

public Builder withUID(String uid) {
this.uid = uid;
return this;
}

public DockerEnvDescription build() {
if (StringUtils.isBlank(name)) {
name = "job-" + RandomStringUtils.randomAlphanumeric(5);
}
return new DockerEnvDescription(name, image, mounts, gpu, envVars, networkMode, dockerClientConfig);
return new DockerEnvDescription(name, image, mounts, gpu, envVars, networkMode, dockerClientConfig, uid);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class DockerEnvironment extends BaseEnvironment {

private static final Logger LOG = LogManager.getLogger(DockerEnvironment.class);
private static final long GB_AS_BYTES = 1073741824;
private static final String ROOT_USER_UID = "0";

@Nullable
public String containerId = null;
Expand Down Expand Up @@ -119,7 +118,7 @@ public void install(LogStream outStream, LogStream errStream) throws Environment
.withAttachStdout(true)
.withAttachStderr(true)
.withTty(true)
.withUser(ROOT_USER_UID)
.withUser(config.uid())
.withEnv(config.envVars())
.withEntrypoint("/bin/sh")
.exec();
Expand Down Expand Up @@ -161,7 +160,7 @@ public LzyProcess runProcess(String[] command, @Nullable String[] envp, @Nullabl
LOG.info("Creating cmd {}", String.join(" ", command));
final ExecCreateCmd execCmd = client.execCreateCmd(containerId)
.withCmd(command)
.withUser(ROOT_USER_UID)
.withUser(config.uid())
.withAttachStdout(true)
.withAttachStderr(true);

Expand Down
Loading