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);
}
}
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);
}
}
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");
}
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");
}
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());
}
Aggregations