Search in sources :

Example 1 with DockerBuildStrategyBuilder

use of io.fabric8.openshift.api.model.DockerBuildStrategyBuilder in project strimzi by strimzi.

the class KafkaConnectBuild method generateBuildConfig.

/**
 * Generates a BuildConfig which will be used to build new container images with additional connector plugins on OCP.
 *
 * @param dockerfile    Dockerfile which should be built by the BuildConfig
 *
 * @return  OpenShift BuildConfig for building new container images on OpenShift
 */
public BuildConfig generateBuildConfig(KafkaConnectDockerfile dockerfile) {
    BuildOutput output;
    if (build.getOutput() instanceof DockerOutput) {
        DockerOutput dockerOutput = (DockerOutput) build.getOutput();
        output = new BuildOutputBuilder().withNewTo().withKind("DockerImage").withName(dockerOutput.getImage()).endTo().build();
        if (dockerOutput.getPushSecret() != null) {
            output.setPushSecret(new LocalObjectReferenceBuilder().withName(dockerOutput.getPushSecret()).build());
        }
    } else if (build.getOutput() instanceof ImageStreamOutput) {
        ImageStreamOutput imageStreamOutput = (ImageStreamOutput) build.getOutput();
        output = new BuildOutputBuilder().withNewTo().withKind("ImageStreamTag").withName(imageStreamOutput.getImage()).endTo().build();
    } else {
        throw new RuntimeException("Unknown output type " + build.getOutput().getType());
    }
    DockerBuildStrategyBuilder dockerBuildStrategyBuilder = new DockerBuildStrategyBuilder();
    if (pullSecret != null) {
        dockerBuildStrategyBuilder.withNewPullSecret().withName(pullSecret).endPullSecret();
    }
    return new BuildConfigBuilder().withNewMetadata().withName(KafkaConnectResources.buildConfigName(cluster)).withLabels(getLabelsWithStrimziName(name, templateBuildConfigLabels).toMap()).withAnnotations(templateBuildConfigAnnotations).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withOutput(output).withNewSource().withType("Dockerfile").withDockerfile(dockerfile.getDockerfile()).endSource().withNewStrategy().withType("Docker").withDockerStrategy(dockerBuildStrategyBuilder.build()).endStrategy().withResources(build.getResources()).withRunPolicy("Serial").withFailedBuildsHistoryLimit(5).withSuccessfulBuildsHistoryLimit(5).withFailedBuildsHistoryLimit(5).endSpec().build();
}
Also used : BuildOutput(io.fabric8.openshift.api.model.BuildOutput) ImageStreamOutput(io.strimzi.api.kafka.model.connect.build.ImageStreamOutput) DockerBuildStrategyBuilder(io.fabric8.openshift.api.model.DockerBuildStrategyBuilder) BuildOutputBuilder(io.fabric8.openshift.api.model.BuildOutputBuilder) DockerOutput(io.strimzi.api.kafka.model.connect.build.DockerOutput) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder)

Example 2 with DockerBuildStrategyBuilder

use of io.fabric8.openshift.api.model.DockerBuildStrategyBuilder in project strimzi-kafka-operator by strimzi.

the class KafkaConnectBuild method generateBuildConfig.

/**
 * Generates a BuildConfig which will be used to build new container images with additional connector plugins on OCP.
 *
 * @param dockerfile    Dockerfile which should be built by the BuildConfig
 *
 * @return  OpenShift BuildConfig for building new container images on OpenShift
 */
public BuildConfig generateBuildConfig(KafkaConnectDockerfile dockerfile) {
    BuildOutput output;
    if (build.getOutput() instanceof DockerOutput) {
        DockerOutput dockerOutput = (DockerOutput) build.getOutput();
        output = new BuildOutputBuilder().withNewTo().withKind("DockerImage").withName(dockerOutput.getImage()).endTo().build();
        if (dockerOutput.getPushSecret() != null) {
            output.setPushSecret(new LocalObjectReferenceBuilder().withName(dockerOutput.getPushSecret()).build());
        }
    } else if (build.getOutput() instanceof ImageStreamOutput) {
        ImageStreamOutput imageStreamOutput = (ImageStreamOutput) build.getOutput();
        output = new BuildOutputBuilder().withNewTo().withKind("ImageStreamTag").withName(imageStreamOutput.getImage()).endTo().build();
    } else {
        throw new RuntimeException("Unknown output type " + build.getOutput().getType());
    }
    DockerBuildStrategyBuilder dockerBuildStrategyBuilder = new DockerBuildStrategyBuilder();
    if (pullSecret != null) {
        dockerBuildStrategyBuilder.withNewPullSecret().withName(pullSecret).endPullSecret();
    }
    return new BuildConfigBuilder().withNewMetadata().withName(KafkaConnectResources.buildConfigName(cluster)).withLabels(getLabelsWithStrimziName(name, templateBuildConfigLabels).toMap()).withAnnotations(templateBuildConfigAnnotations).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withOutput(output).withNewSource().withType("Dockerfile").withDockerfile(dockerfile.getDockerfile()).endSource().withNewStrategy().withType("Docker").withDockerStrategy(dockerBuildStrategyBuilder.build()).endStrategy().withResources(build.getResources()).withRunPolicy("Serial").withFailedBuildsHistoryLimit(5).withSuccessfulBuildsHistoryLimit(5).withFailedBuildsHistoryLimit(5).endSpec().build();
}
Also used : BuildOutput(io.fabric8.openshift.api.model.BuildOutput) ImageStreamOutput(io.strimzi.api.kafka.model.connect.build.ImageStreamOutput) DockerBuildStrategyBuilder(io.fabric8.openshift.api.model.DockerBuildStrategyBuilder) BuildOutputBuilder(io.fabric8.openshift.api.model.BuildOutputBuilder) DockerOutput(io.strimzi.api.kafka.model.connect.build.DockerOutput) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder)

Aggregations

LocalObjectReferenceBuilder (io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder)2 BuildConfigBuilder (io.fabric8.openshift.api.model.BuildConfigBuilder)2 BuildOutput (io.fabric8.openshift.api.model.BuildOutput)2 BuildOutputBuilder (io.fabric8.openshift.api.model.BuildOutputBuilder)2 DockerBuildStrategyBuilder (io.fabric8.openshift.api.model.DockerBuildStrategyBuilder)2 DockerOutput (io.strimzi.api.kafka.model.connect.build.DockerOutput)2 ImageStreamOutput (io.strimzi.api.kafka.model.connect.build.ImageStreamOutput)2