Search in sources :

Example 1 with JKubeServiceException

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

the class DockerBuildService method buildSingleImage.

@Override
public void buildSingleImage(ImageConfiguration imageConfig) throws JKubeServiceException {
    try {
        dockerServices.getBuildService().buildImage(imageConfig, buildServiceConfig.getImagePullManager(), jKubeConfiguration);
        // Assume we always want to tag
        dockerServices.getBuildService().tagImage(imageConfig.getName(), imageConfig);
    } catch (IOException ex) {
        throw new JKubeServiceException("Error while trying to build the image: " + ex.getMessage(), ex);
    }
}
Also used : IOException(java.io.IOException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException)

Example 2 with JKubeServiceException

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

the class JibBuildService method buildSingleImage.

@Override
public void buildSingleImage(ImageConfiguration imageConfig) throws JKubeServiceException {
    try {
        log.info("[[B]]JIB[[B]] image build started");
        if (imageConfig.getBuildConfiguration().isDockerFileMode()) {
            throw new JKubeServiceException("Dockerfile mode is not supported with JIB build strategy");
        }
        prependRegistry(imageConfig, configuration.getProperties().getProperty(PUSH_REGISTRY));
        BuildDirs buildDirs = new BuildDirs(imageConfig.getName(), configuration);
        final Credential pullRegistryCredential = getRegistryCredentials(configuration.getRegistryConfig(), false, imageConfig, log);
        final JibContainerBuilder containerBuilder = containerFromImageConfiguration(imageConfig, pullRegistryCredential);
        final Map<Assembly, List<AssemblyFileEntry>> layers = AssemblyManager.getInstance().copyFilesToFinalTarballDirectory(configuration, buildDirs, AssemblyManager.getAssemblyConfiguration(imageConfig.getBuildConfiguration(), configuration));
        JibServiceUtil.layers(buildDirs, layers).forEach(containerBuilder::addFileEntriesLayer);
        // TODO: Improve Assembly Manager so that the effective assemblyFileEntries computed can be properly shared
        // the call to AssemblyManager.getInstance().createDockerTarArchive should not be necessary,
        // files should be added using the AssemblyFileEntry list. AssemblyManager, should provide
        // a common way to achieve this so that both the tar builder and any other builder could get a hold of
        // archive customizers, file entries, etc.
        File dockerTarArchive = getAssemblyTarArchive(imageConfig, configuration, log);
        JibServiceUtil.buildContainer(containerBuilder, TarImage.at(dockerTarArchive.toPath()).named(imageConfig.getName()), log);
        log.info(" %s successfully built", dockerTarArchive.getAbsolutePath());
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    } catch (Exception ex) {
        throw new JKubeServiceException("Error when building JIB image", ex);
    }
}
Also used : Credential(com.google.cloud.tools.jib.api.Credential) List(java.util.List) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) BuildDirs(org.eclipse.jkube.kit.build.api.assembly.BuildDirs) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) IOException(java.io.IOException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException)

Example 3 with JKubeServiceException

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

the class DockerBuildServiceTest method build_withFailure_shouldThrowException.

@Test
public void build_withFailure_shouldThrowException() throws Exception {
    // Given
    doThrow(new IOException("Mock IO error")).when(mockedDockerBuildService).buildImage(eq(image), any(), any());
    // When
    final JKubeServiceException result = assertThrows(JKubeServiceException.class, () -> new DockerBuildService(mockedJKubeServiceHub).build(image));
    // Then
    assertThat(result).hasMessage("Error while trying to build the image: Mock IO error");
}
Also used : IOException(java.io.IOException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Test(org.junit.Test)

Example 4 with JKubeServiceException

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

the class OpenShiftBuildServiceUtilsTest method createBuildArchive_withIOExceptionOnCreateDockerBuildArchive_shouldThrowException.

@Test
public void createBuildArchive_withIOExceptionOnCreateDockerBuildArchive_shouldThrowException() throws Exception {
    // Given
    when(jKubeServiceHub.getDockerServiceHub().getArchiveService().createDockerBuildArchive(any(ImageConfiguration.class), any(JKubeConfiguration.class), any(ArchiverCustomizer.class))).thenThrow(new IOException("Mocked Exception"));
    // When
    final JKubeServiceException result = assertThrows(JKubeServiceException.class, () -> createBuildArchive(jKubeServiceHub, imageConfiguration));
    // Then
    assertThat(result).hasMessage("Unable to create the build archive").getCause().hasMessage("Mocked Exception");
}
Also used : JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) ArchiverCustomizer(org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) IOException(java.io.IOException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Test(org.junit.Test)

Example 5 with JKubeServiceException

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

the class KubernetesBuildTaskTest method setUp.

@Before
public void setUp() throws IOException {
    // Mock required for environments with no DOCKER available (don't remove)
    dockerAccessFactoryMockedConstruction = mockConstruction(DockerAccessFactory.class, (mock, ctx) -> when(mock.createDockerAccess(any())).thenReturn(mock(DockerAccess.class)));
    dockerBuildServiceMockedConstruction = mockConstruction(DockerBuildService.class, (mock, ctx) -> {
        when(mock.isApplicable()).thenReturn(isBuildServiceApplicable);
        if (isBuildError) {
            doThrow(new JKubeServiceException("Exception during Build")).when(mock).build(any());
        }
    });
    isBuildServiceApplicable = true;
    isBuildError = false;
    extension = new TestKubernetesExtension();
    when(taskEnvironment.project.getExtensions().getByType(KubernetesExtension.class)).thenReturn(extension);
    extension.images = Collections.singletonList(ImageConfiguration.builder().name("foo/bar:latest").build(BuildConfiguration.builder().dockerFile("Dockerfile").build()).build());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) DockerBuildService(org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService) DefaultProperty(org.gradle.api.internal.provider.DefaultProperty) Assert.assertThrows(org.junit.Assert.assertThrows) Mockito.doThrow(org.mockito.Mockito.doThrow) After(org.junit.After) AssertionsForInterfaceTypes.assertThat(org.assertj.core.api.AssertionsForInterfaceTypes.assertThat) Mockito.mockConstruction(org.mockito.Mockito.mockConstruction) Assertions(org.assertj.core.api.Assertions) TestKubernetesExtension(org.eclipse.jkube.gradle.plugin.TestKubernetesExtension) Before(org.junit.Before) MockedConstruction(org.mockito.MockedConstruction) DockerAccessFactory(org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) GradleException(org.gradle.api.GradleException) KubernetesExtension(org.eclipse.jkube.gradle.plugin.KubernetesExtension) Property(org.gradle.api.provider.Property) DockerAccess(org.eclipse.jkube.kit.build.service.docker.access.DockerAccess) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) DockerAccess(org.eclipse.jkube.kit.build.service.docker.access.DockerAccess) DockerBuildService(org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) DockerAccessFactory(org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory) TestKubernetesExtension(org.eclipse.jkube.gradle.plugin.TestKubernetesExtension) Before(org.junit.Before)

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