GeezerVison is showing github.com — Merge branch 'master' into master · ConnorLinfoot/docker-java@dd570e8
File treeExpand file treeCollapse file tree Open diff view settings docker-java-api/src/main/java/com/github/dockerjava/api docker-java-core/src/main/java/com/github/dockerjava/core docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5 docker-java-transport-okhttp/src/main/java/com/github/dockerjava/okhttp docker-java-transport/src/main/java/com/github/dockerjava/transport docker-java/src/test/java/com/github/dockerjava
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docker-java-api/src/main/java/com/github/dockerjava/api/DockerClientDelegate.java +515Lines changed: 515 additions & 0 deletions Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: docker-java-api/src/main/java/com/github/dockerjava/api/model/LogConfig.java +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -76,7 +76,8 @@ public enum LoggingType { | 76 | 76 | AWSLOGS("awslogs"), | 77 | 77 | DB("db"), // Synology specific driver | 78 | 78 | SPLUNK("splunk"), | 79 | | - GCPLOGS("gcplogs"); | | 79 | + GCPLOGS("gcplogs"), | | 80 | + LOKI("loki"); | 80 | 81 |
| 81 | 82 | private String type; | 82 | 83 |
| |
Collapse file Copy file name to clipboardExpand all lines: docker-java-api/src/main/java/com/github/dockerjava/api/model/PropagationMode.java +16-1Lines changed: 16 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,11 +13,20 @@ public enum PropagationMode { | 13 | 13 | /** shared */ | 14 | 14 | SHARED("shared"), | 15 | 15 |
| | 16 | + /** rshared */ | | 17 | + RSHARED("rshared"), | | 18 | + | 16 | 19 | /** slave */ | 17 | 20 | SLAVE("slave"), | 18 | 21 |
| | 22 | + /** rslave */ | | 23 | + RSLAVE("rslave"), | | 24 | + | 19 | 25 | /** private */ | 20 | | - PRIVATE("private"); | | 26 | + PRIVATE("private"), | | 27 | + | | 28 | + /** rprivate */ | | 29 | + RPRIVATE("rprivate"); | 21 | 30 |
| 22 | 31 | /** | 23 | 32 | * The default {@link PropagationMode}: {@link #DEFAULT} | @@ -39,10 +48,16 @@ public static PropagationMode fromString(String v) { | 39 | 48 | switch (v) { | 40 | 49 | case "shared": | 41 | 50 | return SHARED; | | 51 | + case "rshared": | | 52 | + return RSHARED; | 42 | 53 | case "slave": | 43 | 54 | return SLAVE; | | 55 | + case "rslave": | | 56 | + return RSLAVE; | 44 | 57 | case "private": | 45 | 58 | return PRIVATE; | | 59 | + case "rprivate": | | 60 | + return RPRIVATE; | 46 | 61 | default: | 47 | 62 | return DEFAULT; | 48 | 63 | } | |
Collapse file Copy file name to clipboard +67Lines changed: 67 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | | 2 | + <modelVersion>4.0.0</modelVersion> | | 3 | + | | 4 | + <parent> | | 5 | + <groupId>com.github.docker-java</groupId> | | 6 | + <artifactId>docker-java-parent</artifactId> | | 7 | + <version>0-SNAPSHOT</version> | | 8 | + <relativePath>../pom.xml</relativePath> | | 9 | + </parent> | | 10 | + | | 11 | + <artifactId>docker-java-bom</artifactId> | | 12 | + <packaging>pom</packaging> | | 13 | + | | 14 | + <name>docker-java</name> | | 15 | + <url>https://github.com/docker-java/docker-java</url> | | 16 | + <description>Java API Client for Docker</description> | | 17 | + | | 18 | + <dependencyManagement> | | 19 | + <dependencies> | | 20 | + <dependency> | | 21 | + <groupId>${project.groupId}</groupId> | | 22 | + <artifactId>docker-java</artifactId> | | 23 | + <version>${project.version}</version> | | 24 | + </dependency> | | 25 | + <dependency> | | 26 | + <groupId>${project.groupId}</groupId> | | 27 | + <artifactId>docker-java-api</artifactId> | | 28 | + <version>${project.version}</version> | | 29 | + </dependency> | | 30 | + <dependency> | | 31 | + <groupId>${project.groupId}</groupId> | | 32 | + <artifactId>docker-java-core</artifactId> | | 33 | + <version>${project.version}</version> | | 34 | + </dependency> | | 35 | + <dependency> | | 36 | + <groupId>${project.groupId}</groupId> | | 37 | + <artifactId>docker-java-transport</artifactId> | | 38 | + <version>${project.version}</version> | | 39 | + </dependency> | | 40 | + <dependency> | | 41 | + <groupId>${project.groupId}</groupId> | | 42 | + <artifactId>docker-java-transport-httpclient5</artifactId> | | 43 | + <version>${project.version}</version> | | 44 | + </dependency> | | 45 | + <dependency> | | 46 | + <groupId>${project.groupId}</groupId> | | 47 | + <artifactId>docker-java-transport-jersey</artifactId> | | 48 | + <version>${project.version}</version> | | 49 | + </dependency> | | 50 | + <dependency> | | 51 | + <groupId>${project.groupId}</groupId> | | 52 | + <artifactId>docker-java-transport-netty</artifactId> | | 53 | + <version>${project.version}</version> | | 54 | + </dependency> | | 55 | + <dependency> | | 56 | + <groupId>${project.groupId}</groupId> | | 57 | + <artifactId>docker-java-transport-okhttp</artifactId> | | 58 | + <version>${project.version}</version> | | 59 | + </dependency> | | 60 | + <dependency> | | 61 | + <groupId>${project.groupId}</groupId> | | 62 | + <artifactId>docker-java-transport-zerodep</artifactId> | | 63 | + <version>${project.version}</version> | | 64 | + </dependency> | | 65 | + </dependencies> | | 66 | + </dependencyManagement> | | 67 | +</project> |
Collapse file Copy file name to clipboardExpand all lines: docker-java-core/src/main/java/com/github/dockerjava/core/DefaultDockerClientConfig.java +20-4Lines changed: 20 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | import com.github.dockerjava.core.NameParser.HostnameReposName; | 7 | 7 | import com.github.dockerjava.core.NameParser.ReposTag; | 8 | 8 | import org.apache.commons.lang.StringUtils; | | 9 | +import org.apache.commons.lang.SystemUtils; | 9 | 10 | import org.apache.commons.lang.builder.EqualsBuilder; | 10 | 11 | import org.apache.commons.lang.builder.HashCodeBuilder; | 11 | 12 | import org.apache.commons.lang.builder.ToStringBuilder; | @@ -58,6 +59,10 @@ public class DefaultDockerClientConfig implements Serializable, DockerClientConf | 58 | 59 |
| 59 | 60 | static final Properties DEFAULT_PROPERTIES = new Properties(); | 60 | 61 |
| | 62 | + static final String DEFAULT_DOCKER_HOST = "unix:///var/run/docker.sock"; | | 63 | + | | 64 | + static final String WINDOWS_DEFAULT_DOCKER_HOST = "npipe:////./pipe/docker_engine"; | | 65 | + | 61 | 66 | static { | 62 | 67 | CONFIG_KEYS.add(DOCKER_HOST); | 63 | 68 | CONFIG_KEYS.add(DOCKER_TLS_VERIFY); | @@ -69,7 +74,6 @@ public class DefaultDockerClientConfig implements Serializable, DockerClientConf | 69 | 74 | CONFIG_KEYS.add(REGISTRY_EMAIL); | 70 | 75 | CONFIG_KEYS.add(REGISTRY_URL); | 71 | 76 |
| 72 | | - DEFAULT_PROPERTIES.put(DOCKER_HOST, "unix:///var/run/docker.sock"); | 73 | 77 | DEFAULT_PROPERTIES.put(DOCKER_CONFIG, "${user.home}/.docker"); | 74 | 78 | DEFAULT_PROPERTIES.put(REGISTRY_URL, "https://index.docker.io/v1/"); | 75 | 79 | DEFAULT_PROPERTIES.put(REGISTRY_USERNAME, "${user.name}"); | @@ -337,8 +341,12 @@ public static class Builder { | 337 | 341 | * registry.email, DOCKER_CERT_PATH, and DOCKER_CONFIG. | 338 | 342 | */ | 339 | 343 | public Builder withProperties(Properties p) { | 340 | | - return withDockerHost(p.getProperty(DOCKER_HOST)) | 341 | | - .withDockerTlsVerify(p.getProperty(DOCKER_TLS_VERIFY)) | | 344 | + | | 345 | + if (p.getProperty(DOCKER_HOST) != null) { | | 346 | + withDockerHost(p.getProperty(DOCKER_HOST)); | | 347 | + } | | 348 | + | | 349 | + return withDockerTlsVerify(p.getProperty(DOCKER_TLS_VERIFY)) | 342 | 350 | .withDockerConfig(p.getProperty(DOCKER_CONFIG)) | 343 | 351 | .withDockerCertPath(p.getProperty(DOCKER_CERT_PATH)) | 344 | 352 | .withApiVersion(p.getProperty(API_VERSION)) | @@ -412,6 +420,10 @@ public final Builder withDockerTlsVerify(Boolean dockerTlsVerify) { | 412 | 420 | return this; | 413 | 421 | } | 414 | 422 |
| | 423 | + public final boolean isDockerHostSetExplicitly() { | | 424 | + return dockerHost != null; | | 425 | + } | | 426 | + | 415 | 427 | /** | 416 | 428 | * Overrides the default {@link SSLConfig} that is used when calling {@link Builder#withDockerTlsVerify(java.lang.Boolean)} and | 417 | 429 | * {@link Builder#withDockerCertPath(String)}. This way it is possible to pass a custom {@link SSLConfig} to the resulting | @@ -435,7 +447,11 @@ public DefaultDockerClientConfig build() { | 435 | 447 | sslConfig = customSslConfig; | 436 | 448 | } | 437 | 449 |
| 438 | | - return new DefaultDockerClientConfig(dockerHost, dockerConfig, apiVersion, registryUrl, registryUsername, | | 450 | + URI dockerHostUri = dockerHost != null | | 451 | + ? dockerHost | | 452 | + : URI.create(SystemUtils.IS_OS_WINDOWS ? WINDOWS_DEFAULT_DOCKER_HOST : DEFAULT_DOCKER_HOST); | | 453 | + | | 454 | + return new DefaultDockerClientConfig(dockerHostUri, dockerConfig, apiVersion, registryUrl, registryUsername, | 439 | 455 | registryPassword, registryEmail, sslConfig); | 440 | 456 | } | 441 | 457 |
| |
Collapse file Copy file name to clipboardExpand all lines: docker-java-transport-httpclient5/src/main/java/com/github/dockerjava/httpclient5/ApacheDockerHttpClientImpl.java +12-2Lines changed: 12 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | package com.github.dockerjava.httpclient5; | 2 | 2 |
| 3 | 3 | import com.github.dockerjava.transport.DockerHttpClient; | 4 | | -import com.github.dockerjava.transport.DomainSocket; | 5 | 4 | import com.github.dockerjava.transport.NamedPipeSocket; | 6 | 5 | import com.github.dockerjava.transport.SSLConfig; | | 6 | +import com.github.dockerjava.transport.UnixSocket; | 7 | 7 | import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; | 8 | 8 | import org.apache.hc.client5.http.config.RequestConfig; | 9 | 9 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; | | 24 | 24 | import org.apache.hc.core5.http.config.RegistryBuilder; | 25 | 25 | import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy; | 26 | 26 | import org.apache.hc.core5.http.impl.io.EmptyInputStream; | | 27 | +import org.apache.hc.core5.http.io.SocketConfig; | 27 | 28 | import org.apache.hc.core5.http.io.entity.ByteArrayEntity; | 28 | 29 | import org.apache.hc.core5.http.io.entity.InputStreamEntity; | 29 | 30 | import org.apache.hc.core5.http.protocol.BasicHttpContext; | 30 | 31 | import org.apache.hc.core5.http.protocol.HttpContext; | 31 | 32 | import org.apache.hc.core5.net.URIAuthority; | | 33 | +import org.apache.hc.core5.util.TimeValue; | | 34 | +import org.apache.hc.core5.util.Timeout; | 32 | 35 | import org.slf4j.Logger; | 33 | 36 | import org.slf4j.LoggerFactory; | 34 | 37 |
| @@ -93,6 +96,13 @@ protected ApacheDockerHttpClientImpl( | 93 | 96 | null | 94 | 97 | ) | 95 | 98 | ); | | 99 | + // See https://github.com/docker-java/docker-java/pull/1590#issuecomment-870581289 | | 100 | + connectionManager.setDefaultSocketConfig( | | 101 | + SocketConfig.copy(SocketConfig.DEFAULT) | | 102 | + .setSoTimeout(Timeout.ZERO_MILLISECONDS) | | 103 | + .build() | | 104 | + ); | | 105 | + connectionManager.setValidateAfterInactivity(TimeValue.NEG_ONE_SECOND); | 96 | 106 | connectionManager.setMaxTotal(maxConnections); | 97 | 107 | connectionManager.setDefaultMaxPerRoute(maxConnections); | 98 | 108 | RequestConfig.Builder defaultRequest = RequestConfig.custom(); | @@ -134,7 +144,7 @@ private Registry<ConnectionSocketFactory> createConnectionSocketFactoryRegistry( | 134 | 144 | .register("unix", new PlainConnectionSocketFactory() { | 135 | 145 | @Override | 136 | 146 | public Socket createSocket(HttpContext context) throws IOException { | 137 | | - return DomainSocket.get(dockerHost.getPath()); | | 147 | + return UnixSocket.get(dockerHost.getPath()); | 138 | 148 | } | 139 | 149 | }) | 140 | 150 | .register("npipe", new PlainConnectionSocketFactory() { | |
Collapse file Copy file name to clipboardExpand all lines: docker-java-transport-okhttp/src/main/java/com/github/dockerjava/okhttp/UnixSocketFactory.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | package com.github.dockerjava.okhttp; | 2 | 2 |
| 3 | | -import com.github.dockerjava.transport.DomainSocket; | | 3 | +import com.github.dockerjava.transport.UnixSocket; | 4 | 4 |
| 5 | 5 | import javax.net.SocketFactory; | 6 | 6 | import java.io.IOException; | @@ -18,7 +18,7 @@ class UnixSocketFactory extends SocketFactory { | 18 | 18 | @Override | 19 | 19 | public Socket createSocket() { | 20 | 20 | try { | 21 | | - return DomainSocket.get(socketPath); | | 21 | + return UnixSocket.get(socketPath); | 22 | 22 | } catch (IOException e) { | 23 | 23 | throw new RuntimeException(e); | 24 | 24 | } | |
Collapse file Copy file name to clipboardExpand all lines: docker-java-transport/src/main/java/com/github/dockerjava/transport/DomainSocket.java +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -130,7 +130,9 @@ public void close() throws IOException { | 130 | 130 | * @param path the path to the domain socket | 131 | 131 | * @return a {@link DomainSocket} instance | 132 | 132 | * @throws IOException if the socket cannot be opened | | 133 | + * @deprecated use {@link UnixSocket#get(String)} | 133 | 134 | */ | | 135 | + @Deprecated | 134 | 136 | public static DomainSocket get(String path) throws IOException { | 135 | 137 | if (Platform.isMac() || isBsdPlatform()) { | 136 | 138 | return new BsdDomainSocket(path); | |
Collapse file Copy file name to clipboard +88Lines changed: 88 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package com.github.dockerjava.transport; | | 2 | + | | 3 | +import java.io.IOException; | | 4 | +import java.io.InputStream; | | 5 | +import java.io.OutputStream; | | 6 | +import java.net.Socket; | | 7 | +import java.net.SocketAddress; | | 8 | +import java.net.SocketException; | | 9 | +import java.nio.channels.Channels; | | 10 | +import java.nio.channels.SocketChannel; | | 11 | + | | 12 | +public class UnixSocket extends AbstractSocket { | | 13 | + | | 14 | + /** | | 15 | + * Return a new {@link Socket} for the given path. Will use JDK's {@link java.net.UnixDomainSocketAddress} | | 16 | + * if available and fallback to {@link DomainSocket} otherwise. | | 17 | + * | | 18 | + * @param path the path to the domain socket | | 19 | + * @return a {@link Socket} instance | | 20 | + * @throws IOException if the socket cannot be opened | | 21 | + */ | | 22 | + public static Socket get(String path) throws IOException { | | 23 | + try { | | 24 | + return new UnixSocket(path); | | 25 | + } catch (Exception e) { | | 26 | + //noinspection deprecation | | 27 | + return DomainSocket.get(path); | | 28 | + } | | 29 | + } | | 30 | + | | 31 | + private final SocketAddress socketAddress; | | 32 | + | | 33 | + private final SocketChannel socketChannel; | | 34 | + | | 35 | + private UnixSocket(String path) throws Exception { | | 36 | + Class<?> unixDomainSocketAddress = Class.forName("java.net.UnixDomainSocketAddress"); | | 37 | + this.socketAddress = | | 38 | + (SocketAddress) unixDomainSocketAddress.getMethod("of", String.class) | | 39 | + .invoke(null, path); | | 40 | + this.socketChannel = SocketChannel.open(this.socketAddress); | | 41 | + } | | 42 | + | | 43 | + @Override | | 44 | + public InputStream getInputStream() throws IOException { | | 45 | + if (isClosed()) { | | 46 | + throw new SocketException("Socket is closed"); | | 47 | + } | | 48 | + if (!isConnected()) { | | 49 | + throw new SocketException("Socket is not connected"); | | 50 | + } | | 51 | + if (isInputShutdown()) { | | 52 | + throw new SocketException("Socket input is shutdown"); | | 53 | + } | | 54 | + | | 55 | + return Channels.newInputStream(socketChannel); | | 56 | + } | | 57 | + | | 58 | + @Override | | 59 | + public OutputStream getOutputStream() throws IOException { | | 60 | + if (isClosed()) { | | 61 | + throw new SocketException("Socket is closed"); | | 62 | + } | | 63 | + if (!isConnected()) { | | 64 | + throw new SocketException("Socket is not connected"); | | 65 | + } | | 66 | + if (isOutputShutdown()) { | | 67 | + throw new SocketException("Socket output is shutdown"); | | 68 | + } | | 69 | + | | 70 | + return Channels.newOutputStream(socketChannel); | | 71 | + } | | 72 | + | | 73 | + @Override | | 74 | + public SocketAddress getLocalSocketAddress() { | | 75 | + return socketAddress; | | 76 | + } | | 77 | + | | 78 | + @Override | | 79 | + public SocketAddress getRemoteSocketAddress() { | | 80 | + return socketAddress; | | 81 | + } | | 82 | + | | 83 | + @Override | | 84 | + public void close() throws IOException { | | 85 | + super.close(); | | 86 | + this.socketChannel.close(); | | 87 | + } | | 88 | +} |
Collapse file Copy file name to clipboardExpand all lines: docker-java/src/test/java/com/github/dockerjava/cmd/CustomCommandIT.java +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | package com.github.dockerjava.cmd; | 2 | 2 |
| 3 | 3 | import com.github.dockerjava.core.DockerClientImpl; | | 4 | +import com.github.dockerjava.core.DockerRule; | 4 | 5 | import com.github.dockerjava.transport.DockerHttpClient; | 5 | 6 | import com.github.dockerjava.transport.DockerHttpClient.Request; | 6 | 7 | import com.github.dockerjava.transport.DockerHttpClient.Response; | @@ -17,7 +18,8 @@ public class CustomCommandIT extends CmdIT { | 17 | 18 |
| 18 | 19 | @Test | 19 | 20 | public void testCustomCommand() throws Exception { | 20 | | - DockerHttpClient httpClient = ((DockerClientImpl) dockerRule.getClient()).getHttpClient(); | | 21 | + DockerClientImpl dockerClient = getFactoryType().createDockerClient(DockerRule.config(null)); | | 22 | + DockerHttpClient httpClient = dockerClient.getHttpClient(); | 21 | 23 |
| 22 | 24 | Assume.assumeNotNull(httpClient); | 23 | 25 |
| |
|