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