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");
}
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();
}
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");
}
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");
}
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);
}
}
}
Aggregations