Search in sources :

Example 6 with JKubeServiceException

use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.

the class KubernetesBuildTask method run.

@Override
public void run() {
    if (kubernetesExtension.getRuntimeMode() == RuntimeMode.OPENSHIFT) {
        kitLogger.info("Using [[B]]OpenShift[[B]] build with strategy [[B]]%s[[B]]", kubernetesExtension.getBuildStrategyOrDefault().getLabel());
    } else {
        kitLogger.info("Building container image in [[B]]Kubernetes[[B]] mode");
    }
    try {
        storeTimestamp(getBuildTimestampFile(kubernetesExtension.javaProject.getBuildDirectory().getAbsolutePath(), DOCKER_BUILD_TIMESTAMP), getBuildTimestamp(null, null, kubernetesExtension.javaProject.getBuildDirectory().getAbsolutePath(), DOCKER_BUILD_TIMESTAMP));
        jKubeServiceHub.getBuildService().build(resolvedImages.toArray(new ImageConfiguration[0]));
    } catch (JKubeServiceException | IOException e) {
        kitLogger.error(e.getMessage());
        throw new GradleException(e.getMessage(), e);
    }
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) GradleException(org.gradle.api.GradleException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) IOException(java.io.IOException)

Example 7 with JKubeServiceException

use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.

the class JibBuildServiceBuildIntegrationTest method build_dockerFileMode_shouldThrowException.

@Test
public void build_dockerFileMode_shouldThrowException() {
    // Given
    final ImageConfiguration ic = imageConfiguration.toBuilder().build(imageConfiguration.getBuild().toBuilder().dockerFile("Dockerfile").build()).build();
    // When
    final JKubeServiceException result = assertThrows(JKubeServiceException.class, () -> jibBuildService.build(ic));
    // Then
    assertThat(result).hasMessage("Error when building JIB image").getCause().hasMessage("Dockerfile mode is not supported with JIB build strategy");
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Test(org.junit.Test)

Example 8 with JKubeServiceException

use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.

the class JibBuildService method pushSingleImage.

@Override
protected void pushSingleImage(ImageConfiguration imageConfiguration, int retries, RegistryConfig registryConfig, boolean skipTag) throws JKubeServiceException {
    try {
        prependRegistry(imageConfiguration, registryConfig.getRegistry());
        log.info("This push refers to: %s", imageConfiguration.getName());
        JibServiceUtil.jibPush(imageConfiguration, getRegistryCredentials(registryConfig, true, imageConfiguration, log), getBuildTarArchive(imageConfiguration, configuration), log);
    } catch (Exception ex) {
        throw new JKubeServiceException("Error when push JIB image", ex);
    }
}
Also used : JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) IOException(java.io.IOException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException)

Example 9 with JKubeServiceException

use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.

the class OpenShiftBuildServiceUtils method createS2IArchiveCustomizer.

private static ArchiverCustomizer createS2IArchiveCustomizer(BuildServiceConfig buildServiceConfig, ImageConfiguration imageConfiguration) throws JKubeServiceException {
    try {
        if (imageConfiguration.getBuildConfiguration() != null && imageConfiguration.getBuildConfiguration().getEnv() != null) {
            String fileName = IoUtil.sanitizeFileName("s2i-env-" + imageConfiguration.getName());
            final File environmentFile = new File(buildServiceConfig.getBuildDirectory(), fileName);
            try (PrintWriter out = new PrintWriter(new FileWriter(environmentFile))) {
                for (Map.Entry<String, String> e : imageConfiguration.getBuildConfiguration().getEnv().entrySet()) {
                    out.println(e.getKey() + "=" + e.getValue());
                }
            }
            return tarArchiver -> {
                tarArchiver.includeFile(environmentFile, ".s2i/environment");
                return tarArchiver;
            };
        } else {
            return null;
        }
    } catch (IOException e) {
        throw new JKubeServiceException("Unable to add environment variables to the S2I build archive", e);
    }
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) BuildStrategyBuilder(io.fabric8.openshift.api.model.BuildStrategyBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) JKubeBuildStrategy(org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) BuildConfigSpec(io.fabric8.openshift.api.model.BuildConfigSpec) StringUtils(org.apache.commons.lang3.StringUtils) ImageName(org.eclipse.jkube.kit.config.image.ImageName) Map(java.util.Map) DOCKER_IMAGE(org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService.DOCKER_IMAGE) DEFAULT_S2I_BUILD_SUFFIX(org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService.DEFAULT_S2I_BUILD_SUFFIX) ArchiverCustomizer(org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer) PrintWriter(java.io.PrintWriter) BuildOutput(io.fabric8.openshift.api.model.BuildOutput) FileWriter(java.io.FileWriter) DEFAULT_BUILD_OUTPUT_KIND(org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService.DEFAULT_BUILD_OUTPUT_KIND) KubernetesHelper(org.eclipse.jkube.kit.common.util.KubernetesHelper) IOException(java.io.IOException) BuildStrategy(io.fabric8.openshift.api.model.BuildStrategy) File(java.io.File) ImageStreamService.resolveImageStreamName(org.eclipse.jkube.kit.config.service.openshift.ImageStreamService.resolveImageStreamName) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) BuildOutputBuilder(io.fabric8.openshift.api.model.BuildOutputBuilder) List(java.util.List) IMAGE_STREAM_TAG(org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService.IMAGE_STREAM_TAG) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) IoUtil(org.eclipse.jkube.kit.common.util.IoUtil) Optional(java.util.Optional) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Collections(java.util.Collections) BuildUtil.extractBaseFromDockerfile(org.eclipse.jkube.kit.build.api.helper.BuildUtil.extractBaseFromDockerfile) FileWriter(java.io.FileWriter) IOException(java.io.IOException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) File(java.io.File) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 10 with JKubeServiceException

use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.

the class OpenshiftBuildService method logBuildFailure.

private void logBuildFailure(OpenShiftClient client, String buildName) throws JKubeServiceException {
    try {
        List<Build> builds = client.builds().inNamespace(applicableOpenShiftNamespace).list().getItems();
        for (Build build : builds) {
            if (build.getMetadata().getName().contains(buildName)) {
                log.error(build.getMetadata().getName() + "\t" + "\t" + build.getStatus().getReason() + "\t" + build.getStatus().getMessage());
                throw new JKubeServiceException("Unable to build the image using the OpenShift build service", new KubernetesClientException(build.getStatus().getReason() + " " + build.getStatus().getMessage()));
            }
        }
        log.error("Also, check cluster events via `oc get events` to see what could have possibly gone wrong");
    } catch (KubernetesClientException clientException) {
        Status status = clientException.getStatus();
        if (status != null)
            log.error("OpenShift Error: [%d] %s", status.getCode(), status.getMessage());
    }
}
Also used : Status(io.fabric8.kubernetes.api.model.Status) Build(io.fabric8.openshift.api.model.Build) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

JKubeServiceException (org.eclipse.jkube.kit.config.service.JKubeServiceException)13 IOException (java.io.IOException)9 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)6 Test (org.junit.Test)6 File (java.io.File)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 Collections (java.util.Collections)2 List (java.util.List)2 ArchiverCustomizer (org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer)2 ImageName (org.eclipse.jkube.kit.config.image.ImageName)2 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)2 GradleException (org.gradle.api.GradleException)2 Credential (com.google.cloud.tools.jib.api.Credential)1 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)1 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 LocalObjectReferenceBuilder (io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder)1 Status (io.fabric8.kubernetes.api.model.Status)1 WatcherException (io.fabric8.kubernetes.client.WatcherException)1 Build (io.fabric8.openshift.api.model.Build)1