Search in sources :

Example 26 with Assembly

use of org.eclipse.jkube.kit.common.Assembly 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 27 with Assembly

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

the class AssemblyConfigurationUtils method createDockerFileBuilder.

@Nonnull
static DockerFileBuilder createDockerFileBuilder(BuildConfiguration buildConfig, AssemblyConfiguration assemblyConfig, Map<Assembly, List<AssemblyFileEntry>> layers) {
    DockerFileBuilder builder = new DockerFileBuilder().baseImage(buildConfig.getFrom()).env(buildConfig.getEnv()).labels(buildConfig.getLabels()).expose(buildConfig.getPorts()).run(buildConfig.getRunCmds()).volumes(buildConfig.getVolumes()).user(buildConfig.getUser());
    Optional.ofNullable(buildConfig.getMaintainer()).ifPresent(builder::maintainer);
    Optional.ofNullable(buildConfig.getWorkdir()).ifPresent(builder::workdir);
    Optional.ofNullable(buildConfig.getHealthCheck()).ifPresent(builder::healthCheck);
    Optional.ofNullable(buildConfig.getCmd()).ifPresent(builder::cmd);
    Optional.ofNullable(buildConfig.getEntryPoint()).ifPresent(builder::entryPoint);
    if (assemblyConfig != null) {
        builder.basedir(assemblyConfig.getTargetDir()).assemblyUser(assemblyConfig.getUser()).exportTargetDir(assemblyConfig.getExportTargetDir());
        if (layers.isEmpty()) {
            builder.add(assemblyConfig.getTargetDir(), "");
        }
        final List<Assembly> effectiveLayers = layers.entrySet().stream().filter(e -> !e.getValue().isEmpty()).map(Map.Entry::getKey).collect(Collectors.toList());
        for (Assembly layer : effectiveLayers) {
            if (StringUtils.isNotBlank(layer.getId())) {
                builder.add(StringUtils.prependIfMissing(layer.getId(), "/") + assemblyConfig.getTargetDir(), "");
            } else {
                builder.add(assemblyConfig.getTargetDir(), "");
            }
        }
    } else {
        builder.exportTargetDir(false);
    }
    if (buildConfig.optimise()) {
        builder.optimise();
    }
    return builder;
}
Also used : DockerFileBuilder(org.eclipse.jkube.kit.config.image.build.DockerFileBuilder) Map(java.util.Map) Assembly(org.eclipse.jkube.kit.common.Assembly) Nonnull(javax.annotation.Nonnull)

Example 28 with Assembly

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

the class JibBuildServiceBuildIntegrationTest method build_withLayersAndArtifact_shouldPerformJibBuild.

@Test
public void build_withLayersAndArtifact_shouldPerformJibBuild() throws Exception {
    // Given
    FileUtils.touch(new File(targetDirectory, "final-artifact.jar"));
    final File dlFile = new File(targetDirectory, "to-deployments.txt");
    FileUtils.touch(dlFile);
    final File otherFile = new File(targetDirectory, "to-other.txt");
    FileUtils.touch(otherFile);
    final ImageConfiguration ic = imageConfiguration.toBuilder().build(BuildConfiguration.builder().assembly(AssemblyConfiguration.builder().name("custom").targetDir("/deployments").layer(Assembly.builder().id("deployments-layer").file(AssemblyFile.builder().outputDirectory(new File(".")).source(dlFile).destName(dlFile.getName()).build()).build()).layer(Assembly.builder().id("other-layer").file(AssemblyFile.builder().outputDirectory(new File("other")).source(otherFile).destName(otherFile.getName()).build()).build()).build()).build()).build();
    // When
    jibBuildService.build(ic);
    // Then
    assertDockerFile().hasContent("FROM busybox\n" + "COPY /deployments-layer/deployments /deployments/\n" + "COPY /other-layer/deployments /deployments/\n" + "COPY /jkube-generated-layer-final-artifact/deployments /deployments/\n" + "VOLUME [\"/deployments\"]");
    FileAssertions.assertThat(resolveDockerBuildDirs().resolve("build").toFile()).fileTree().containsExactlyInAnyOrder("Dockerfile", "deployments-layer", "deployments-layer/deployments", "deployments-layer/deployments/to-deployments.txt", "other-layer", "other-layer/deployments", "other-layer/deployments/other", "other-layer/deployments/other/to-other.txt", "jkube-generated-layer-final-artifact", "jkube-generated-layer-final-artifact/deployments", "jkube-generated-layer-final-artifact/deployments/final-artifact.jar", "deployments");
    ArchiveAssertions.assertThat(resolveDockerBuildDirs().resolve("tmp").resolve("docker-build.tar").toFile()).fileTree().hasSize(6).contains("config.json", "manifest.json").haveExactly(4, new Condition<>(s -> s.endsWith(".tar.gz"), "Tar File layers"));
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) FileAssertions(org.eclipse.jkube.kit.common.assertj.FileAssertions) Expectations(mockit.Expectations) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assert.assertThrows(org.junit.Assert.assertThrows) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) Path(java.nio.file.Path) JavaProject(org.eclipse.jkube.kit.common.JavaProject) Before(org.junit.Before) ArchiveAssertions(org.eclipse.jkube.kit.common.assertj.ArchiveAssertions) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) Properties(java.util.Properties) RegistryConfig(org.eclipse.jkube.kit.common.RegistryConfig) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) AbstractFileAssert(org.assertj.core.api.AbstractFileAssert) File(java.io.File) KitLogger(org.eclipse.jkube.kit.common.KitLogger) Rule(org.junit.Rule) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) Assembly(org.eclipse.jkube.kit.common.Assembly) Condition(org.assertj.core.api.Condition) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Collections(java.util.Collections) Mocked(mockit.Mocked) TemporaryFolder(org.junit.rules.TemporaryFolder) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Test(org.junit.Test)

Example 29 with Assembly

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

the class AssemblyFileSetUtilsProcessAssemblyFileSetTest method assemblyConfigurationHasNoTargetDir_shouldThrowException.

@Test
public void assemblyConfigurationHasNoTargetDir_shouldThrowException() {
    // Given
    final AssemblyFileSet afs = AssemblyFileSet.builder().directory(sourceDirectory).build();
    final Assembly layer = new Assembly();
    final AssemblyConfiguration ac = AssemblyConfiguration.builder().build();
    // When
    final NullPointerException result = Assert.assertThrows(NullPointerException.class, () -> processAssemblyFileSet(baseDirectory, outputDirectory, afs, layer, ac));
    // Then
    assertThat(result).hasMessage("Assembly Configuration target dir is required");
}
Also used : AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) AssemblyFileSetUtils.processAssemblyFileSet(org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet) Assembly(org.eclipse.jkube.kit.common.Assembly) Test(org.junit.Test)

Example 30 with Assembly

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

the class AssemblyFileSetUtilsProcessAssemblyFileSetTest method fileSetDirectoryAndOutputDirectoryResolvingToSelf.

/**
 * Has AssemblyFileSet with directory and outputDirectory relative path resolving to self.
 * Has AssemblyConfiguration targetDir.
 *
 * Should copy <b>contents</b> of AssemblyFileSet#directory to the outputDirectory in a subdirectory named as the
 * AssemblyConfiguration#targetDir.
 */
@Test
public void fileSetDirectoryAndOutputDirectoryResolvingToSelf() throws Exception {
    // Given
    final AssemblyFileSet afs = AssemblyFileSet.builder().directory(sourceDirectory).outputDirectory(new File(".")).build();
    final Assembly layer = new Assembly();
    final AssemblyConfiguration ac = AssemblyConfiguration.builder().name("NotImportant").targetDir("deployments").build();
    // When
    final List<AssemblyFileEntry> result = processAssemblyFileSet(baseDirectory, outputDirectory, afs, layer, ac);
    // Then
    assertThat(result).hasSize(16);
    FileAssertions.assertThat(new File(outputDirectory, "deployments")).exists().fileTree().containsExactlyInAnyOrder("1.txt", "3.other", "37", "one", "one/1.txt", "one/3.other", "one/37", "two", "two/1.txt", "two/3.other", "two/37", "three", "three/1.txt", "three/3.other", "three/37").doesNotContainSequence("source-directory");
}
Also used : AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) AssemblyFileSetUtils.processAssemblyFileSet(org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) Test(org.junit.Test)

Aggregations

Assembly (org.eclipse.jkube.kit.common.Assembly)36 AssemblyConfiguration (org.eclipse.jkube.kit.common.AssemblyConfiguration)31 File (java.io.File)29 Test (org.junit.Test)29 AssemblyFileSet (org.eclipse.jkube.kit.common.AssemblyFileSet)22 AssemblyFileEntry (org.eclipse.jkube.kit.common.AssemblyFileEntry)21 AssemblyFileSetUtils.processAssemblyFileSet (org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet)18 AssemblyFile (org.eclipse.jkube.kit.common.AssemblyFile)12 List (java.util.List)9 Map (java.util.Map)7 IOException (java.io.IOException)6 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)6 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 Collectors (java.util.stream.Collectors)5 Nonnull (javax.annotation.Nonnull)5 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 AssemblyConfigurationUtils.getJKubeAssemblyFiles (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles)4