use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.
the class BaseGeneratorTest method addLatestTagIfSnapshot.
@Test
public void addLatestTagIfSnapshot() {
new Expectations() {
{
ctx.getProject();
result = project;
project.getVersion();
result = "1.2-SNAPSHOT";
}
};
BuildConfiguration.BuildConfigurationBuilder builder = BuildConfiguration.builder();
BaseGenerator generator = createGenerator(null);
generator.addLatestTagIfSnapshot(builder);
;
BuildConfiguration config = builder.build();
List<String> tags = config.getTags();
assertEquals(1, tags.size());
assertTrue(tags.get(0).endsWith("latest"));
}
use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration 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.build.BuildConfiguration 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");
}
use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.
the class DynamicDockerfileGenerator method generateImageConfiguration.
public ImageConfiguration generateImageConfiguration() throws IOException {
final File context = assembleContext();
generateDockerfile(context);
BuildConfiguration buildConfiguration = initBuildConfiguration(context);
return ImageConfiguration.builder().name(imageName).build(buildConfiguration).build();
}
use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.
the class DynamicDockerfileGenerator method initBuildConfiguration.
/**
* Generates a Dockerfile dynamically with any entries you wish and writes it to the provided directory
*/
private BuildConfiguration initBuildConfiguration(File contextDir) {
kitLogger.info("Preparing build configuration for Dynamic Dockerfile mode");
final BuildConfiguration buildConfiguration = BuildConfiguration.builder().contextDir(contextDir.getAbsolutePath()).dockerFile("Dockerfile").assembly(AssemblyConfiguration.builder().name("ContextAssembly").targetDir("/").build()).build();
buildConfiguration.initAndValidate();
return buildConfiguration;
}
Aggregations