Skip to content
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 @@ -42,6 +42,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -206,8 +207,9 @@ public Execution() {
}

ImageAction.add(step.image, run);
String dockerHost = envHost.get("DOCKER_HOST", "unix:///var/run/docker.sock");
getContext().newBodyInvoker().
withContext(BodyInvoker.mergeLauncherDecorators(getContext().get(LauncherDecorator.class), new Decorator(container, envHost, ws, toolName, dockerVersion))).
withContext(BodyInvoker.mergeLauncherDecorators(getContext().get(LauncherDecorator.class), new Decorator(container, dockerHost, envHost, ws, toolName, dockerVersion))).
withCallback(new Callback(container, toolName)).
start();
return false;
Expand Down Expand Up @@ -240,14 +242,16 @@ private static class Decorator extends LauncherDecorator implements Serializable

private static final long serialVersionUID = 1;
private final String container;
private final String dockerHost;
private final String[] envHost;
private final String ws;
private final @CheckForNull String toolName;
private final boolean hasEnv;
private final boolean hasWorkdir;

Decorator(String container, EnvVars envHost, String ws, String toolName, VersionNumber dockerVersion) {
Decorator(String container, String dockerHost, EnvVars envHost, String ws, String toolName, VersionNumber dockerVersion) {
this.container = container;
this.dockerHost = dockerHost;
this.envHost = Util.mapToEnv(envHost);
this.ws = ws;
this.toolName = toolName;
Expand Down Expand Up @@ -332,6 +336,8 @@ private static class Decorator extends LauncherDecorator implements Serializable
System.arraycopy(originalMasks, 0, masks, prefix.size(), originalMasks.length);
starter.masks(masks);

starter.envs(Collections.singletonMap("DOCKER_HOST", dockerHost));

return super.launch(starter);
}
@Override public void kill(Map<String,String> modelEnvVars) throws IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,23 @@ private static final class Execution extends SynchronousNonBlockingStepExecution
}
}

@Test
@Issue("JENKINS-64954")
public void dockerConnectionTracking() {
story.then(r -> {
DockerTestUtil.assumeDocker();
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {\n"
+ " docker.image(\"docker:dind\").withRun(\"--privileged\", \"dockerd --tls=false --host 0.0.0.0\") { dockerContainer ->\n"
+ " docker.image(\"docker:dind\").inside(\"--link ${dockerContainer.id}:docker --entrypoint=''\") {\n"
+ " docker.withServer(\"tcp://docker\") {\n"
+ " sh \"echo with nested docker\"\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("with nested docker", b);
});
}
}