Search in sources :

Example 26 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class AssemblyFileUtilsTest method getAssemblyFileOutputDirectoryWithRelativeDirectoryShouldReturnComputedPath.

@Test
public void getAssemblyFileOutputDirectoryWithRelativeDirectoryShouldReturnComputedPath() throws IOException {
    // Given
    final AssemblyFile af = AssemblyFile.builder().outputDirectory(new File("target")).build();
    final File outputDirectoryForRelativePaths = temporaryFolder.newFolder("output");
    final Assembly layer = new Assembly();
    final AssemblyConfiguration ac = AssemblyConfiguration.builder().targetDir("/project").build();
    // When
    final File result = getAssemblyFileOutputDirectory(af, outputDirectoryForRelativePaths, layer, ac);
    // Then
    final String expectedPath = outputDirectoryForRelativePaths.toPath().resolve("project").resolve("target").toAbsolutePath().toString();
    assertEquals(expectedPath, result.getAbsolutePath());
}
Also used : AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) Test(org.junit.Test)

Example 27 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class AssemblyConfigurationUtilsTest method getAssemblyConfigurationOrCreateDefaultWithConfigurationShouldReturnConfiguration.

@Test
public void getAssemblyConfigurationOrCreateDefaultWithConfigurationShouldReturnConfiguration(@Injectable final BuildConfiguration buildConfiguration) {
    // Given
    final AssemblyConfiguration configuration = AssemblyConfiguration.builder().user("OtherUser").name("ImageName").build();
    // @formatter:off
    new Expectations() {

        {
            buildConfiguration.getAssembly();
            result = configuration;
        }
    };
    // @formatter:on
    // When
    final AssemblyConfiguration result = getAssemblyConfigurationOrCreateDefault(buildConfiguration);
    // Then
    assertThat(result).hasFieldOrPropertyWithValue("name", "ImageName").hasFieldOrPropertyWithValue("targetDir", "/ImageName").hasFieldOrPropertyWithValue("user", "OtherUser");
}
Also used : Expectations(mockit.Expectations) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) Test(org.junit.Test)

Example 28 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class AssemblyConfigurationUtilsTest method createDockerFileBuilder_withAssemblyAndFilesInSingleLayer_shouldReturnTransformedContent.

@Test
public void createDockerFileBuilder_withAssemblyAndFilesInSingleLayer_shouldReturnTransformedContent() {
    // Given
    final BuildConfiguration buildConfig = BuildConfiguration.builder().user("1000").maintainer("Alex").build();
    final AssemblyConfiguration assemblyConfiguration = AssemblyConfiguration.builder().targetDir("/deployments").layer(Assembly.builder().id("layer-with-id").build()).layer(new Assembly()).build();
    final Map<Assembly, List<AssemblyFileEntry>> layers = assemblyConfiguration.getLayers().stream().collect(Collectors.toMap(Function.identity(), a -> Collections.singletonList(new AssemblyFileEntry(new File(""), new File(""), null))));
    layers.put(new Assembly(), Collections.emptyList());
    // When
    final String result = createDockerFileBuilder(buildConfig, assemblyConfiguration, layers).content();
    // Then
    assertThat(result).isEqualTo("FROM busybox\n" + "MAINTAINER Alex\n" + "COPY /layer-with-id/deployments /deployments/\n" + "VOLUME [\"/deployments\"]\n" + "USER 1000\n");
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) Expectations(mockit.Expectations) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) Test(org.junit.Test) AssemblyConfigurationUtils.createDockerFileBuilder(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.createDockerFileBuilder) AssemblyConfigurationUtils.getJKubeAssemblyFileSets(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFileSets) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) File(java.io.File) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault) List(java.util.List) AssemblyConfigurationUtils.getJKubeAssemblyFiles(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles) Assembly(org.eclipse.jkube.kit.common.Assembly) Map(java.util.Map) Arguments(org.eclipse.jkube.kit.config.image.build.Arguments) Injectable(mockit.Injectable) Collections(java.util.Collections) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) List(java.util.List) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) Test(org.junit.Test)

Example 29 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class AssemblyConfigurationUtilsTest method createDockerFileBuilder_withAssemblyAndFiles_shouldReturnTransformedContent.

@Test
public void createDockerFileBuilder_withAssemblyAndFiles_shouldReturnTransformedContent() {
    // Given
    final BuildConfiguration buildConfig = BuildConfiguration.builder().putEnv("ENV_VAR", "VALUE").label("LABEL", "LABEL_VALUE").port("8080").user("1000").volume("VOLUME").runCmd("chown -R 1000:1000 /opt").maintainer("Alex").cmd(Arguments.builder().execArgument("sh").execArgument("-c").execArgument("server").build()).build();
    final AssemblyConfiguration assemblyConfiguration = AssemblyConfiguration.builder().targetDir("/deployments").layer(Assembly.builder().id("layer-with-id").build()).layer(Assembly.builder().build()).build();
    final Map<Assembly, List<AssemblyFileEntry>> layers = assemblyConfiguration.getLayers().stream().collect(Collectors.toMap(Function.identity(), a -> Collections.singletonList(new AssemblyFileEntry(new File(""), new File(""), null))));
    // When
    final String result = createDockerFileBuilder(buildConfig, assemblyConfiguration, layers).content();
    // Then
    assertThat(result).isEqualTo("FROM busybox\n" + "MAINTAINER Alex\n" + "ENV ENV_VAR=VALUE\n" + "LABEL LABEL=LABEL_VALUE\n" + "EXPOSE 8080\n" + "COPY /layer-with-id/deployments /deployments/\n" + "COPY /deployments /deployments/\n" + "RUN chown -R 1000:1000 /opt\n" + "VOLUME [\"/deployments\"]\n" + "VOLUME [\"VOLUME\"]\n" + "CMD [\"sh\",\"-c\",\"server\"]\n" + "USER 1000\n");
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) Expectations(mockit.Expectations) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) Test(org.junit.Test) AssemblyConfigurationUtils.createDockerFileBuilder(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.createDockerFileBuilder) AssemblyConfigurationUtils.getJKubeAssemblyFileSets(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFileSets) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) File(java.io.File) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault) List(java.util.List) AssemblyConfigurationUtils.getJKubeAssemblyFiles(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles) Assembly(org.eclipse.jkube.kit.common.Assembly) Map(java.util.Map) Arguments(org.eclipse.jkube.kit.config.image.build.Arguments) Injectable(mockit.Injectable) Collections(java.util.Collections) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) List(java.util.List) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) Test(org.junit.Test)

Example 30 with AssemblyConfiguration

use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.

the class AssemblyConfigurationUtilsTest method getAssemblyConfigurationOrCreateDefaultNoConfigurationShouldReturnDefault.

@Test
public void getAssemblyConfigurationOrCreateDefaultNoConfigurationShouldReturnDefault(@Injectable final BuildConfiguration buildConfiguration) {
    // Given
    // @formatter:off
    new Expectations() {

        {
            buildConfiguration.getAssembly();
            result = null;
        }
    };
    // @formatter:on
    // When
    final AssemblyConfiguration result = getAssemblyConfigurationOrCreateDefault(buildConfiguration);
    // Then
    assertThat(result).hasFieldOrPropertyWithValue("name", "maven").hasFieldOrPropertyWithValue("targetDir", "/maven").hasFieldOrPropertyWithValue("user", null);
}
Also used : Expectations(mockit.Expectations) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) Test(org.junit.Test)

Aggregations

AssemblyConfiguration (org.eclipse.jkube.kit.common.AssemblyConfiguration)41 Test (org.junit.Test)32 File (java.io.File)29 Assembly (org.eclipse.jkube.kit.common.Assembly)29 AssemblyFileSet (org.eclipse.jkube.kit.common.AssemblyFileSet)22 AssemblyFileEntry (org.eclipse.jkube.kit.common.AssemblyFileEntry)19 AssemblyFileSetUtils.processAssemblyFileSet (org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet)19 AssemblyFile (org.eclipse.jkube.kit.common.AssemblyFile)12 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)8 List (java.util.List)6 Expectations (mockit.Expectations)6 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 Nonnull (javax.annotation.Nonnull)5 AssemblyConfigurationUtils.getJKubeAssemblyFiles (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles)5 IOException (java.io.IOException)4 Map (java.util.Map)4 AssemblyConfigurationUtils.createDockerFileBuilder (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.createDockerFileBuilder)4 AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault)4 AssemblyConfigurationUtils.getJKubeAssemblyFileSets (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFileSets)4