use of io.fabric8.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.
the class DockerImageWatcher method watch.
@Override
public void watch(List<ImageConfiguration> configs, final Set<HasMetadata> resources, PlatformMode mode) {
BuildService.BuildContext buildContext = getContext().getBuildContext();
WatchService.WatchContext watchContext = getContext().getWatchContext();
// add a image customizer
watchContext = new WatchService.WatchContext.Builder(watchContext).imageCustomizer(new Task<ImageConfiguration>() {
@Override
public void execute(ImageConfiguration imageConfiguration) throws DockerAccessException, MojoExecutionException, MojoFailureException {
buildImage(imageConfiguration);
}
}).containerRestarter(new Task<WatchService.ImageWatcher>() {
@Override
public void execute(WatchService.ImageWatcher imageWatcher) throws DockerAccessException, MojoExecutionException, MojoFailureException {
restartContainer(imageWatcher, resources);
}
}).build();
ServiceHub hub = getContext().getServiceHub();
try {
hub.getWatchService().watch(watchContext, buildContext, configs);
} catch (Exception ex) {
throw new RuntimeException("Error while watching", ex);
}
}
use of io.fabric8.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.
the class DockerImageWatcher method restartContainer.
protected void restartContainer(WatchService.ImageWatcher watcher, Set<HasMetadata> resources) throws MojoExecutionException {
ImageConfiguration imageConfig = watcher.getImageConfiguration();
String imageName = imageConfig.getName();
try {
ClusterAccess clusterAccess = new ClusterAccess(getContext().getNamespace());
KubernetesClient client = clusterAccess.createDefaultClient(log);
String namespace = clusterAccess.getNamespace();
String imagePrefix = getImagePrefix(imageName);
for (HasMetadata entity : resources) {
updateImageName(client, namespace, entity, imagePrefix, imageName);
}
} catch (KubernetesClientException e) {
KubernetesResourceUtil.handleKubernetesClientException(e, this.log);
} catch (MojoExecutionException e) {
throw e;
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
Aggregations