use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.
the class OpenshiftBuildService method buildSingleImage.
@Override
public void buildSingleImage(ImageConfiguration imageConfig) throws JKubeServiceException {
initClient();
String buildName = null;
try {
final ImageConfiguration.ImageConfigurationBuilder applicableImageConfigBuilder = imageConfig.toBuilder();
if (imageConfig.getBuildConfiguration() != null && !imageConfig.getBuildConfiguration().isDockerFileMode() && imageConfig.getBuildConfiguration().getAssembly() != null) {
applicableImageConfigBuilder.build(imageConfig.getBuild().toBuilder().assembly(imageConfig.getBuildConfiguration().getAssembly().getFlattenedClone(jKubeServiceHub.getConfiguration())).build());
}
final ImageConfiguration applicableImageConfig = applicableImageConfigBuilder.build();
ImageName imageName = new ImageName(applicableImageConfig.getName());
File dockerTar = createBuildArchive(jKubeServiceHub, applicableImageConfig);
KubernetesListBuilder builder = new KubernetesListBuilder();
// Check for buildconfig / imagestream / pullSecret and create them if necessary
String openshiftPullSecret = buildServiceConfig.getOpenshiftPullSecret();
final boolean usePullSecret = checkOrCreatePullSecret(client, builder, openshiftPullSecret, applicableImageConfig);
if (usePullSecret) {
buildName = updateOrCreateBuildConfig(buildServiceConfig, client, builder, applicableImageConfig, openshiftPullSecret);
} else {
buildName = updateOrCreateBuildConfig(buildServiceConfig, client, builder, applicableImageConfig, null);
}
if (buildServiceConfig.getBuildOutputKind() == null || IMAGE_STREAM_TAG.equals(buildServiceConfig.getBuildOutputKind())) {
checkOrCreateImageStream(buildServiceConfig, client, builder, resolveImageStreamName(imageName));
applyBuild(buildName, dockerTar, builder);
// Create a file with generated image streams
addImageStreamToFile(getImageStreamFile(), imageName, client);
} else {
applyBuild(buildName, dockerTar, builder);
}
} catch (JKubeServiceException e) {
throw e;
} catch (Exception ex) {
// Log additional details in case of any IOException
if (ex.getCause() instanceof IOException) {
log.error("Build for %s failed: %s", buildName, ex.getCause().getMessage());
logBuildFailure(client, buildName);
} else {
throw new JKubeServiceException("Unable to build the image using the OpenShift build service", ex);
}
}
}
use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.
the class OpenshiftBuildServiceIntegrationTest method build_withDockerfileModeAndFlattenedAssembly_shouldThrowException.
@Test
public void build_withDockerfileModeAndFlattenedAssembly_shouldThrowException() {
// Given
image.setBuild(BuildConfiguration.builder().dockerFile(new File(target, "Dockerfile").getAbsolutePath()).assembly(AssemblyConfiguration.builder().layer(Assembly.builder().id("one").build()).build().getFlattenedClone(jKubeServiceHub.getConfiguration())).build());
image.getBuildConfiguration().initAndValidate();
final OpenshiftBuildService openshiftBuildService = new OpenshiftBuildService(jKubeServiceHub);
// When
final JKubeServiceException result = assertThrows(JKubeServiceException.class, () -> openshiftBuildService.build(image));
// Then
assertThat(result).getCause().hasMessage("This image has already been flattened, you can only flatten the image once");
}
use of org.eclipse.jkube.kit.config.service.JKubeServiceException in project jkube by eclipse.
the class OpenshiftBuildServiceIntegrationTest method testFailedBuild.
@Test
public void testFailedBuild() {
withBuildServiceConfig(defaultConfig.build());
final OpenshiftBuildService openshiftBuildService = new OpenshiftBuildService(jKubeServiceHub);
final JKubeServiceException result = assertThrows(JKubeServiceException.class, () -> openshiftBuildService.build(image));
assertThat(result).hasMessageContaining("Unable to build the image using the OpenShift build service");
}
Aggregations