use of io.fabric8.maven.docker.service.helper.StartContainerExecutor in project docker-maven-plugin by fabric8io.
the class StartContainerExecutorTest method showLogs_withShowLogsMatchImage.
@Test
public void showLogs_withShowLogsMatchImage() {
// Given
final ImageConfiguration imageConfig = new ImageConfiguration.Builder().name("name").alias("alias").build();
final StartContainerExecutor executor = new StartContainerExecutor.Builder().showLogs("name, alias").imageConfig(imageConfig).build();
// When
final boolean actual = executor.showLogs();
// Then
assertTrue(actual);
}
use of io.fabric8.maven.docker.service.helper.StartContainerExecutor in project docker-maven-plugin by fabric8io.
the class StartMojo method startImage.
private void startImage(final ImageConfiguration imageConfig, final ServiceHub hub, final ExecutorCompletionService<StartedContainer> startingContainers, final PortMapping.PropertyWriteHelper portMappingPropertyWriteHelper) throws IOException {
final RunService runService = hub.getRunService();
final Properties projProperties = project.getProperties();
final RunImageConfiguration runConfig = imageConfig.getRunConfiguration();
final PortMapping portMapping = runService.createPortMapping(runConfig, projProperties);
final LogDispatcher dispatcher = getLogDispatcher(hub);
StartContainerExecutor startExecutor = new StartContainerExecutor.Builder().exposeContainerProps(exposeContainerProps).dispatcher(dispatcher).follow(follow).log(log).portMapping(portMapping).gavLabel(getGavLabel()).projectProperties(project.getProperties()).basedir(project.getBasedir()).imageConfig(imageConfig).serviceHub(hub).logOutputSpecFactory(serviceHubFactory.getLogOutputSpecFactory()).showLogs(showLogs).containerNamePattern(containerNamePattern).buildTimestamp(getBuildTimestamp()).build();
startingContainers.submit(() -> {
String containerId = startExecutor.startContainer();
// Update port-mapping writer
portMappingPropertyWriteHelper.add(portMapping, runConfig.getPortPropertyFile());
return new StartedContainer(imageConfig, containerId);
});
}
use of io.fabric8.maven.docker.service.helper.StartContainerExecutor in project docker-maven-plugin by fabric8io.
the class StartContainerExecutorTest method showLogs_withoutRunConfig.
@Test
public void showLogs_withoutRunConfig() {
// Given
final ImageConfiguration imageConfig = new ImageConfiguration.Builder().name("name").alias("alias").build();
final StartContainerExecutor executor = new StartContainerExecutor.Builder().imageConfig(imageConfig).build();
// When
final boolean actual = executor.showLogs();
// Then
assertFalse(actual);
}
use of io.fabric8.maven.docker.service.helper.StartContainerExecutor in project docker-maven-plugin by fabric8io.
the class StartContainerExecutorTest method testStartContainers.
@Test
public void testStartContainers(@Mocked ServiceHub hub, @Mocked DockerAccess dockerAccess, @Mocked ContainerTracker containerTracker, @Mocked Logger log) throws IOException, ExecException {
// Given
new Expectations() {
{
dockerAccess.createContainer((ContainerCreateConfig) any, anyString);
result = "container-name";
dockerAccess.getContainer(anyString);
result = new ContainerDetails(JsonFactory.newJsonObject("{\"NetworkSettings\":{\"IPAddress\":\"192.168.1.2\"}}"));
QueryService queryService = new QueryService(dockerAccess);
hub.getQueryService();
result = queryService;
hub.getRunService();
result = new RunService(dockerAccess, queryService, containerTracker, new LogOutputSpecFactory(true, true, null), log);
}
};
Properties projectProps = new Properties();
StartContainerExecutor startContainerExecutor = new StartContainerExecutor.Builder().serviceHub(hub).projectProperties(projectProps).portMapping(new PortMapping(Collections.emptyList(), projectProps)).gavLabel(new GavLabel("io.fabric8:test:0.1.0")).basedir(new File("/tmp/foo")).containerNamePattern("test-").buildTimestamp(new Date()).exposeContainerProps("docker.container").imageConfig(new ImageConfiguration.Builder().name("name").alias("alias").runConfig(new RunImageConfiguration.Builder().build()).build()).build();
// When
String containerId = startContainerExecutor.startContainer();
// Then
assertEquals("container-name", containerId);
assertEquals("container-name", projectProps.getProperty("docker.container.alias.id"));
assertEquals("192.168.1.2", projectProps.getProperty("docker.container.alias.ip"));
}
use of io.fabric8.maven.docker.service.helper.StartContainerExecutor in project docker-maven-plugin by fabric8io.
the class StartContainerExecutorTest method getExposedPropertyKeyPart_withoutRunConfig.
@Test
public void getExposedPropertyKeyPart_withoutRunConfig() {
// Given
final ImageConfiguration imageConfig = new ImageConfiguration.Builder().name("name").alias("alias").build();
final StartContainerExecutor executor = new StartContainerExecutor.Builder().imageConfig(imageConfig).build();
// When
final String actual = executor.getExposedPropertyKeyPart();
// Then
assertEquals("alias", actual);
}
Aggregations