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);
}
});
}
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());
}
Aggregations