use of org.eclipse.jkube.kit.config.image.build.DockerFileBuilder 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.config.image.build.DockerFileBuilder in project jkube by eclipse.
the class AssemblyManager method createDockerTarArchiveForGeneratorMode.
private void createDockerTarArchiveForGeneratorMode(BuildConfiguration buildConfig, BuildDirs buildDirs, List<ArchiverCustomizer> archiveCustomizers, AssemblyConfiguration assemblyConfiguration, Map<Assembly, List<AssemblyFileEntry>> layers) throws IOException {
// Create custom docker file in output dir
DockerFileBuilder builder = createDockerFileBuilder(buildConfig, assemblyConfiguration, layers);
builder.write(buildDirs.getOutputDirectory());
// Add own Dockerfile
final File dockerFile = new File(buildDirs.getOutputDirectory(), DOCKERFILE_NAME);
archiveCustomizers.add(archiver -> {
archiver.includeFile(dockerFile, DOCKERFILE_NAME);
return archiver;
});
}
use of org.eclipse.jkube.kit.config.image.build.DockerFileBuilder in project jkube by eclipse.
the class DynamicDockerfileGenerator method generateDockerfile.
/**
* Generates a Dockerfile dynamically with any entries you wish and writes it to the provided directory
*/
private void generateDockerfile(File targetDirectory) throws IOException {
kitLogger.info("Generating dynamic Dockerfile");
new DockerFileBuilder().basedir("/").baseImage("busybox").expose(Collections.singletonList("8080")).env(Collections.singletonMap("JAVA_OPTIONS", "-Xmx1500m")).add("/static/hello-docker.txt", "/home/app/file.txt").add("/static/hello-docker-other.txt", "/home/app/file-2.txt").add("/other-directory/*.txt", "/home/resources/").cmd(Arguments.builder().shell("/bin/sh").build()).write(targetDirectory);
}
Aggregations