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