Skip to content

Commit 04eaf1f

Browse files
committed
apply a rebased and squashed unixsocket-branch with a working ssl config.
other changes: - make all unit tests succeed on Windows - only create a container when needed - read the complete response when copying a file from a container
1 parent d1ea20f commit 04eaf1f

25 files changed

+581
-65
lines changed

pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
</developer>
4040
</developers>
4141

42+
<repositories>
43+
<repository>
44+
<id>jcenter</id>
45+
<url>http://jcenter.bintray.com</url>
46+
</repository>
47+
</repositories>
48+
4249
<properties>
4350
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4451
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@@ -64,6 +71,7 @@
6471
<jnr.unixsocket.version>0.3</jnr.unixsocket.version>
6572
<guava.version>18.0</guava.version>
6673
<bouncycastle.version>1.51</bouncycastle.version>
74+
<unix-socket-factory.version>2014-11-16T14-41-27</unix-socket-factory.version>
6775

6876
<!--test dependencies -->
6977
<version.logback>1.0.1</version.logback>
@@ -93,12 +101,23 @@
93101
<!-- <artifactId>jersey-jetty-connector</artifactId> -->
94102
<!-- <version>${jersey.version}</version> -->
95103
<!-- </dependency> -->
104+
<dependency>
105+
<groupId>org.glassfish.jersey.connectors</groupId>
106+
<artifactId>jersey-apache-connector</artifactId>
107+
<version>${jersey.version}</version>
108+
</dependency>
96109
<dependency>
97110
<groupId>org.glassfish.jersey.core</groupId>
98111
<artifactId>jersey-client</artifactId>
99112
<version>${jersey.version}</version>
100113
</dependency>
101114

115+
<dependency>
116+
<groupId>de.gesellix</groupId>
117+
<artifactId>unix-socket-factory</artifactId>
118+
<version>${unix-socket-factory.version}</version>
119+
</dependency>
120+
102121
<dependency>
103122
<groupId>org.apache.commons</groupId>
104123
<artifactId>commons-compress</artifactId>

src/main/java/com/github/dockerjava/api/command/EventCallback.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ public interface EventCallback {
99
public void onEvent(Event event);
1010
public void onException(Throwable throwable);
1111
public void onCompletion(int numEvents);
12+
public boolean isReceiving();
1213
}

src/main/java/com/github/dockerjava/api/model/AuthConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AuthConfig {
88
/**
99
* For backwards compatibility. Make sure you update the properties if you change this.
1010
*
11-
* @see /docker.io.properties
11+
* @see "/docker.io.properties"
1212
*/
1313
public static final String DEFAULT_SERVER_ADDRESS = "https://index.docker.io/v1/";
1414

src/main/java/com/github/dockerjava/core/DockerClientConfig.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class DockerClientConfig implements Serializable {
3333
private static final String DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY = "docker.io.enableLoggingFilter";
3434
private static final String DOCKER_IO_DOCKER_CERT_PATH_PROPERTY = "docker.io.dockerCertPath";
3535
private static final String DOCKER_IO_DOCKER_CFG_PATH_PROPERTY = "docker.io.dockerCfgPath";
36+
// connection pooling properties
37+
private static final String DOCKER_IO_MAX_PER_ROUTE_PROPERTY = "docker.io.perRouteConnections";
38+
private static final String DOCKER_IO_MAX_TOTAL_PROPERTY = "docker.io.totalConnections";
3639
/**
3740
* A map from the environment name to the interval name.
3841
*/
@@ -49,13 +52,18 @@ public class DockerClientConfig implements Serializable {
4952
.put("DOCKER_CFG_PATH", DOCKER_IO_DOCKER_CFG_PATH_PROPERTY)
5053
.build();
5154
private static final String DOCKER_IO_PROPERTIES_PROPERTY = "docker.io.properties";
52-
private final URI uri;
55+
private URI uri;
5356
private final String version, username, password, email, serverAddress, dockerCfgPath;
5457
private final Integer readTimeout;
5558
private final boolean loggingFilterEnabled;
5659
private final SSLConfig sslConfig;
60+
61+
private final int maxTotalConnections;
62+
private final int maxPerRouteConnections;
5763

58-
DockerClientConfig(URI uri, String version, String username, String password, String email, String serverAddress, String dockerCfgPath, Integer readTimeout, boolean loggingFilterEnabled, SSLConfig sslConfig) {
64+
DockerClientConfig(URI uri, String version, String username, String password, String email, String serverAddress,
65+
String dockerCfgPath, Integer readTimeout, boolean loggingFilterEnabled, SSLConfig sslConfig,
66+
int maxTotalConns, int maxPerRouteConns) {
5967
this.uri = uri;
6068
this.version = version;
6169
this.username = username;
@@ -66,6 +74,8 @@ public class DockerClientConfig implements Serializable {
6674
this.readTimeout = readTimeout;
6775
this.loggingFilterEnabled = loggingFilterEnabled;
6876
this.sslConfig = sslConfig;
77+
this.maxTotalConnections = maxTotalConns;
78+
this.maxPerRouteConnections = maxPerRouteConns;
6979
}
7080

7181
private static Properties loadIncludedDockerProperties(Properties systemProperties) {
@@ -194,6 +204,10 @@ public URI getUri() {
194204
return uri;
195205
}
196206

207+
public void setUri(URI uri) {
208+
this.uri = uri;
209+
}
210+
197211
public String getVersion() {
198212
return version;
199213
}
@@ -329,7 +343,7 @@ public String toString() {
329343
public static class DockerClientConfigBuilder {
330344
private URI uri;
331345
private String version, username, password, email, serverAddress, dockerCfgPath;
332-
private Integer readTimeout;
346+
private Integer readTimeout, maxTotalConnections, maxPerRouteConnections;
333347
private boolean loggingFilterEnabled;
334348
private SSLConfig sslConfig;
335349

@@ -349,7 +363,10 @@ public DockerClientConfigBuilder withProperties(Properties p) {
349363
.withReadTimeout(Integer.valueOf(p.getProperty(DOCKER_IO_READ_TIMEOUT_PROPERTY, "0")))
350364
.withLoggingFilter(Boolean.valueOf(p.getProperty(DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY, "true")))
351365
.withDockerCertPath(p.getProperty(DOCKER_IO_DOCKER_CERT_PATH_PROPERTY))
352-
.withDockerCfgPath(p.getProperty(DOCKER_IO_DOCKER_CFG_PATH_PROPERTY));
366+
.withDockerCfgPath(p.getProperty(DOCKER_IO_DOCKER_CFG_PATH_PROPERTY))
367+
.withMaxPerRouteConnections(Integer.valueOf(p.getProperty(DOCKER_IO_MAX_PER_ROUTE_PROPERTY, "2")))
368+
.withMaxTotalConnections(Integer.valueOf(p.getProperty(DOCKER_IO_MAX_TOTAL_PROPERTY, "20")))
369+
;
353370
}
354371

355372
public final DockerClientConfigBuilder withUri(String uri) {
@@ -387,6 +404,16 @@ public final DockerClientConfigBuilder withReadTimeout(Integer readTimeout) {
387404
this.readTimeout = readTimeout;
388405
return this;
389406
}
407+
408+
public final DockerClientConfigBuilder withMaxTotalConnections(Integer maxTotalConnections) {
409+
this.maxTotalConnections = maxTotalConnections;
410+
return this;
411+
}
412+
413+
public final DockerClientConfigBuilder withMaxPerRouteConnections(Integer maxPerRouteConnections) {
414+
this.maxPerRouteConnections = maxPerRouteConnections;
415+
return this;
416+
}
390417

391418
public final DockerClientConfigBuilder withLoggingFilter(boolean loggingFilterEnabled) {
392419
this.loggingFilterEnabled = loggingFilterEnabled;
@@ -420,8 +447,18 @@ public DockerClientConfig build() {
420447
dockerCfgPath,
421448
readTimeout,
422449
loggingFilterEnabled,
423-
sslConfig
450+
sslConfig,
451+
maxTotalConnections,
452+
maxPerRouteConnections
424453
);
425454
}
426455
}
456+
457+
public int getMaxTotalConnections() {
458+
return maxTotalConnections;
459+
}
460+
461+
public int getMaxPerRoutConnections() {
462+
return maxPerRouteConnections;
463+
}
427464
}

src/main/java/com/github/dockerjava/core/DockerClientImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88
import java.io.InputStream;
99

1010
import com.github.dockerjava.api.DockerClient;
11-
import com.github.dockerjava.api.DockerClientException;
1211
import com.github.dockerjava.api.command.*;
1312
import com.github.dockerjava.api.model.AuthConfig;
14-
import com.github.dockerjava.core.NameParser.HostnameReposName;
15-
import com.github.dockerjava.core.NameParser.ReposTag;
1613
import com.github.dockerjava.core.command.*;
1714
import com.google.common.base.Preconditions;
1815

1916
/**
2017
* @author Konstantin Pelykh (kpelykh@gmail.com)
2118
*
22-
* @see https://github.com/docker/docker/blob/master/api/client/commands.go
19+
* @see "https://github.com/docker/docker/blob/master/api/client/commands.go"
2320
*/
2421
public class DockerClientImpl implements Closeable, DockerClient {
2522

src/main/java/com/github/dockerjava/core/LocalDirectorySSLConfig.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package com.github.dockerjava.core;
22

3+
import com.github.dockerjava.api.DockerClientException;
34
import com.google.common.base.Objects;
45
import com.google.common.base.Preconditions;
5-
6-
import com.github.dockerjava.api.DockerClientException;
7-
86
import org.bouncycastle.jce.provider.BouncyCastleProvider;
97
import org.glassfish.jersey.SslConfigurator;
108

9+
import javax.net.ssl.SSLContext;
1110
import java.io.Serializable;
1211
import java.security.KeyStore;
1312
import java.security.Security;
1413

15-
import javax.net.ssl.SSLContext;
16-
1714
/**
1815
* SSL Config from local files.
1916
*/
@@ -41,9 +38,6 @@ public SSLContext getSSLContext() {
4138

4239
Security.addProvider(new BouncyCastleProvider());
4340

44-
KeyStore keyStore = CertificateUtils.createKeyStore(dockerCertPath);
45-
KeyStore trustStore = CertificateUtils.createTrustStore(dockerCertPath);
46-
4741
// properties acrobatics not needed for java > 1.6
4842
String httpProtocols = System.getProperty("https.protocols");
4943
System.setProperty("https.protocols", "TLSv1");
@@ -52,9 +46,9 @@ public SSLContext getSSLContext() {
5246
System.setProperty("https.protocols", httpProtocols);
5347
}
5448

55-
sslConfig.keyStore(keyStore);
49+
sslConfig.keyStore(CertificateUtils.createKeyStore(dockerCertPath));
5650
sslConfig.keyStorePassword("docker");
57-
sslConfig.trustStore(trustStore);
51+
sslConfig.trustStore(CertificateUtils.createTrustStore(dockerCertPath));
5852

5953
return sslConfig.createSSLContext();
6054

src/main/java/com/github/dockerjava/core/SSLConfig.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.github.dockerjava.core;
22

3-
import java.security.KeyManagementException;
4-
import java.security.KeyStoreException;
5-
import java.security.NoSuchAlgorithmException;
6-
import java.security.UnrecoverableKeyException;
3+
import java.security.*;
74

85
import javax.net.ssl.SSLContext;
96

0 commit comments

Comments
 (0)