Search in sources :

Example 1 with JKubeConfiguration

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

the class BuildUtilTest method extractBaseFromDockerfile_withNonExistentDockerfile_shouldReturnNull.

@Test
public void extractBaseFromDockerfile_withNonExistentDockerfile_shouldReturnNull() {
    // Given
    final JKubeConfiguration jKubeConfiguration = JKubeConfiguration.builder().sourceDirectory("src").project(JavaProject.builder().baseDirectory(new File(".")).build()).build();
    final BuildConfiguration buildConfiguration = BuildConfiguration.builder().dockerFileFile(new File("Dockerfile")).build();
    // When
    final String result = extractBaseFromDockerfile(jKubeConfiguration, buildConfiguration);
    // Then
    assertThat(result).isNull();
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) File(java.io.File) Test(org.junit.Test)

Example 2 with JKubeConfiguration

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

the class AssemblyManager method createAssemblyArchive.

private void createAssemblyArchive(AssemblyConfiguration assemblyConfig, JKubeConfiguration params, BuildDirs buildDirs, ArchiveCompression compression, Map<Assembly, List<AssemblyFileEntry>> layers) throws IOException {
    if (layers.isEmpty()) {
        return;
    }
    AssemblyConfigurationSource source = new AssemblyConfigurationSource(params, buildDirs, assemblyConfig);
    JKubeBuildTarArchiver jkubeTarArchiver = new JKubeBuildTarArchiver();
    AssemblyMode buildMode = assemblyConfig.getMode();
    try {
        layers.values().stream().flatMap(List::stream).filter(afe -> StringUtils.isNotBlank(afe.getFileMode())).forEach(jkubeTarArchiver::setFileMode);
        jkubeTarArchiver.createArchive(source.getOutputDirectory(), buildDirs, compression);
    } catch (IOException e) {
        String error = "Failed to create assembly for docker image " + " (with mode '" + buildMode + "'): " + e.getMessage() + ".";
        if (params.getProject().getArtifact() == null) {
            error += " If you include the build artifact please ensure that you have " + "built the artifact before with 'mvn package' (should be available in the target/ dir). " + "Please see the documentation (section \"Assembly\") for more information.";
        }
        throw new IOException(error, e);
    }
}
Also used : JKubeProjectUtil(org.eclipse.jkube.kit.common.util.JKubeProjectUtil) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) AssemblyConfigurationUtils.createDockerFileBuilder(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.createDockerFileBuilder) DockerFileUtil(org.eclipse.jkube.kit.build.api.helper.DockerFileUtil) StringUtils(org.apache.commons.lang3.StringUtils) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) LinkedHashMap(java.util.LinkedHashMap) AssemblyConfigurationUtils.getJKubeAssemblyFiles(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) Map(java.util.Map) FileUtil(org.eclipse.jkube.kit.common.util.FileUtil) AssemblyMode(org.eclipse.jkube.kit.common.AssemblyMode) Nonnull(javax.annotation.Nonnull) JavaProject(org.eclipse.jkube.kit.common.JavaProject) DockerFileBuilder(org.eclipse.jkube.kit.config.image.build.DockerFileBuilder) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) Properties(java.util.Properties) AssemblyFileUtils.resolveSourceFile(org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.resolveSourceFile) Files(java.nio.file.Files) ArchiveCompression(org.eclipse.jkube.kit.common.archive.ArchiveCompression) BufferedWriter(java.io.BufferedWriter) AssemblyFileUtils.getAssemblyFileOutputDirectory(org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.getAssemblyFileOutputDirectory) FileWriter(java.io.FileWriter) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) IOException(java.io.IOException) AssemblyConfigurationUtils.getJKubeAssemblyFileSets(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFileSets) Collectors(java.util.stream.Collectors) File(java.io.File) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault) KitLogger(org.eclipse.jkube.kit.common.KitLogger) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Assembly(org.eclipse.jkube.kit.common.Assembly) JKubeTarArchiver(org.eclipse.jkube.kit.common.archive.JKubeTarArchiver) Optional(java.util.Optional) AssemblyFileSetUtils.processAssemblyFileSet(org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet) AssemblyMode(org.eclipse.jkube.kit.common.AssemblyMode) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 3 with JKubeConfiguration

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

the class AssemblyManager method copyFilesToFinalTarballDirectory.

public Map<Assembly, List<AssemblyFileEntry>> copyFilesToFinalTarballDirectory(JKubeConfiguration configuration, BuildDirs buildDirs, AssemblyConfiguration assemblyConfiguration) throws IOException {
    final Map<Assembly, List<AssemblyFileEntry>> entries = new LinkedHashMap<>();
    FileUtil.createDirectory(new File(buildDirs.getOutputDirectory(), assemblyConfiguration.getTargetDir()));
    final List<Assembly> layers = assemblyConfiguration.getProcessedLayers(configuration);
    if (layers.size() > 1 && layers.stream().anyMatch(l -> StringUtils.isBlank(l.getId()))) {
        throw new IllegalStateException("Assemblies with more than one layer require a proper id for each layer");
    }
    for (Assembly layer : layers) {
        entries.put(layer, copyLayerFilesToFinalTarballDirectory(configuration.getProject(), buildDirs, assemblyConfiguration, layer));
    }
    return entries;
}
Also used : JKubeProjectUtil(org.eclipse.jkube.kit.common.util.JKubeProjectUtil) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) AssemblyConfigurationUtils.createDockerFileBuilder(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.createDockerFileBuilder) DockerFileUtil(org.eclipse.jkube.kit.build.api.helper.DockerFileUtil) StringUtils(org.apache.commons.lang3.StringUtils) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) LinkedHashMap(java.util.LinkedHashMap) AssemblyConfigurationUtils.getJKubeAssemblyFiles(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFiles) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) Map(java.util.Map) FileUtil(org.eclipse.jkube.kit.common.util.FileUtil) AssemblyMode(org.eclipse.jkube.kit.common.AssemblyMode) Nonnull(javax.annotation.Nonnull) JavaProject(org.eclipse.jkube.kit.common.JavaProject) DockerFileBuilder(org.eclipse.jkube.kit.config.image.build.DockerFileBuilder) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) Properties(java.util.Properties) AssemblyFileUtils.resolveSourceFile(org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.resolveSourceFile) Files(java.nio.file.Files) ArchiveCompression(org.eclipse.jkube.kit.common.archive.ArchiveCompression) BufferedWriter(java.io.BufferedWriter) AssemblyFileUtils.getAssemblyFileOutputDirectory(org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.getAssemblyFileOutputDirectory) FileWriter(java.io.FileWriter) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) IOException(java.io.IOException) AssemblyConfigurationUtils.getJKubeAssemblyFileSets(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getJKubeAssemblyFileSets) Collectors(java.util.stream.Collectors) File(java.io.File) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.getAssemblyConfigurationOrCreateDefault) KitLogger(org.eclipse.jkube.kit.common.KitLogger) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Assembly(org.eclipse.jkube.kit.common.Assembly) JKubeTarArchiver(org.eclipse.jkube.kit.common.archive.JKubeTarArchiver) Optional(java.util.Optional) AssemblyFileSetUtils.processAssemblyFileSet(org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet) ArrayList(java.util.ArrayList) List(java.util.List) AssemblyFileUtils.resolveSourceFile(org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.resolveSourceFile) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with JKubeConfiguration

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

the class AssemblyManagerCreateDockerTarArchiveTest method withoutDockerfile.

@Test
public void withoutDockerfile() throws IOException {
    // Given
    final JKubeConfiguration jKubeConfiguration = createJKubeConfiguration();
    final BuildConfiguration buildConfiguration = BuildConfiguration.builder().build();
    // When
    File dockerArchiveFile = assemblyManager.createDockerTarArchive("test-image", jKubeConfiguration, buildConfiguration, prefixedLogger, null);
    // Then
    assertTargetHasDockerDirectories("test-image");
    ArchiveAssertions.assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSameContentAsDirectory(getExpectedDirectory("without-dockerfile"));
    assertDockerFile("test-image").hasContent(DOCKERFILE_DEFAULT_FALLBACK_CONTENT);
    assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder("Dockerfile", "jkube-generated-layer-final-artifact", "jkube-generated-layer-final-artifact/maven", "jkube-generated-layer-final-artifact/maven/test-0.1.0.jar", "maven");
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Test(org.junit.Test)

Example 5 with JKubeConfiguration

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

the class AssemblyManagerCreateDockerTarArchiveTest method withDockerfileInBaseDirectoryAndDockerinclude.

@Test
public void withDockerfileInBaseDirectoryAndDockerinclude() throws IOException {
    // Given
    final File dockerFile = new File(baseDirectory, "Dockerfile");
    writeLineToFile(dockerFile, "FROM openjdk:jre");
    writeLineToFile(new File(baseDirectory, ".jkube-dockerinclude"), "**/*.txt");
    writeLineToFile(new File(targetDirectory, "ill-be-included.txt"), "Hello");
    writeLineToFile(new File(targetDirectory, "ill-wont-be-included"), "Hello");
    final JKubeConfiguration configuration = createJKubeConfiguration();
    final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder().dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).build();
    // When
    final File dockerArchiveFile = assemblyManager.createDockerTarArchive("test-image", configuration, jKubeBuildConfiguration, prefixedLogger, null);
    // Then
    assertTargetHasDockerDirectories("test-image");
    ArchiveAssertions.assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSameContentAsDirectory(getExpectedDirectory("with-dockerfile-in-base-directory-and-dockerinclude"));
    assertDockerFile("test-image").hasContent("FROM openjdk:jre\n");
    assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder("Dockerfile", "maven", "maven/test-0.1.0.jar", "maven/target", "maven/target/ill-be-included.txt");
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Test(org.junit.Test)

Aggregations

JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)23 File (java.io.File)15 Test (org.junit.Test)13 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)12 AssemblyFile (org.eclipse.jkube.kit.common.AssemblyFile)11 KitLogger (org.eclipse.jkube.kit.common.KitLogger)6 IOException (java.io.IOException)5 List (java.util.List)5 ArrayList (java.util.ArrayList)4 AssemblyConfiguration (org.eclipse.jkube.kit.common.AssemblyConfiguration)4 AssemblyFileEntry (org.eclipse.jkube.kit.common.AssemblyFileEntry)4 JavaProject (org.eclipse.jkube.kit.common.JavaProject)4 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)4 Map (java.util.Map)3 Optional (java.util.Optional)3 Properties (java.util.Properties)3 Assembly (org.eclipse.jkube.kit.common.Assembly)3 Before (org.junit.Before)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2