use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromDetectionOnNonFatJar.
/**
* The main class is determined via main class detection in a non-fat-jar deployment
*/
@Test
public void testMainClassDeterminationFromDetectionOnNonFatJar(@Injectable File baseDir) {
processorConfig.getConfig().put("java-exec", Collections.singletonMap("name", "TheNonFatJarImageName"));
new Expectations() {
{
project.getBaseDirectory();
result = baseDir;
fatJarDetector.scan();
result = null;
mainClassDetector.getMainClass();
result = "the.detected.MainClass";
}
};
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", "TheNonFatJarImageName", imageConfig.getName());
assertEquals("Main Class set as environment variable", "the.detected.MainClass", 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 KarafGeneratorTest method customizeWithKarafMavenPluginAndCustomConfigShouldAddImageConfiguration.
@Test
public void customizeWithKarafMavenPluginAndCustomConfigShouldAddImageConfiguration(@Mocked Plugin plugin) {
// Given
final List<ImageConfiguration> originalImageConfigurations = new ArrayList<>();
Properties props = new Properties();
props.put("jkube.generator.karaf.baseDir", "/other-dir");
props.put("jkube.generator.karaf.webPort", "8080");
// @formatter:off
new Expectations() {
{
generatorContext.getProject().getBuildDirectory();
result = temporaryFolder.getRoot();
generatorContext.getProject().getVersion();
result = "1.33.7-SNAPSHOT";
generatorContext.getProject().getProperties();
result = props;
}
};
// @formatter:on
// When
final List<ImageConfiguration> result = new KarafGenerator(generatorContext).customize(originalImageConfigurations, false);
// Then
assertThat(result, hasSize(1));
final ImageConfiguration imageConfiguration = result.iterator().next();
assertThat(imageConfiguration.getBuildConfiguration().getPorts(), contains("8080", "8778"));
assertThat(imageConfiguration.getBuildConfiguration().getEnv(), hasEntry("DEPLOYMENTS_DIR", "/other-dir"));
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class KarafGeneratorTest method customizeWithKarafMavenPluginShouldAddImageConfiguration.
@Test
public void customizeWithKarafMavenPluginShouldAddImageConfiguration(@Mocked Plugin plugin) {
// Given
final List<ImageConfiguration> originalImageConfigurations = new ArrayList<>();
// @formatter:off
new Expectations() {
{
plugin.getGroupId();
result = "org.apache.karaf.tooling";
minTimes = 0;
plugin.getArtifactId();
result = "karaf-maven-plugin";
minTimes = 0;
generatorContext.getProject().getPlugins();
result = Collections.singletonList(plugin);
minTimes = 0;
generatorContext.getProject().getBuildDirectory();
result = temporaryFolder.getRoot();
generatorContext.getProject().getVersion();
result = "1.33.7-SNAPSHOT";
generatorContext.getConfig();
result = new ProcessorConfig();
}
};
// @formatter:on
// When
final List<ImageConfiguration> result = new KarafGenerator(generatorContext).customize(originalImageConfigurations, false);
// Then
assertThat(originalImageConfigurations, sameInstance(result));
assertThat(result, hasSize(1));
final ImageConfiguration imageConfiguration = result.iterator().next();
assertThat(imageConfiguration.getName(), equalTo("%g/%a:%l"));
assertThat(imageConfiguration.getAlias(), equalTo("karaf"));
final BuildConfiguration bc = imageConfiguration.getBuildConfiguration();
assertThat(bc.getTags(), contains("latest"));
assertThat(bc.getPorts(), contains("8181", "8778"));
assertThat(bc.getEnv(), hasEntry("DEPLOYMENTS_DIR", "/deployments"));
assertThat(bc.getEnv(), hasEntry("KARAF_HOME", "/deployments/karaf"));
final AssemblyConfiguration ac = bc.getAssembly();
assertThat(ac.getName(), equalTo("deployments"));
assertThat(ac.isExcludeFinalOutputArtifact(), equalTo(false));
assertThat(ac.getLayers(), hasSize(1));
assertThat(ac.getLayers().iterator().next().getFileSets(), contains(allOf(hasProperty("directory", equalTo(new File(temporaryFolder.getRoot(), "assembly"))), hasProperty("outputDirectory", equalTo(new File("karaf"))), hasProperty("directoryMode", equalTo("0775"))), allOf(hasProperty("directory", equalTo(temporaryFolder.getRoot().toPath().resolve("assembly").resolve("bin").toFile())), hasProperty("outputDirectory", equalTo(new File("karaf", "bin"))), hasProperty("fileMode", equalTo("0777")), hasProperty("directoryMode", equalTo("0775")))));
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class WebAppGenerator method customize.
@Override
public List<ImageConfiguration> customize(List<ImageConfiguration> configs, boolean prePackagePhase) {
final AppServerHandler handler = getAppServerHandler(getContext());
if (getContext().getRuntimeMode() == RuntimeMode.OPENSHIFT && getContext().getStrategy() == JKubeBuildStrategy.s2i && !prePackagePhase && !handler.supportsS2iBuild()) {
throw new IllegalArgumentException("S2I not yet supported for the webapp-generator. Use " + "-Djkube.build.strategy=docker for OpenShift mode. Please refer to the reference manual at " + "https://www.eclipse.org/jkube/docs for details about build modes.");
}
log.info("Using %s as base image for webapp", handler.getFrom());
final ImageConfiguration.ImageConfigurationBuilder imageBuilder = ImageConfiguration.builder();
final BuildConfiguration.BuildConfigurationBuilder buildBuilder = BuildConfiguration.builder();
buildBuilder.from(getFrom(handler)).ports(handler.exposedPorts()).env(getEnv(handler));
String dockerRunCommand = getDockerRunCommand(handler);
if (dockerRunCommand != null) {
buildBuilder.cmd(Arguments.builder().shell(dockerRunCommand).build());
}
handler.runCmds().forEach(buildBuilder::runCmd);
addSchemaLabels(buildBuilder, log);
if (!prePackagePhase) {
buildBuilder.assembly(createAssembly(handler));
}
addLatestTagIfSnapshot(buildBuilder);
imageBuilder.name(getImageName()).alias(getAlias()).build(buildBuilder.build());
configs.add(imageBuilder.build());
return configs;
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class WebAppGeneratorTest method customizeWithOverriddenPropertiesShouldAddImageConfiguration.
@Test
public void customizeWithOverriddenPropertiesShouldAddImageConfiguration() 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());
final Properties projectProperties = new Properties();
projectProperties.put("jkube.generator.webapp.targetDir", "/other-dir");
projectProperties.put("jkube.generator.webapp.user", "root");
projectProperties.put("jkube.generator.webapp.cmd", "sleep 3600");
projectProperties.put("jkube.generator.webapp.path", "/some-context");
projectProperties.put("jkube.generator.webapp.ports", "8082,80");
projectProperties.put("jkube.generator.webapp.supportsS2iBuild", "true");
projectProperties.put("jkube.generator.from", "image-to-trigger-custom-app-server-handler");
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(generatorContext.getRuntimeMode()).thenReturn(RuntimeMode.OPENSHIFT);
when(generatorContext.getStrategy()).thenReturn(JKubeBuildStrategy.s2i);
when(generatorContext.getProject().getProperties()).thenReturn(projectProperties);
// When
final List<ImageConfiguration> result = new WebAppGenerator(generatorContext).customize(originalImageConfigurations, false);
// Then
assertThat(result).isSameAs(originalImageConfigurations).hasSize(1).first().hasFieldOrPropertyWithValue("name", "%a:%l").hasFieldOrPropertyWithValue("alias", "webapp").extracting(ImageConfiguration::getBuildConfiguration).hasFieldOrPropertyWithValue("tags", Collections.singletonList("latest")).hasFieldOrPropertyWithValue("ports", Arrays.asList("8082", "80")).hasFieldOrPropertyWithValue("env", Collections.singletonMap("DEPLOY_DIR", "/other-dir")).hasFieldOrPropertyWithValue("cmd.shell", "sleep 3600").extracting(BuildConfiguration::getAssembly).hasFieldOrPropertyWithValue("excludeFinalOutputArtifact", true).hasFieldOrPropertyWithValue("user", "root").extracting("inline.files").asList().extracting("destName").containsExactly("some-context.war");
}
Aggregations