Search in sources :

Example 86 with ImageConfiguration

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

the class DockerHealthCheckEnricherTest method testUnmatchingHealthCheck.

@Test
public void testUnmatchingHealthCheck() throws Exception {
    // Setup mock behaviour
    new Expectations() {

        {
            final ImageConfiguration image = ImageConfiguration.builder().alias("myImage").build(BuildConfiguration.builder().healthCheck(HealthCheckConfiguration.builder().mode(HealthCheckMode.cmd).cmd(Arguments.builder().shell("/bin/check").build()).timeout("1s").interval("1h1s").retries(3).build()).build()).build();
            context.getConfiguration();
            result = Configuration.builder().image(image).build();
        }
    };
    KubernetesListBuilder builder = createDeployment("myUnmatchingImage");
    DockerHealthCheckEnricher enricher = new DockerHealthCheckEnricher(context);
    enricher.create(PlatformMode.kubernetes, builder);
    KubernetesList list = builder.build();
    assertEquals(1, list.getItems().size());
    assertNoProbes(list.getItems().get(0));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.Test)

Example 87 with ImageConfiguration

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

the class GeneratorManager method generate.

public static List<ImageConfiguration> generate(List<ImageConfiguration> imageConfigs, GeneratorContext genCtx, boolean prePackagePhase) {
    final PluginServiceFactory<GeneratorContext> pluginFactory = new PluginServiceFactory<>(genCtx);
    if (genCtx.isUseProjectClasspath()) {
        pluginFactory.addAdditionalClassLoader(ClassUtil.createProjectClassLoader(genCtx.getProject().getCompileClassPathElements(), genCtx.getLogger()));
    }
    List<ImageConfiguration> ret = imageConfigs;
    final KitLogger log = genCtx.getLogger();
    final List<Generator> generators = pluginFactory.createServiceObjects(SERVICE_PATHS);
    final List<Generator> usableGenerators = genCtx.getConfig().prepareProcessors(generators, "generator");
    log.verbose("Generators:");
    for (Generator generator : usableGenerators) {
        log.verbose(" - %s", generator.getName());
        if (generator.isApplicable(ret)) {
            log.info("Running generator %s", generator.getName());
            ret = generator.customize(ret, prePackagePhase);
        }
    }
    return ret;
}
Also used : KitLogger(org.eclipse.jkube.kit.common.KitLogger) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) PluginServiceFactory(org.eclipse.jkube.kit.common.util.PluginServiceFactory)

Example 88 with ImageConfiguration

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

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromFatJar.

/**
 * The main class is determined as the Main-Class of a fat jar
 */
@Test
public void testMainClassDeterminationFromFatJar(@Mocked FileUtil fileUtil, @Injectable File baseDir, @Injectable File fatJarArchive) {
    processorConfig.getConfig().put("java-exec", Collections.singletonMap("name", "TheFatJarImageName"));
    new Expectations() {

        {
            project.getBaseDirectory();
            result = baseDir;
            fileUtil.getRelativePath(withInstanceOf(File.class), withInstanceOf(File.class));
            result = baseDir;
            fatJarDetector.scan();
            result = fatJarDetectorResult;
            fatJarDetectorResult.getArchiveFile();
            result = fatJarArchive;
        }
    };
    final GeneratorContext generatorContext = GeneratorContext.builder().project(project).config(processorConfig).strategy(JKubeBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    final List<ImageConfiguration> images = new ArrayList<>();
    List<ImageConfiguration> customized = generator.customize(images, false);
    assertEquals("1 images returned", 1, customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheFatJarImageName", imageConfig.getName());
    assertNull("Main Class is NOT set as environment variable#", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : Expectations(mockit.Expectations) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ArrayList(java.util.ArrayList) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) File(java.io.File) Test(org.junit.Test)

Example 89 with ImageConfiguration

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

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromConfig.

/**
 * The main class is determined via config in a non-fat-jar deployment
 */
@Test
public void testMainClassDeterminationFromConfig() {
    // Given
    final Map<String, Object> configurations = new HashMap<>();
    configurations.put("mainClass", "the.main.ClassName");
    configurations.put("name", "TheImageName");
    processorConfig.getConfig().put("java-exec", configurations);
    final GeneratorContext generatorContext = GeneratorContext.builder().project(project).config(processorConfig).strategy(JKubeBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    List<ImageConfiguration> customized = generator.customize(new ArrayList<>(), false);
    assertEquals("1 images returned", 1, customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheImageName", imageConfig.getName());
    assertEquals("Main Class set as environment variable", "the.main.ClassName", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : HashMap(java.util.HashMap) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) Test(org.junit.Test)

Example 90 with ImageConfiguration

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

the class WebAppGeneratorTest method customizeWithDefaultHandlerShouldAddImageConfiguration.

@Test
public void customizeWithDefaultHandlerShouldAddImageConfiguration() throws IOException {
    // Given
    final List<ImageConfiguration> originalImageConfigurations = new ArrayList<>();
    final File buildDirectory = temporaryFolder.newFolder("build");
    final File artifactFile = new File(buildDirectory, "artifact.war");
    assertTrue(artifactFile.createNewFile());
    when(generatorContext.getProject().getBuildDirectory()).thenReturn(buildDirectory);
    when(generatorContext.getProject().getBuildFinalName()).thenReturn("artifact");
    when(generatorContext.getProject().getPackaging()).thenReturn("war");
    when(generatorContext.getProject().getVersion()).thenReturn("1.33.7-SNAPSHOT");
    // When
    final List<ImageConfiguration> result = new WebAppGenerator(generatorContext).customize(originalImageConfigurations, false);
    // Then
    assertThat(result).isSameAs(originalImageConfigurations).hasSize(1).first().hasFieldOrPropertyWithValue("name", "%g/%a:%l").hasFieldOrPropertyWithValue("alias", "webapp").extracting(ImageConfiguration::getBuildConfiguration).hasFieldOrPropertyWithValue("tags", Collections.singletonList("latest")).hasFieldOrPropertyWithValue("ports", Collections.singletonList("8080")).hasFieldOrPropertyWithValue("env", Collections.singletonMap("DEPLOY_DIR", "/deployments")).extracting(BuildConfiguration::getAssembly).hasFieldOrPropertyWithValue("excludeFinalOutputArtifact", true).extracting("inline.files").asList().extracting("destName").containsExactly("ROOT.war");
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) 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