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