Skip to content

configurable docker command via env vars #265

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -196,10 +196,10 @@ public Execution() {
volumes.put(tmp, tmp);
}

String command = launcher.isUnix() ? "cat" : "cmd.exe";
String[] command = launcher.isUnix() ? DockerClient.getUnixCommand(envHost, "cat") : "cmd.exe".split(" ");
container = dockerClient.run(env, step.image, step.args, ws, volumes, volumesFromContainers, envReduced, dockerClient.whoAmI(), /* expected to hang until killed */ command);
final List<String> ps = dockerClient.listProcess(env, container);
if (!ps.contains(command)) {
if (!ps.contains(Arrays.toString(command))) {
listener.error(
"The container started but didn't run the expected command. " +
"Please double check your ENTRYPOINT does execute the command passed as docker run argument, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public class DockerClient {
private final @CheckForNull Node node;
private final @CheckForNull String toolName;

public static String[] getUnixCommand(EnvVars env, String defaultCmd) {
return env.get("DEFAULT_DOCKER_COMMAND", defaultCmd).split(" ");
}

public DockerClient(@NonNull Launcher launcher, @CheckForNull Node node, @CheckForNull String toolName) {
this.launcher = launcher;
this.node = node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public static EnvVars newDockerLaunchEnv() {
return env;
}

public static EnvVars newHostEnv() {
EnvVars env = new EnvVars();
env.put("DEFAULT_DOCKER_COMMAND", "sh -c sleep INF");
return env;
}

private DockerTestUtil() {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ public void setup() throws Exception {
@Test
public void test_run() throws IOException, InterruptedException {
EnvVars launchEnv = DockerTestUtil.newDockerLaunchEnv();
String[] defaultCommand = DockerClient.getUnixCommand(DockerTestUtil.newHostEnv(), "cat");
String containerId =
dockerClient.run(launchEnv, "learn/tutorial", null, null, Collections.<String, String>emptyMap(), Collections.<String>emptyList(), new EnvVars(),
dockerClient.whoAmI(), "cat");
dockerClient.whoAmI(), defaultCommand);
Assert.assertEquals(64, containerId.length());
ContainerRecord containerRecord = dockerClient.getContainerRecord(launchEnv, containerId);
Assert.assertEquals(dockerClient.inspect(launchEnv, "learn/tutorial", ".Id"), containerRecord.getImageId());
Expand Down