Search in sources :

Example 91 with ImageConfiguration

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);
    }
}
Also used : Task(io.fabric8.maven.docker.util.Task) ServiceHub(io.fabric8.maven.docker.service.ServiceHub) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BuildService(io.fabric8.maven.docker.service.BuildService) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) WatchService(io.fabric8.maven.docker.service.WatchService)

Example 92 with ImageConfiguration

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);
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ClusterAccess(io.fabric8.maven.core.access.ClusterAccess) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)50 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)38 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)24 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 Test (org.junit.Test)13 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)10 File (java.io.File)9 IOException (java.io.IOException)9 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)8 ArrayList (java.util.ArrayList)8 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)7 Before (org.junit.Before)7 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)6 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)6 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)5 Expectations (mockit.Expectations)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 ExecException (io.fabric8.maven.docker.access.ExecException)4 WatchImageConfiguration (io.fabric8.maven.docker.config.WatchImageConfiguration)4