mirror of https://github.com/apache/jclouds.git
[JCLOUDS-1117] fix for advanced Docker configuration - the Config.Builder should stay unchanged if used
This commit is contained in:
parent
4ef28251c5
commit
d4cf774389
|
@ -89,9 +89,11 @@ public class DockerComputeServiceAdapter implements
|
|||
String loginUserPassword = template.getImage().getDefaultCredentials().getOptionalPassword().or("password");
|
||||
|
||||
DockerTemplateOptions templateOptions = DockerTemplateOptions.class.cast(options);
|
||||
|
||||
Config containerConfig = null;
|
||||
Config.Builder containerConfigBuilder = templateOptions.getConfigBuilder();
|
||||
if (containerConfigBuilder == null) {
|
||||
containerConfigBuilder = Config.builder();
|
||||
containerConfigBuilder = Config.builder().image(imageId);
|
||||
|
||||
containerConfigBuilder.entrypoint(templateOptions.getEntrypoint());
|
||||
containerConfigBuilder.cmd(templateOptions.getCommands());
|
||||
|
@ -147,12 +149,9 @@ public class DockerComputeServiceAdapter implements
|
|||
hostConfigBuilder.networkMode(templateOptions.getNetworkMode());
|
||||
|
||||
containerConfigBuilder.hostConfig(hostConfigBuilder.build());
|
||||
}
|
||||
|
||||
containerConfigBuilder.image(imageId);
|
||||
|
||||
// add the inbound ports into exposed ports map
|
||||
Config containerConfig = containerConfigBuilder.build();
|
||||
containerConfig = containerConfigBuilder.build();
|
||||
Map<String, Object> exposedPorts = Maps.newHashMap();
|
||||
if (containerConfig.exposedPorts() == null) {
|
||||
exposedPorts.putAll(containerConfig.exposedPorts());
|
||||
|
@ -179,9 +178,14 @@ public class DockerComputeServiceAdapter implements
|
|||
portBindings.put(exposedPort, Lists.<Map<String, String>>newArrayList(ImmutableMap.of("HostIp", "0.0.0.0")));
|
||||
}
|
||||
}
|
||||
HostConfig.Builder hostConfigBuilder = HostConfig.builder().fromHostConfig(containerConfig.hostConfig());
|
||||
hostConfigBuilder = HostConfig.builder().fromHostConfig(containerConfig.hostConfig());
|
||||
hostConfigBuilder.portBindings(portBindings);
|
||||
containerConfigBuilder.hostConfig(hostConfigBuilder.build());
|
||||
|
||||
} else {
|
||||
containerConfigBuilder.image(imageId);
|
||||
}
|
||||
|
||||
containerConfig = containerConfigBuilder.build();
|
||||
|
||||
logger.debug(">> creating new container with containerConfig(%s)", containerConfig);
|
||||
|
|
|
@ -26,6 +26,7 @@ import static org.testng.Assert.assertNotNull;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.RunNodesException;
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
|
@ -49,8 +50,11 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
|
||||
|
@ -61,6 +65,7 @@ import com.google.inject.Module;
|
|||
public class SshToCustomPortLiveTest extends BaseComputeServiceContextLiveTest {
|
||||
|
||||
private static final int SSH_PORT = 8822;
|
||||
private static final int SSH_PORT_BRIDGE = 18822;
|
||||
private static final String IMAGE_REPOSITORY = "jclouds/testrepo";
|
||||
private static final String IMAGE_TAG_1 = "testtag";
|
||||
private static final String IMAGE_TAG_2 = "second";
|
||||
|
@ -130,12 +135,17 @@ public class SshToCustomPortLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
|
||||
@Test(dependsOnMethods = "testImageCreated")
|
||||
public void testAdvancedConfig() throws RunNodesException {
|
||||
final String portId = SSH_PORT + "/tcp";
|
||||
final DockerTemplateOptions options = DockerTemplateOptions.Builder
|
||||
.configBuilder(
|
||||
Config.builder().env(ImmutableList.<String> of("SSH_PORT=" + SSH_PORT, "ROOT_PASSWORD=jcloudsRulez"))
|
||||
.hostConfig(HostConfig.builder().networkMode("host").build())
|
||||
.exposedPorts(ImmutableMap.<String, Object> of(portId, Maps.newHashMap()))
|
||||
.hostConfig(HostConfig.builder().networkMode("bridge")
|
||||
.portBindings(ImmutableMap.<String, List<Map<String, String>>> of(portId,
|
||||
Lists.<Map<String, String>>newArrayList(ImmutableMap.of("HostPort", String.valueOf(SSH_PORT_BRIDGE)))))
|
||||
.build())
|
||||
.image("test-if-this-value-is-correctly-overriden"))
|
||||
.overrideLoginUser("root").overrideLoginPassword("jcloudsRulez").blockOnPort(SSH_PORT, 30);
|
||||
.overrideLoginUser("root").overrideLoginPassword("jcloudsRulez").blockOnPort(SSH_PORT_BRIDGE, 30);
|
||||
|
||||
final Template template = view.getComputeService().templateBuilder().imageId(image.id()).options(options).build();
|
||||
|
||||
|
|
Loading…
Reference in New Issue