Skip to content
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

Upgrade docker client #1534

Merged
merged 5 commits into from
May 23, 2017
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
6 changes: 6 additions & 0 deletions SingularityExecutor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<artifactId>docker-client</artifactId>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.hubspot.singularity.executor.utils.DockerUtils;
import com.hubspot.singularity.runner.base.shared.ProcessFailedException;
import com.hubspot.singularity.runner.base.shared.SimpleProcessManager;
import com.spotify.docker.client.DockerException;
import com.spotify.docker.client.exceptions.DockerException;

@Singleton
public class SingularityExecutorThreadChecker {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

public class SingularityExecutorDockerAuthConfig {

private boolean fromDockerConfig;

private String username;
private String password;
private String email;
private String serverAddress;

public boolean isFromDockerConfig() {
return fromDockerConfig;
}

public void setFromDockerConfig(boolean fromDockerConfig) {
this.fromDockerConfig = fromDockerConfig;
}

public String getUsername() {
return username;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import com.google.common.base.Throwables;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
Expand All @@ -21,7 +22,7 @@
import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DefaultDockerClient.Builder;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.messages.AuthConfig;
import com.spotify.docker.client.messages.RegistryAuth;

public class SingularityExecutorModule extends AbstractModule {

Expand Down Expand Up @@ -108,12 +109,22 @@ public DockerClient providesDockerClient(SingularityExecutorConfiguration config
if(configuration.getDockerAuthConfig().isPresent()) {
SingularityExecutorDockerAuthConfig authConfig = configuration.getDockerAuthConfig().get();

dockerClientBuilder.authConfig(AuthConfig.builder()
.email(authConfig.getEmail())
.username(authConfig.getUsername())
.password(authConfig.getPassword())
.serverAddress(authConfig.getServerAddress())
.build());
if(authConfig.isFromDockerConfig()) {
try {
dockerClientBuilder.registryAuth(RegistryAuth.fromDockerConfig().build());

} catch(IOException e) {
throw Throwables.propagate(e);
}
}
else {
dockerClientBuilder.registryAuth(RegistryAuth.builder()
.email(authConfig.getEmail())
.username(authConfig.getUsername())
.password(authConfig.getPassword())
.serverAddress(authConfig.getServerAddress())
.build());
}
}

return dockerClientBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import com.hubspot.singularity.executor.utils.DockerUtils;
import com.hubspot.singularity.runner.base.shared.ExceptionChainParser;
import com.hubspot.singularity.runner.base.shared.SimpleProcessManager;
import com.spotify.docker.client.ContainerNotFoundException;
import com.spotify.docker.client.DockerException;
import com.spotify.docker.client.exceptions.ContainerNotFoundException;
import com.spotify.docker.client.exceptions.DockerException;
import com.spotify.docker.client.messages.ContainerInfo;

public class SingularityExecutorTaskCleanup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.hubspot.singularity.executor.utils.DockerUtils;
import com.hubspot.singularity.executor.utils.ExecutorUtils;
import com.hubspot.singularity.runner.base.shared.ProcessFailedException;
import com.spotify.docker.client.DockerException;
import com.spotify.docker.client.exceptions.DockerException;

public class SingularityExecutorTaskProcessBuilder implements Callable<ProcessBuilder> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import com.google.inject.Inject;
import com.hubspot.singularity.executor.config.SingularityExecutorConfiguration;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.DockerException;
import com.spotify.docker.client.DockerClient.RemoveContainerParam;
import com.spotify.docker.client.exceptions.DockerException;
import com.spotify.docker.client.messages.Container;
import com.spotify.docker.client.messages.ContainerInfo;

Expand Down Expand Up @@ -97,7 +98,7 @@ public void stopContainer(final String containerId, final int timeout) throws Do
public void removeContainer(final String containerId, final boolean removeRunning) throws DockerException {
Callable<Void> callable = new Callable<Void>() {
@Override public Void call() throws Exception {
dockerClient.removeContainer(containerId, removeRunning);
dockerClient.removeContainer(containerId, RemoveContainerParam.removeVolumes(removeRunning));
return null;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ public class SingularityExecutorConfigurationTest {
@Test
public void itLoadsDockerAuthConfig() {
SingularityExecutorConfiguration config = loadConfig("config/executor-conf-dockerauth.yaml");

assertThat(config.getDockerAuthConfig().isPresent()).isTrue();
assertThat(config.getDockerAuthConfig().get().isFromDockerConfig()).isFalse();
assertThat(config.getDockerAuthConfig().get().getUsername()).isEqualTo("dockeruser");
assertThat(config.getDockerAuthConfig().get().getPassword()).isEqualTo("dockerpassword");
assertThat(config.getDockerAuthConfig().get().getServerAddress()).isEqualTo("https://private.docker.registry/path");
}

@Test
public void itLoadsDockerAuthFromConfigFileIfSpecified() {
SingularityExecutorConfiguration config = loadConfig("config/executor-conf-dockerauth-fromconfig.yaml");

assertThat(config.getDockerAuthConfig().isPresent()).isTrue();
assertThat(config.getDockerAuthConfig().get().isFromDockerConfig()).isTrue();
}

private SingularityExecutorConfiguration loadConfig(String file) {
try {
ObjectMapper mapper = new SingularityRunnerBaseModule(null).providesYamlMapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
executor:

dockerAuthConfig:
fromDockerConfig: true
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<dependency>
<groupId>com.spotify</groupId>
<artifactId>docker-client</artifactId>
<version>3.1.5</version>
<version>8.4.0</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand All @@ -192,6 +192,10 @@
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>aopalliance-repackaged</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down