Search in sources :

Example 11 with JKubeConfiguration

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

the class AssemblyManagerCreateDockerTarArchiveTest method withDockerfileInBaseDirectory.

@Test
public void withDockerfileInBaseDirectory() throws IOException {
    // Given
    final File dockerFile = new File(baseDirectory, "Dockerfile");
    writeLineToFile(dockerFile, "FROM openjdk:jre");
    final JKubeConfiguration configuration = createJKubeConfiguration();
    final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder().dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).build();
    // When
    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"));
    assertDockerFile("test-image").hasContent("FROM openjdk:jre\n");
    assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder("Dockerfile", "maven", "maven/Dockerfile", "maven/test-0.1.0.jar", "maven/target", "maven/target/test-0.1.0.jar");
}
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 12 with JKubeConfiguration

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

the class AssemblyManagerCreateDockerTarArchiveTest method withDockerfileInBaseDirectoryAndDockerignore.

@Test
public void withDockerfileInBaseDirectoryAndDockerignore() throws IOException {
    // Given
    final File dockerFile = new File(baseDirectory, "Dockerfile");
    writeLineToFile(dockerFile, "FROM openjdk:jre");
    writeLineToFile(new File(baseDirectory, ".jkube-dockerignore"), "**/*.txt\ntarget/ill-be-ignored-too");
    writeLineToFile(new File(targetDirectory, "ill-be-ignored.txt"), "Hello");
    writeLineToFile(new File(targetDirectory, "ill-be-ignored-too"), "Hello");
    writeLineToFile(new File(targetDirectory, "i-wont-be-ignored"), "Hello");
    final JKubeConfiguration configuration = createJKubeConfiguration();
    final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder().dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).build();
    // When
    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-dockerignore"));
    assertDockerFile("test-image").hasContent("FROM openjdk:jre\n");
    assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder("Dockerfile", "maven", "maven/Dockerfile", "maven/test-0.1.0.jar", "maven/target", "maven/target/test-0.1.0.jar", "maven/target/i-wont-be-ignored");
}
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 13 with JKubeConfiguration

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

the class AssemblyManagerCreateDockerTarArchiveTest method withoutDockerfileAndFinalCustomizer.

@Test
public void withoutDockerfileAndFinalCustomizer() throws IOException {
    // Given
    final JKubeConfiguration jKubeConfiguration = createJKubeConfiguration();
    final BuildConfiguration buildConfiguration = BuildConfiguration.builder().build();
    final AtomicBoolean customized = new AtomicBoolean(false);
    final ArchiverCustomizer finalCustomizer = ac -> {
        customized.set(true);
        return ac;
    };
    // When
    File dockerArchiveFile = assemblyManager.createDockerTarArchive("no-docker-file-and-customizer", jKubeConfiguration, buildConfiguration, prefixedLogger, finalCustomizer);
    // Then
    assertTargetHasDockerDirectories("no-docker-file-and-customizer");
    ArchiveAssertions.assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSameContentAsDirectory(getExpectedDirectory("without-dockerfile-and-final-customizer"));
    assertDockerFile("no-docker-file-and-customizer").hasContent(DOCKERFILE_DEFAULT_FALLBACK_CONTENT);
    assertBuildDirectoryFileTree("no-docker-file-and-customizer").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");
    assertThat(customized).isTrue();
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) FileAssertions(org.eclipse.jkube.kit.common.assertj.FileAssertions) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) Path(java.nio.file.Path) JavaProject(org.eclipse.jkube.kit.common.JavaProject) Before(org.junit.Before) PrintWriter(java.io.PrintWriter) ArchiveAssertions(org.eclipse.jkube.kit.common.assertj.ArchiveAssertions) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) AbstractListAssert(org.assertj.core.api.AbstractListAssert) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) AbstractFileAssert(org.assertj.core.api.AbstractFileAssert) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) List(java.util.List) Rule(org.junit.Rule) Assembly(org.eclipse.jkube.kit.common.Assembly) ObjectAssert(org.assertj.core.api.ObjectAssert) ListAssert(org.assertj.core.api.ListAssert) PrefixedLogger(org.eclipse.jkube.kit.common.PrefixedLogger) Mocked(mockit.Mocked) TemporaryFolder(org.junit.rules.TemporaryFolder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Test(org.junit.Test)

Example 14 with JKubeConfiguration

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

the class AssemblyManagerCreateDockerTarArchiveTest method createChangedFilesArchive.

@Test
public void createChangedFilesArchive() throws IOException {
    // Given
    final JKubeConfiguration jKubeConfiguration = createJKubeConfiguration();
    final List<AssemblyFileEntry> entries = new ArrayList<>();
    final File assemblyDirectory = temporaryFolder.getRoot().toPath().resolve("target").resolve("docker").toFile();
    entries.add(AssemblyFileEntry.builder().source(temporaryFolder.getRoot().toPath().resolve("target").resolve("test-0.1.0.jar").toFile()).dest(temporaryFolder.getRoot().toPath().resolve("target").resolve("docker").resolve("test-0.1.0.jar").toFile()).fileMode("0655").build());
    // When
    final File result = assemblyManager.createChangedFilesArchive(entries, assemblyDirectory, "image-name", jKubeConfiguration);
    // Then
    ArchiveAssertions.assertThat(result).isFile().hasName("changed-files.tar").hasSameContentAsDirectory(getExpectedDirectory("changed-files.tar"));
}
Also used : AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) ArrayList(java.util.ArrayList) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Test(org.junit.Test)

Example 15 with JKubeConfiguration

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

the class AssemblyManagerCreateDockerTarArchiveTest method withDockerfileInBaseDirectoryAndDockerexclude.

@Test
public void withDockerfileInBaseDirectoryAndDockerexclude() throws IOException {
    // Given
    final File dockerFile = new File(baseDirectory, "Dockerfile");
    writeLineToFile(dockerFile, "FROM openjdk:jre");
    writeLineToFile(new File(baseDirectory, ".jkube-dockerexclude"), "**/*.txt");
    writeLineToFile(new File(targetDirectory, "ill-wont-be-included.txt"), "Hello");
    writeLineToFile(new File(targetDirectory, "ill-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-dockerexclude"));
    assertDockerFile("test-image").hasContent("FROM openjdk:jre\n");
    assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder("Dockerfile", "maven", "maven/Dockerfile", "maven/test-0.1.0.jar", "maven/target", "maven/target/test-0.1.0.jar", "maven/target/ill-be-included");
}
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