Skip to content

Fix default docker-java.properties to match with docker CLI defaults #590

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

Merged
merged 1 commit into from
Jun 3, 2016
Merged
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
16 changes: 10 additions & 6 deletions src/main/java/com/github/dockerjava/core/DockerClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,16 @@ private String checkDockerCertPath(boolean dockerTlsVerify, String dockerCertPat

if (!certPath.exists()) {
throw new DockerClientException(
"Certificate path (DOCKER_CERT_PATH) '" + dockerCertPath + "' doesn't exist.");
"Enabled TLS verification (DOCKER_TLS_VERIFY=1) but certificate path (DOCKER_CERT_PATH) '" + dockerCertPath
+ "' doesn't exist.");
}

if (certPath.isDirectory()) {
return dockerCertPath;
} else {
throw new DockerClientException(
"Certificate path (DOCKER_CERT_PATH) '" + dockerCertPath + "' doesn't point to a directory.");
"Enabled TLS verification (DOCKER_TLS_VERIFY=1) but certificate path (DOCKER_CERT_PATH) '" + dockerCertPath
+ "' doesn't point to a directory.");
}
}
} else {
Expand Down Expand Up @@ -375,7 +377,6 @@ public final DockerClientConfigBuilder withDockerHost(String dockerHost) {
return this;
}


public final DockerClientConfigBuilder withApiVersion(RemoteApiVersion apiVersion) {
this.apiVersion = apiVersion.getVersion();
return this;
Expand Down Expand Up @@ -417,8 +418,12 @@ public final DockerClientConfigBuilder withDockerConfig(String dockerConfig) {
}

public final DockerClientConfigBuilder withDockerTlsVerify(String dockerTlsVerify) {
String trimmed = dockerTlsVerify.trim();
this.dockerTlsVerify = "true".equalsIgnoreCase(trimmed) || "1".equals(trimmed);
if (dockerTlsVerify != null) {
String trimmed = dockerTlsVerify.trim();
this.dockerTlsVerify = "true".equalsIgnoreCase(trimmed) || "1".equals(trimmed);
} else {
this.dockerTlsVerify = false;
}
return this;
}

Expand All @@ -433,4 +438,3 @@ public DockerClientConfig build() {
}
}
}

This file was deleted.

12 changes: 3 additions & 9 deletions src/main/resources/docker-java.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#docker.io.url=https://localhost:2376
#docker.io.dockerCertPath=${user.home}/.docker
#docker.io.dockerCfgPath=${user.home}/.dockercfg
#docker.io.username=${user.name}
#docker.io.serverAddress=https://index.docker.io/v1/
#
DOCKER_HOST=tcp://localhost:2376
DOCKER_TLS_VERIFY=1
DOCKER_HOST=unix:///var/run/docker.sock
DOCKER_CONFIG=${user.home}/.docker
DOCKER_CERT_PATH=${user.home}/.docker/certs
#DOCKER_TLS_VERIFY=1
#DOCKER_CERT_PATH=${user.home}/.docker/certs

api.version=
registry.url=https://index.docker.io/v1/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.Is.is;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertNull;

import java.lang.reflect.Field;
import java.net.URI;
Expand Down Expand Up @@ -54,8 +53,6 @@ public void environmentDockerHost() throws Exception {
// and it looks to be SSL disabled
env.remove("DOCKER_CERT_PATH");



// given default cert path
Properties systemProperties = new Properties();
systemProperties.setProperty("user.name", "someUserName");
Expand All @@ -82,7 +79,6 @@ public void environment() throws Exception {
env.put(DockerClientConfig.DOCKER_CERT_PATH, dockerCertPath());
env.put(DockerClientConfig.DOCKER_TLS_VERIFY, "1");


// when you build a config
DockerClientConfig config = buildConfig(env, new Properties());

Expand All @@ -106,12 +102,12 @@ public void defaults() throws Exception {
DockerClientConfig config = buildConfig(Collections.<String, String> emptyMap(), systemProperties);

// then the cert path is as expected
assertEquals(config.getDockerHost(), URI.create("tcp://localhost:2376"));
assertEquals(config.getDockerHost(), URI.create("unix:///var/run/docker.sock"));
assertEquals(config.getRegistryUsername(), "someUserName");
assertEquals(config.getRegistryUrl(), AuthConfig.DEFAULT_SERVER_ADDRESS);
assertEquals(config.getApiVersion(), RemoteApiVersion.unknown());
assertEquals(config.getDockerConfig(), homeDir() + "/.docker");
assertEquals(config.getDockerCertPath(), homeDir() + "/.docker/certs");
assertNull(config.getDockerCertPath());
}

@Test
Expand Down