Search in sources :

Example 66 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration 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);
        }
    }
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageName(org.eclipse.jkube.kit.config.image.ImageName) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) IOException(java.io.IOException) File(java.io.File) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) WatcherException(io.fabric8.kubernetes.client.WatcherException) IOException(java.io.IOException)

Example 67 with ImageConfiguration

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

the class KubernetesResourceUtilTest method extractContainerName_withPeriodsInImageUser_shouldRemovePeriodsFromContainerName.

@Test
public void extractContainerName_withPeriodsInImageUser_shouldRemovePeriodsFromContainerName() {
    // Given
    final ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("org.eclipse.jkube.testing/test-image").build();
    final GroupArtifactVersion gav = new GroupArtifactVersion("org.eclipse.jkube.testing", "test-image", "1.0.0");
    // When
    final String result = KubernetesResourceUtil.extractContainerName(gav, imageConfiguration);
    // Then
    assertThat(result).isEqualTo("orgeclipsejkubetesting-test-image");
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) GroupArtifactVersion(org.eclipse.jkube.kit.config.resource.GroupArtifactVersion) Test(org.junit.Test)

Example 68 with ImageConfiguration

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

the class ContainerHandlerTest method getContainerWithGroupArtifactTest.

@Test
public void getContainerWithGroupArtifactTest() {
    project.setArtifactId("test-artifact");
    project.setGroupId("test-group");
    ports.add("8080");
    ports.add("9090");
    tags.add("latest");
    tags.add("test");
    ContainerHandler handler = new ContainerHandler(project.getProperties(), new GroupArtifactVersion("test-group", "test-artifact", "0"), probeHandler);
    // container name with group id and aritact id without alias and user
    final BuildConfiguration buildImageConfiguration = BuildConfiguration.builder().ports(ports).from("fabric8/").cleanup("try").tags(tags).compressionString("gzip").dockerFile("testFile").build();
    ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("test").build(buildImageConfiguration).registry("docker.io").build();
    images.clear();
    images.add(imageConfiguration);
    containers = handler.getContainers(config, images);
    assertNotNull(containers);
    assertEquals("test-group-test-artifact", containers.get(0).getName());
    assertEquals("docker.io/test:latest", containers.get(0).getImage());
    assertEquals("IfNotPresent", containers.get(0).getImagePullPolicy());
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) GroupArtifactVersion(org.eclipse.jkube.kit.config.resource.GroupArtifactVersion) Test(org.junit.Test)

Example 69 with ImageConfiguration

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

the class ContainerHandlerTest method testGetContainersWithUserAndImageAndTagWithPeriodInImageUser.

@Test
public void testGetContainersWithUserAndImageAndTagWithPeriodInImageUser() {
    // Given
    ContainerHandler containerHandler = createContainerHandler(project);
    List<ImageConfiguration> imageConfigurations = new ArrayList<>();
    imageConfigurations.add(ImageConfiguration.builder().name("roman.gordill/customer-service-cache:latest").registry("quay.io").build(BuildConfiguration.builder().from("quay.io/jkube/jkube-java:0.0.13").assembly(AssemblyConfiguration.builder().targetDir("/deployments").build()).build()).build());
    // When
    List<Container> containers = containerHandler.getContainers(config, imageConfigurations);
    // Then
    assertNotNull(containers);
    assertEquals(1, containers.size());
    Container container = containers.get(0);
    assertEquals("quay.io/roman.gordill/customer-service-cache:latest", container.getImage());
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 70 with ImageConfiguration

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

the class PropertyConfigHandlerTest method testEnvAndLabels.

@Test
public void testEnvAndLabels() {
    List<ImageConfiguration> configs = resolveImage(imageConfiguration, props(mergeArrays(getBaseTestData(), new String[] { "docker.from", "baase", "docker.name", "demo", "docker.env.HOME", "/tmp", "docker.env.root.dir", "/bla", "docker.labels.version", "1.0.0", "docker.labels.blub.bla.foobar", "yep" })));
    assertEquals(1, configs.size());
    ImageConfiguration calcConfig = configs.get(0);
    for (Map env : new Map[] { calcConfig.getBuildConfiguration().getEnv(), calcConfig.getRunConfiguration().getEnv() }) {
        assertEquals(2, env.size());
        assertEquals("/tmp", env.get("HOME"));
        assertEquals("/bla", env.get("root.dir"));
    }
    for (Map labels : new Map[] { calcConfig.getBuildConfiguration().getLabels(), calcConfig.getRunConfiguration().getLabels() }) {
        assertEquals(3, labels.size());
        assertEquals("1.0.0", labels.get("version"));
        assertEquals("yep", labels.get("blub.bla.foobar"));
    }
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) 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