Search in sources :

Example 6 with RunImageConfiguration

use of io.fabric8.maven.docker.config.RunImageConfiguration in project docker-maven-plugin by fabric8io.

the class StartMojo method startImage.

private void startImage(final ImageConfiguration image, final ServiceHub hub, final ExecutorCompletionService<StartedContainer> startingContainers, final PortMapping.PropertyWriteHelper portMappingPropertyWriteHelper) {
    final RunService runService = hub.getRunService();
    final Properties projProperties = project.getProperties();
    final RunImageConfiguration runConfig = image.getRunConfiguration();
    final PortMapping portMapping = runService.createPortMapping(runConfig, projProperties);
    final LogDispatcher dispatcher = getLogDispatcher(hub);
    startingContainers.submit(new Callable<StartedContainer>() {

        @Override
        public StartedContainer call() throws Exception {
            final String containerId = runService.createAndStartContainer(image, portMapping, getPomLabel(), projProperties, project.getBasedir());
            // Update port-mapping writer
            portMappingPropertyWriteHelper.add(portMapping, runConfig.getPortPropertyFile());
            if (showLogs(image)) {
                dispatcher.trackContainerLog(containerId, serviceHubFactory.getLogOutputSpecFactory().createSpec(containerId, image));
            }
            // Wait if requested
            hub.getWaitService().wait(image, projProperties, containerId);
            WaitConfiguration waitConfig = runConfig.getWaitConfiguration();
            if (waitConfig != null && waitConfig.getExec() != null && waitConfig.getExec().getPostStart() != null) {
                try {
                    runService.execInContainer(containerId, waitConfig.getExec().getPostStart(), image);
                } catch (ExecException exp) {
                    if (waitConfig.getExec().isBreakOnError()) {
                        throw exp;
                    } else {
                        log.warn("Cannot run postStart: %s", exp.getMessage());
                    }
                }
            }
            return new StartedContainer(image, containerId);
        }
    });
}
Also used : LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher) ExecException(io.fabric8.maven.docker.access.ExecException) PortMapping(io.fabric8.maven.docker.access.PortMapping) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException) ExecException(io.fabric8.maven.docker.access.ExecException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 7 with RunImageConfiguration

use of io.fabric8.maven.docker.config.RunImageConfiguration in project docker-maven-plugin by fabric8io.

the class DockerComposeConfigHandlerTest method validateRunConfiguration.

void validateRunConfiguration(RunImageConfiguration runConfig) {
    validateVolumeConfig(runConfig.getVolumeConfiguration());
    assertEquals(a("CAP"), runConfig.getCapAdd());
    assertEquals(a("CAP"), runConfig.getCapDrop());
    assertEquals("command.sh", runConfig.getCmd().getShell());
    assertEquals(a("8.8.8.8"), runConfig.getDns());
    assertEquals(a("example.com"), runConfig.getDnsSearch());
    assertEquals("domain.com", runConfig.getDomainname());
    assertEquals("entrypoint.sh", runConfig.getEntrypoint().getShell());
    assertEquals(a("localhost:127.0.0.1"), runConfig.getExtraHosts());
    assertEquals("subdomain", runConfig.getHostname());
    assertEquals(a("redis", "link1"), runConfig.getLinks());
    assertEquals((Long) 1L, runConfig.getMemory());
    assertEquals((Long) 1L, runConfig.getMemorySwap());
    assertEquals(RunImageConfiguration.NamingStrategy.none, runConfig.getNamingStrategy());
    assertEquals(null, runConfig.getEnvPropertyFile());
    assertEquals(null, runConfig.getPortPropertyFile());
    assertEquals(a("8081:8080"), runConfig.getPorts());
    assertEquals(true, runConfig.getPrivileged());
    assertEquals("tomcat", runConfig.getUser());
    assertEquals(a("from"), runConfig.getVolumeConfiguration().getFrom());
    assertEquals("foo", runConfig.getWorkingDir());
    validateEnv(runConfig.getEnv());
    // not sure it's worth it to implement 'equals/hashcode' for these
    RestartPolicy policy = runConfig.getRestartPolicy();
    assertEquals("on-failure", policy.getName());
    assertEquals(1, policy.getRetry());
}
Also used : RestartPolicy(io.fabric8.maven.docker.config.RestartPolicy)

Aggregations

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)2 LogConfiguration (io.fabric8.maven.docker.config.LogConfiguration)2 RestartPolicy (io.fabric8.maven.docker.config.RestartPolicy)2 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)2 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)2 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 ExecException (io.fabric8.maven.docker.access.ExecException)1 PortMapping (io.fabric8.maven.docker.access.PortMapping)1 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)1 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)1 IOException (java.io.IOException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1