Search in sources :

Example 6 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration 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 7 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class OpenshiftBuildServiceIntegrationTest method testDockerBuildFromExt.

@Test
public void testDockerBuildFromExt() throws Exception {
    final BuildServiceConfig dockerConfig = withBuildServiceConfig(BuildServiceConfig.builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-docker").jKubeBuildStrategy(JKubeBuildStrategy.docker).resourceConfig(mockedResourceConfig).build());
    final WebServerEventCollector collector = prepareMockServer(dockerConfig, true, false, false);
    OpenshiftBuildService service = new OpenshiftBuildService(jKubeServiceHub);
    Map<String, String> fromExt = ImmutableMap.of("name", "app:1.2-1", "kind", "ImageStreamTag", "namespace", "my-project");
    ImageConfiguration fromExtImage = ImageConfiguration.builder().name(projectName).build(BuildConfiguration.builder().fromExt(fromExt).nocache(Boolean.TRUE).build()).build();
    service.build(fromExtImage);
    assertTrue(mockServer.getOpenShiftMockServer().getRequestCount() > 8);
    collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
    assertEquals("{\"apiVersion\":\"build.openshift.io/v1\",\"kind\":\"BuildConfig\",\"metadata\":{\"name\":\"myapp-docker\"},\"spec\":{\"output\":{\"to\":{\"kind\":\"ImageStreamTag\",\"name\":\"myapp:latest\"}},\"source\":{\"type\":\"Binary\"},\"strategy\":{\"dockerStrategy\":{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"app:1.2-1\",\"namespace\":\"my-project\"},\"noCache\":true},\"type\":\"Docker\"}}}", collector.getBodies().get(1));
    collector.assertEventsNotRecorded("patch-build-config");
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Test(org.junit.Test)

Example 8 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class ContainerHandler method getContainers.

List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images) {
    List<Container> ret = new ArrayList<>();
    for (ImageConfiguration imageConfig : images) {
        if (imageConfig.getBuildConfiguration() != null) {
            Probe livenessProbe = probeHandler.getProbe(config.getLiveness());
            Probe readinessProbe = probeHandler.getProbe(config.getReadiness());
            Container container = new ContainerBuilder().withName(KubernetesResourceUtil.extractContainerName(this.groupArtifactVersion, imageConfig)).withImage(getImageName(imageConfig)).withImagePullPolicy(getImagePullPolicy(config)).withEnv(getEnvVars(config)).withSecurityContext(createSecurityContext(config)).withPorts(getContainerPorts(imageConfig)).withVolumeMounts(getVolumeMounts(config)).withLivenessProbe(livenessProbe).withReadinessProbe(readinessProbe).build();
            ret.add(container);
        }
    }
    return ret;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ArrayList(java.util.ArrayList) Probe(io.fabric8.kubernetes.api.model.Probe)

Example 9 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class AbstractDockerMojo method buildAndTag.

private void buildAndTag(List<ImageConfiguration> imageConfigs) throws MojoExecutionException {
    try {
        // TODO need to refactor d-m-p to avoid this call
        EnvUtil.storeTimestamp(getBuildTimestampFile(project.getBuild().getDirectory(), DOCKER_BUILD_TIMESTAMP), getBuildTimestamp(getPluginContext(), CONTEXT_KEY_BUILD_TIMESTAMP, project.getBuild().getDirectory(), DOCKER_BUILD_TIMESTAMP));
        jkubeServiceHub.getBuildService().build(imageConfigs.toArray(new ImageConfiguration[0]));
    } catch (Exception ex) {
        throw new MojoExecutionException("Failed to execute the build", ex);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) InvocationTargetException(java.lang.reflect.InvocationTargetException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 10 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class WatcherManagerTest method watch_withTestWatcher_shouldMutateImages.

@Test
public void watch_withTestWatcher_shouldMutateImages() throws Exception {
    // Given
    final List<ImageConfiguration> images = Collections.singletonList(new ImageConfiguration());
    // When
    WatcherManager.watch(images, null, Collections.emptyList(), watcherContext);
    // Then
    assertThat(images).hasSize(1).extracting(ImageConfiguration::getName).contains("processed-by-test");
    // @formatter:off
    new Verifications() {

        {
            logger.info("Running watcher %s", "fake-watcher");
            times = 1;
        }
    };
// @formatter:on
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Verifications(mockit.Verifications) Test(org.junit.Test)

Aggregations

ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)109 Test (org.junit.Test)75 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)29 RunImageConfiguration (org.eclipse.jkube.kit.config.image.RunImageConfiguration)28 File (java.io.File)26 ArrayList (java.util.ArrayList)19 Expectations (mockit.Expectations)15 GroupArtifactVersion (org.eclipse.jkube.kit.config.resource.GroupArtifactVersion)11 Before (org.junit.Before)11 IOException (java.io.IOException)9 Properties (java.util.Properties)8 KitLogger (org.eclipse.jkube.kit.common.KitLogger)8 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)7 JKubeServiceException (org.eclipse.jkube.kit.config.service.JKubeServiceException)7 WatchImageConfiguration (org.eclipse.jkube.kit.config.image.WatchImageConfiguration)6 ResourceConfig (org.eclipse.jkube.kit.config.resource.ResourceConfig)6 List (java.util.List)5 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)5 VolumeConfig (org.eclipse.jkube.kit.config.resource.VolumeConfig)5 Container (io.fabric8.kubernetes.api.model.Container)4