use of io.fabric8.maven.docker.access.DockerAccessException 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.access.DockerAccessException in project docker-maven-plugin by fabric8io.
the class WatchService method watch.
public synchronized void watch(WatchContext context, BuildService.BuildContext buildContext, List<ImageConfiguration> images) throws DockerAccessException, MojoExecutionException {
// Important to be be a single threaded scheduler since watch jobs must run serialized
ScheduledExecutorService executor = null;
try {
executor = Executors.newSingleThreadScheduledExecutor();
for (StartOrderResolver.Resolvable resolvable : runService.getImagesConfigsInOrder(queryService, images)) {
final ImageConfiguration imageConfig = (ImageConfiguration) resolvable;
String imageId = queryService.getImageId(imageConfig.getName());
String containerId = runService.lookupContainer(imageConfig.getName());
ImageWatcher watcher = new ImageWatcher(imageConfig, context, imageId, containerId);
long interval = watcher.getInterval();
WatchMode watchMode = watcher.getWatchMode(imageConfig);
log.info("Watching " + imageConfig.getName() + (watchMode != null ? " using " + watchMode.getDescription() : ""));
ArrayList<String> tasks = new ArrayList<>();
if (imageConfig.getBuildConfiguration() != null && imageConfig.getBuildConfiguration().getAssemblyConfiguration() != null) {
if (watcher.isCopy()) {
String containerBaseDir = imageConfig.getBuildConfiguration().getAssemblyConfiguration().getTargetDir();
schedule(executor, createCopyWatchTask(watcher, context.getMojoParameters(), containerBaseDir), interval);
tasks.add("copying artifacts");
}
if (watcher.isBuild()) {
schedule(executor, createBuildWatchTask(watcher, context.getMojoParameters(), watchMode == WatchMode.both, buildContext), interval);
tasks.add("rebuilding");
}
}
if (watcher.isRun() && watcher.getContainerId() != null) {
schedule(executor, createRestartWatchTask(watcher), interval);
tasks.add("restarting");
}
if (tasks.size() > 0) {
log.info("%s: Watch for %s", imageConfig.getDescription(), StringUtils.join(tasks.toArray(), " and "));
}
}
log.info("Waiting ...");
if (!context.isKeepRunning()) {
runService.addShutdownHookForStoppingContainers(context.isKeepContainer(), context.isRemoveVolumes(), context.isAutoCreateCustomNetworks());
}
wait();
} catch (InterruptedException e) {
log.warn("Interrupted");
} finally {
if (executor != null) {
executor.shutdownNow();
}
}
}
use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.
the class HealthCheckChecker method check.
@Override
public boolean check() {
try {
final ContainerDetails container = docker.getContainer(containerId);
if (container == null) {
log.debug("HealthWaitChecker: Container %s not found");
return false;
}
if (container.getHealthcheck() == null) {
throw new IllegalArgumentException("Can not wait for healthstate of " + imageConfigDesc + ". No HEALTHCHECK configured.");
}
if (first) {
log.info("%s: Waiting to become healthy", imageConfigDesc);
log.debug("HealthWaitChecker: Waiting for healthcheck: '%s'", container.getHealthcheck());
first = false;
} else if (log.isDebugEnabled()) {
log.debug("HealthWaitChecker: Waiting on healthcheck '%s'", container.getHealthcheck());
}
return container.isHealthy();
} catch (DockerAccessException e) {
log.warn("Error while checking health: %s", e.getMessage());
return false;
}
}
use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.
the class DockerAccessIT method testExecContainer.
private void testExecContainer() throws DockerAccessException {
Arguments arguments = new Arguments();
arguments.setExec(Lists.newArrayList("echo", "test", "echo"));
String execContainerId = dockerClient.createExecContainer(this.containerId, arguments);
// assertThat(dockerClient.startExecContainer(execContainerId), is("test echo"));
}
use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.
the class BuildMojo method buildAndTag.
protected void buildAndTag(ServiceHub hub, ImageConfiguration imageConfig) throws MojoExecutionException, DockerAccessException {
EnvUtil.storeTimestamp(getBuildTimestampFile(), getBuildTimestamp());
BuildService.BuildContext buildContext = getBuildContext();
ImagePullManager pullManager = getImagePullManager(determinePullPolicy(imageConfig.getBuildConfiguration()), autoPull);
BuildService buildService = hub.getBuildService();
buildService.buildImage(imageConfig, pullManager, buildContext);
if (!skipTag) {
buildService.tagImage(imageConfig.getName(), imageConfig);
}
}
Aggregations