use of io.fabric8.maven.docker.config.WaitConfiguration in project docker-maven-plugin by fabric8io.
the class ContainerTrackerTest method getImageConfiguration.
private ImageConfiguration getImageConfiguration(String name, String alias, int shutdown, int kill, String preStop, boolean breakOnError) {
WaitConfiguration waitConfig = null;
if (shutdown != 0 && kill != 0) {
WaitConfiguration.Builder builder = new WaitConfiguration.Builder().shutdown(shutdown).kill(kill);
if (preStop != null) {
builder.preStop(preStop);
builder.breakOnError(breakOnError);
}
waitConfig = builder.build();
}
return new ImageConfiguration.Builder().name(name).alias(alias).runConfig(new RunImageConfiguration.Builder().wait(waitConfig).build()).build();
}
use of io.fabric8.maven.docker.config.WaitConfiguration in project docker-maven-plugin by fabric8io.
the class WaitService method prepareWaitCheckers.
private List<WaitChecker> prepareWaitCheckers(ImageConfiguration imageConfig, Properties projectProperties, String containerId) throws MojoExecutionException {
WaitConfiguration wait = getWaitConfiguration(imageConfig);
if (wait == null) {
return Collections.emptyList();
}
List<WaitChecker> checkers = new ArrayList<>();
if (wait.getUrl() != null) {
checkers.add(getUrlWaitChecker(imageConfig.getDescription(), projectProperties, wait));
}
if (wait.getLog() != null) {
log.debug("LogWaitChecker: Waiting on %s", wait.getLog());
checkers.add(new LogWaitChecker(wait.getLog(), dockerAccess, containerId, log));
}
if (wait.getTcp() != null) {
try {
Container container = queryService.getMandatoryContainer(containerId);
checkers.add(getTcpWaitChecker(container, imageConfig.getDescription(), projectProperties, wait.getTcp()));
} catch (DockerAccessException e) {
throw new MojoExecutionException("Unable to access container.", e);
}
}
if (wait.getHealthy() == Boolean.TRUE) {
checkers.add(new HealthCheckChecker(dockerAccess, containerId, imageConfig.getDescription(), log));
}
if (wait.getExit() != null) {
checkers.add(new ExitCodeChecker(wait.getExit(), queryService, containerId));
}
return checkers;
}
use of io.fabric8.maven.docker.config.WaitConfiguration 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);
}
});
}
Aggregations