Search in sources :

Example 6 with StartContainerExecutor

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);
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) Test(org.junit.Test)

Example 7 with StartContainerExecutor

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);
    });
}
Also used : RunService(io.fabric8.maven.docker.service.RunService) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher) PortMapping(io.fabric8.maven.docker.access.PortMapping) Properties(java.util.Properties) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) StartContainerExecutor(io.fabric8.maven.docker.service.helper.StartContainerExecutor)

Example 8 with StartContainerExecutor

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);
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) Test(org.junit.Test)

Example 9 with StartContainerExecutor

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"));
}
Also used : Expectations(mockit.Expectations) RunService(io.fabric8.maven.docker.service.RunService) LogOutputSpecFactory(io.fabric8.maven.docker.log.LogOutputSpecFactory) Properties(java.util.Properties) Date(java.util.Date) GavLabel(io.fabric8.maven.docker.util.GavLabel) QueryService(io.fabric8.maven.docker.service.QueryService) PortMapping(io.fabric8.maven.docker.access.PortMapping) File(java.io.File) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) ContainerDetails(io.fabric8.maven.docker.model.ContainerDetails) Test(org.junit.Test)

Example 10 with StartContainerExecutor

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);
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) Test(org.junit.Test)

Aggregations

RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)10 Test (org.junit.Test)9 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)8 PortMapping (io.fabric8.maven.docker.access.PortMapping)2 LogConfiguration (io.fabric8.maven.docker.config.LogConfiguration)2 RunService (io.fabric8.maven.docker.service.RunService)2 Properties (java.util.Properties)2 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)1 LogOutputSpecFactory (io.fabric8.maven.docker.log.LogOutputSpecFactory)1 ContainerDetails (io.fabric8.maven.docker.model.ContainerDetails)1 QueryService (io.fabric8.maven.docker.service.QueryService)1 StartContainerExecutor (io.fabric8.maven.docker.service.helper.StartContainerExecutor)1 GavLabel (io.fabric8.maven.docker.util.GavLabel)1 File (java.io.File)1 Date (java.util.Date)1 Expectations (mockit.Expectations)1