Search in sources :

Example 1 with DockerServiceHub

use of org.eclipse.jkube.kit.build.service.docker.DockerServiceHub in project jkube by eclipse.

the class DockerImageWatcher method watch.

@Override
public void watch(List<ImageConfiguration> configs, String namespace, final Collection<HasMetadata> resources, PlatformMode mode) {
    WatchContext watchContext = getContext().getWatchContext();
    watchContext = watchContext.toBuilder().imageCustomizer(this::buildImage).containerRestarter(imageWatcher -> restartContainer(imageWatcher, resources)).containerCommandExecutor(command -> executeCommandInPod(command, resources)).containerCopyTask(f -> copyFileToPod(f, resources)).build();
    DockerServiceHub hub = getContext().getJKubeServiceHub().getDockerServiceHub();
    try {
        hub.getWatchService().watch(watchContext, getContext().getBuildContext(), configs);
    } catch (Exception ex) {
        throw new RuntimeException("Error while watching", ex);
    }
}
Also used : ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) OpenshiftHelper(org.eclipse.jkube.kit.common.util.OpenshiftHelper) ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) Container(io.fabric8.kubernetes.api.model.Container) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec) Date(java.util.Date) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) WatchContext(org.eclipse.jkube.kit.build.service.docker.watch.WatchContext) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) WatcherContext(org.eclipse.jkube.watcher.api.WatcherContext) PlatformMode(org.eclipse.jkube.kit.config.resource.PlatformMode) ReplicaSetSpec(io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec) PipedInputStream(java.io.PipedInputStream) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Duration(java.time.Duration) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) ImageNameFormatter(org.eclipse.jkube.kit.build.service.docker.helper.ImageNameFormatter) BaseWatcher(org.eclipse.jkube.watcher.api.BaseWatcher) PrintWriter(java.io.PrintWriter) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) Collection(java.util.Collection) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) IOException(java.io.IOException) KubernetesHelper(org.eclipse.jkube.kit.common.util.KubernetesHelper) FileInputStream(java.io.FileInputStream) PipedOutputStream(java.io.PipedOutputStream) WatchException(org.eclipse.jkube.kit.build.service.docker.watch.WatchException) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) DockerServiceHub(org.eclipse.jkube.kit.build.service.docker.DockerServiceHub) KitLogger(org.eclipse.jkube.kit.common.KitLogger) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) WatchService(org.eclipse.jkube.kit.build.service.docker.WatchService) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DockerServiceHub(org.eclipse.jkube.kit.build.service.docker.DockerServiceHub) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) WatchException(org.eclipse.jkube.kit.build.service.docker.watch.WatchException) WatchContext(org.eclipse.jkube.kit.build.service.docker.watch.WatchContext)

Example 2 with DockerServiceHub

use of org.eclipse.jkube.kit.build.service.docker.DockerServiceHub in project jkube by eclipse.

the class Main method main.

public static void main(String[] args) {
    final KitLogger kitLogger = new KitLogger.StdoutLogger();
    kitLogger.info("Initiating default JKube configuration and required services...");
    kitLogger.info(" - Creating Docker Service Hub");
    final DockerServiceHub dockerServiceHub = DockerServiceHub.newInstance(kitLogger);
    kitLogger.info(" - Creating Docker Build Service Configuration");
    final BuildServiceConfig dockerBuildServiceConfig = BuildServiceConfig.builder().build();
    kitLogger.info(" - Creating configuration for JKube");
    kitLogger.info(" - Current working directory is: %s", getProjectDir().toFile().toString());
    final JKubeConfiguration configuration = JKubeConfiguration.builder().project(JavaProject.builder().baseDirectory(getProjectDir().toFile()).build()).outputDirectory("target").sourceDirectory(getProjectDir().toFile().getAbsolutePath()).build();
    JKubeServiceHub.JKubeServiceHubBuilder buildBuilder = JKubeServiceHub.builder().log(kitLogger).configuration(configuration).platformMode(RuntimeMode.KUBERNETES).dockerServiceHub(dockerServiceHub).buildServiceConfig(dockerBuildServiceConfig);
    try (JKubeServiceHub jKubeServiceHub = buildBuilder.build()) {
        jKubeServiceHub.getBuildService().build(new DynamicDockerfileGenerator(kitLogger, getProjectDir(), IMAGE_NAME).generateImageConfiguration());
        final String imageId = jKubeServiceHub.getDockerServiceHub().getDockerAccess().getImageId(IMAGE_NAME);
        kitLogger.info("Docker image built successfully (%s)!", imageId);
        System.exit(0);
    } catch (Exception ex) {
        ex.printStackTrace();
        kitLogger.error("Error occurred: '%s'", ex.getMessage());
    }
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) KitLogger(org.eclipse.jkube.kit.common.KitLogger) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) DockerServiceHub(org.eclipse.jkube.kit.build.service.docker.DockerServiceHub) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub)

Aggregations

DockerServiceHub (org.eclipse.jkube.kit.build.service.docker.DockerServiceHub)2 KitLogger (org.eclipse.jkube.kit.common.KitLogger)2 Container (io.fabric8.kubernetes.api.model.Container)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)1 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)1 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)1 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 DeploymentSpec (io.fabric8.kubernetes.api.model.apps.DeploymentSpec)1 ReplicaSet (io.fabric8.kubernetes.api.model.apps.ReplicaSet)1 ReplicaSetSpec (io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)1 DeploymentConfigSpec (io.fabric8.openshift.api.model.DeploymentConfigSpec)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1