Skip to content

Commit

Permalink
Update to docker-java 3.2.12 (#4459)
Browse files Browse the repository at this point in the history
* Try `docker-java` 3.2.12

* use shaded configuration

* Update build.gradle
  • Loading branch information
bsideup authored Sep 15, 2021
1 parent 79b064b commit 5e88d74
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
10 changes: 6 additions & 4 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ dependencies {

shaded 'org.awaitility:awaitility:4.1.0'

api "com.github.docker-java:docker-java-api:3.2.11"
shaded platform('com.github.docker-java:docker-java-bom:3.2.12')

shaded ('com.github.docker-java:docker-java-core:3.2.11') {
api "com.github.docker-java:docker-java-api"

shaded ('com.github.docker-java:docker-java-core') {
exclude(group: 'com.github.docker-java', module: 'docker-java-api')
exclude(group: 'com.github.docker-java', module: 'docker-java-transport')
exclude(group: 'com.fasterxml.jackson.core', module: 'jackson-annotations')
Expand All @@ -88,13 +90,13 @@ dependencies {
exclude(group: 'org.apache.commons', module: 'commons-compress')
}

shaded ('com.github.docker-java:docker-java-transport-okhttp:3.2.11') {
shaded ('com.github.docker-java:docker-java-transport-okhttp') {
exclude(group: 'com.github.docker-java', module: 'docker-java-core')
exclude(group: 'net.java.dev.jna')
exclude(group: 'org.slf4j')
}

api 'com.github.docker-java:docker-java-transport-zerodep:3.2.11'
api 'com.github.docker-java:docker-java-transport-zerodep'

shaded "org.yaml:snakeyaml:1.29"

Expand Down
19 changes: 17 additions & 2 deletions core/src/main/java/org/testcontainers/DockerClientFactory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.testcontainers;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.DockerClientDelegate;
import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.command.PullImageCmd;
Expand Down Expand Up @@ -94,7 +95,17 @@ public class DockerClientFactory {
}

public static DockerClient lazyClient() {
return LazyDockerClient.INSTANCE;
return new DockerClientDelegate() {
@Override
protected DockerClient getDockerClient() {
return instance().client();
}

@Override
public String toString() {
return "LazyDockerClient";
}
};
}

/**
Expand Down Expand Up @@ -177,7 +188,11 @@ public DockerClient client() {
final DockerClientProviderStrategy strategy = getOrInitializeStrategy();

log.info("Docker host IP address is {}", strategy.getDockerHostIpAddress());
final DockerClient client = new DelegatingDockerClient(strategy.getDockerClient()) {
final DockerClient client = new DockerClientDelegate() {

@Getter
final DockerClient dockerClient = strategy.getDockerClient();

@Override
public void close() {
throw new IllegalStateException("You should never close the global DockerClient!");
Expand Down
16 changes: 0 additions & 16 deletions core/src/main/java/org/testcontainers/LazyDockerClient.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.core.DockerClientConfig;
import lombok.experimental.Delegate;
import com.github.dockerjava.core.DockerClientConfigDelegate;
import lombok.extern.slf4j.Slf4j;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.RegistryAuthLocator;
Expand All @@ -18,20 +18,18 @@
* TODO move to docker-java
*/
@Slf4j
class AuthDelegatingDockerClientConfig implements DockerClientConfig {

@Delegate(excludes = DelegateExclusions.class)
private DockerClientConfig delegate;
class AuthDelegatingDockerClientConfig extends DockerClientConfigDelegate {

public AuthDelegatingDockerClientConfig(DockerClientConfig delegate) {
this.delegate = delegate;
super(delegate);
}

@Override
public AuthConfig effectiveAuthConfig(String imageName) {
// allow docker-java auth config to be used as a fallback
AuthConfig fallbackAuthConfig;
try {
fallbackAuthConfig = delegate.effectiveAuthConfig(imageName);
fallbackAuthConfig = super.effectiveAuthConfig(imageName);
} catch (Exception e) {
log.debug("Delegate call to effectiveAuthConfig failed with cause: '{}'. " +
"Resolution of auth config will continue using RegistryAuthLocator.",
Expand All @@ -47,8 +45,4 @@ public AuthConfig effectiveAuthConfig(String imageName) {
log.debug("Effective auth config [{}]", toSafeString(effectiveAuthConfig));
return effectiveAuthConfig;
}

private interface DelegateExclusions {
AuthConfig effectiveAuthConfig(String imageName);
}
}

0 comments on commit 5e88d74

Please sign in to comment.