Search in sources :

Example 26 with BuildConfiguration

use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration 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 27 with BuildConfiguration

use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration 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 28 with BuildConfiguration

use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration 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)

Example 29 with BuildConfiguration

use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.

the class AssemblyManagerCreateDockerTarArchiveTest method withoutDockerfileAndAlreadyExistingFileInAssemblyGetsOverwritten.

@Test
public void withoutDockerfileAndAlreadyExistingFileInAssemblyGetsOverwritten() throws IOException {
    final JKubeConfiguration jKubeConfiguration = createJKubeConfiguration();
    final BuildConfiguration buildConfiguration = BuildConfiguration.builder().build();
    File dockerArchiveFile;
    // When
    assemblyManager.createDockerTarArchive("modified-image", jKubeConfiguration, buildConfiguration, prefixedLogger, null);
    // Modify file contents
    writeLineToFile(jKubeConfiguration.getProject().getArtifact(), "Modified content");
    dockerArchiveFile = assemblyManager.createDockerTarArchive("modified-image", jKubeConfiguration, buildConfiguration, prefixedLogger, null);
    // Then
    assertTargetHasDockerDirectories("modified-image");
    ArchiveAssertions.assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSameContentAsDirectory(getExpectedDirectory("without-dockerfile-and-already-existing-file-in-assembly-gets-overwritten"));
    assertDockerFile("modified-image").hasContent(DOCKERFILE_DEFAULT_FALLBACK_CONTENT);
    assertBuildDirectoryFileTree("modified-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");
    assertThat(resolveDockerBuild("modified-image").resolve("jkube-generated-layer-final-artifact").resolve("maven").resolve("test-0.1.0.jar")).exists().isRegularFile().hasContent("Modified content");
}
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 30 with BuildConfiguration

use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.

the class BuildService method autoPullBaseImage.

private void autoPullBaseImage(ImageConfiguration imageConfig, ImagePullManager imagePullManager, JKubeConfiguration configuration) throws IOException {
    BuildConfiguration buildConfig = imageConfig.getBuildConfiguration();
    if (buildConfig.getDockerArchive() != null) {
        // No auto pull needed in archive mode
        return;
    }
    List<String> fromImages;
    if (buildConfig.isDockerFileMode()) {
        fromImages = extractBaseFromDockerfile(buildConfig, configuration);
    } else {
        fromImages = new LinkedList<>();
        String baseImage = extractBaseFromConfiguration(buildConfig);
        if (baseImage != null) {
            fromImages.add(baseImage);
        }
    }
    for (String fromImage : fromImages) {
        if (fromImage != null && !AssemblyManager.SCRATCH_IMAGE.equals(fromImage)) {
            registryService.pullImageWithPolicy(fromImage, imagePullManager, configuration.getRegistryConfig(), buildConfig);
        }
    }
}
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