Search in sources :

Example 1 with DockerFileBuilder

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;
}
Also used : DockerFileBuilder(org.eclipse.jkube.kit.config.image.build.DockerFileBuilder) Map(java.util.Map) Assembly(org.eclipse.jkube.kit.common.Assembly) Nonnull(javax.annotation.Nonnull)

Example 2 with DockerFileBuilder

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;
    });
}
Also used : AssemblyConfigurationUtils.createDockerFileBuilder(org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.createDockerFileBuilder) DockerFileBuilder(org.eclipse.jkube.kit.config.image.build.DockerFileBuilder) AssemblyFileUtils.resolveSourceFile(org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.resolveSourceFile) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File)

Example 3 with DockerFileBuilder

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);
}
Also used : DockerFileBuilder(org.eclipse.jkube.kit.config.image.build.DockerFileBuilder)

Aggregations

DockerFileBuilder (org.eclipse.jkube.kit.config.image.build.DockerFileBuilder)3 File (java.io.File)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1 AssemblyConfigurationUtils.createDockerFileBuilder (org.eclipse.jkube.kit.build.api.assembly.AssemblyConfigurationUtils.createDockerFileBuilder)1 Assembly (org.eclipse.jkube.kit.common.Assembly)1 AssemblyFile (org.eclipse.jkube.kit.common.AssemblyFile)1 AssemblyFileUtils.resolveSourceFile (org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.resolveSourceFile)1