Search in sources :

Example 16 with BuildConfiguration

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"));
}
Also used : Expectations(mockit.Expectations) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 17 with BuildConfiguration

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")))));
}
Also used : Expectations(mockit.Expectations) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) Test(org.junit.Test)

Example 18 with BuildConfiguration

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");
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 19 with BuildConfiguration

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();
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) File(java.io.File)

Example 20 with BuildConfiguration

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;
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration)

Aggregations

BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)58 Test (org.junit.Test)39 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)24 File (java.io.File)23 Properties (java.util.Properties)11 AssemblyFile (org.eclipse.jkube.kit.common.AssemblyFile)10 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)10 RunImageConfiguration (org.eclipse.jkube.kit.config.image.RunImageConfiguration)8 GroupArtifactVersion (org.eclipse.jkube.kit.config.resource.GroupArtifactVersion)8 Before (org.junit.Before)8 AssemblyConfiguration (org.eclipse.jkube.kit.common.AssemblyConfiguration)7 ArrayList (java.util.ArrayList)6 Expectations (mockit.Expectations)5 VolumeConfig (org.eclipse.jkube.kit.config.resource.VolumeConfig)5 Verifications (mockit.Verifications)4 List (java.util.List)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assembly (org.eclipse.jkube.kit.common.Assembly)3 AssemblyFileEntry (org.eclipse.jkube.kit.common.AssemblyFileEntry)3 JavaProject (org.eclipse.jkube.kit.common.JavaProject)3