Skip to content

Commit

Permalink
fix(core): autodetect unix socket path for the docker runner
Browse files Browse the repository at this point in the history
close #601
  • Loading branch information
tchiotludo committed Aug 2, 2022
1 parent 5a565bf commit f51d4d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ public static class DockerOptions {
title = "Docker api uri"
)
@PluginProperty(dynamic = true)
@Builder.Default
private final String dockerHost = "unix:///var/run/docker.sock";
private String dockerHost;

@Schema(
title = "Docker config file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ public DockerScriptRunner(ApplicationContext applicationContext) {
private DockerClient getDockerClient(AbstractBash abstractBash, RunContext runContext, Path workingDirectory) throws IllegalVariableEvaluationException, IOException {
DefaultDockerClientConfig.Builder dockerClientConfigBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder();

String dockerHost = null;
if (abstractBash.getDockerOptions() != null) {
if (abstractBash.getDockerOptions().getDockerHost() != null) {
dockerClientConfigBuilder.withDockerHost(runContext.render(abstractBash.getDockerOptions().getDockerHost()));
dockerHost = runContext.render(abstractBash.getDockerOptions().getDockerHost());
}

if (abstractBash.getDockerOptions().getDockerConfig() != null) {
Expand All @@ -66,6 +67,16 @@ private DockerClient getDockerClient(AbstractBash abstractBash, RunContext runCo
}
}

if (dockerHost != null) {
dockerClientConfigBuilder.withDockerHost(dockerHost);
} else {
if (Files.exists(Path.of("/var/run/docker.sock"))) {
dockerClientConfigBuilder.withDockerHost("unix:///var/run/docker.sock");
} else if (Files.exists(Path.of("/dind/docker.sock"))) {
dockerClientConfigBuilder.withDockerHost("unix:///dind/docker.sock");
}
}

DockerClientConfig dockerClientConfig = dockerClientConfigBuilder.build();

ApacheDockerHttpClient dockerHttpClient = new Builder()
Expand Down

0 comments on commit f51d4d2

Please sign in to comment.