use of io.fabric8.openshift.api.model.BuildStrategy in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method updateOrCreateBuildConfig.
private String updateOrCreateBuildConfig(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, ImageConfiguration imageConfig) {
ImageName imageName = new ImageName(imageConfig.getName());
String buildName = getS2IBuildName(config, imageName);
String imageStreamName = getImageStreamName(imageName);
String outputImageStreamTag = imageStreamName + ":" + (imageName.getTag() != null ? imageName.getTag() : "latest");
BuildStrategy buildStrategyResource = createBuildStrategy(imageConfig, config.getOpenshiftBuildStrategy());
BuildOutput buildOutput = new BuildOutputBuilder().withNewTo().withKind("ImageStreamTag").withName(outputImageStreamTag).endTo().build();
// Fetch exsting build config
BuildConfig buildConfig = client.buildConfigs().withName(buildName).get();
if (buildConfig != null) {
// lets verify the BC
BuildConfigSpec spec = getBuildConfigSpec(buildConfig);
validateSourceType(buildName, spec);
if (config.getBuildRecreateMode().isBuildConfig()) {
// Delete and recreate afresh
client.buildConfigs().withName(buildName).delete();
return createBuildConfig(builder, buildName, buildStrategyResource, buildOutput);
} else {
// Update & return
return updateBuildConfig(client, buildName, buildStrategyResource, buildOutput, spec);
}
} else {
// Create afresh
return createBuildConfig(builder, buildName, buildStrategyResource, buildOutput);
}
}
use of io.fabric8.openshift.api.model.BuildStrategy in project fabric8-maven-plugin by fabric8io.
the class PushMojo method customizeConfig.
/**
* Customization hook called by the base plugin.
*
* @param configs configuration to customize
* @return the configuration customized by our generators.
*/
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
try {
ProcessorConfig generatorConfig = ProfileUtil.blendProfileWithConfiguration(ProfileUtil.GENERATOR_CONFIG, profile, resourceDir, generator);
GeneratorContext ctx = new GeneratorContext.Builder().config(generatorConfig).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:push").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(false).build();
return GeneratorManager.generate(configs, ctx, true);
} catch (Exception e) {
throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
}
}
use of io.fabric8.openshift.api.model.BuildStrategy in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method getResolvedImages.
private List<ImageConfiguration> getResolvedImages(List<ImageConfiguration> images, final Logger log) throws MojoExecutionException {
List<ImageConfiguration> ret;
ret = ConfigHelper.resolveImages(log, images, new ConfigHelper.Resolver() {
@Override
public List<ImageConfiguration> resolve(ImageConfiguration image) {
return imageConfigResolver.resolve(image, project, session);
}
}, // no filter on image name yet (TODO: Maybe add this, too ?)
null, new ConfigHelper.Customizer() {
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
try {
GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:resource").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).build();
return GeneratorManager.generate(configs, ctx, true);
} catch (Exception e) {
throw new IllegalArgumentException("Cannot extract generator: " + e, e);
}
}
});
Date now = getBuildReferenceDate();
storeReferenceDateInPluginContext(now);
String minimalApiVersion = ConfigHelper.initAndValidate(ret, null, /* no minimal api version */
new ImageNameFormatter(project, now), log);
return ret;
}
use of io.fabric8.openshift.api.model.BuildStrategy in project fabric8-maven-plugin by fabric8io.
the class WatchMojo method customizeConfig.
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
try {
Fabric8ServiceHub serviceHub = getFabric8ServiceHub();
GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:watch").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).artifactResolver(serviceHub.getArtifactResolverService()).build();
return GeneratorManager.generate(configs, ctx, false);
} catch (MojoExecutionException e) {
throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
}
}
use of io.fabric8.openshift.api.model.BuildStrategy in project fabric8 by fabric8io.
the class Builds method configureDefaultBuildConfig.
public static BuildConfig configureDefaultBuildConfig(BuildConfig buildConfig, String name, String gitUrl, boolean foundExistingGitUrl, String buildImageStream, String buildImageTag, String s2iCustomBuilderImage, String secret, String jenkinsUrl) {
BuildConfigSpec spec = buildConfig.getSpec();
if (spec == null) {
spec = new BuildConfigSpec();
buildConfig.setSpec(spec);
}
if (!foundExistingGitUrl && Strings.isNotBlank(gitUrl)) {
BuildSource source = spec.getSource();
if (source == null) {
source = new BuildSource();
spec.setSource(source);
}
source.setType("Git");
GitBuildSource git = source.getGit();
if (git == null) {
git = new GitBuildSource();
source.setGit(git);
}
git.setUri(gitUrl);
}
if (Strings.isNotBlank(buildImageStream) && Strings.isNotBlank(buildImageTag)) {
BuildStrategy strategy = spec.getStrategy();
if (strategy == null) {
strategy = new BuildStrategy();
spec.setStrategy(strategy);
}
// TODO only do this if we are using Jenkins?
strategy.setType("JenkinsPipeline");
JenkinsPipelineBuildStrategy buildStrategy = strategy.getJenkinsPipelineStrategy();
if (buildStrategy == null) {
buildStrategy = new JenkinsPipelineBuildStrategy();
strategy.setJenkinsPipelineStrategy(buildStrategy);
}
ListEnvVarBuilder envBuilder = new ListEnvVarBuilder();
if (Strings.isNotBlank(jenkinsUrl)) {
envBuilder.withEnvVar("BASE_URI", jenkinsUrl);
}
buildStrategy.setJenkinsfilePath("Jenkinsfile");
}
List<BuildTriggerPolicy> triggers = spec.getTriggers();
if (triggers == null) {
triggers = new ArrayList<>();
}
if (triggers.isEmpty()) {
triggers.add(new BuildTriggerPolicyBuilder().withType("GitHub").withNewGithub().withSecret(secret).endGithub().build());
triggers.add(new BuildTriggerPolicyBuilder().withType("Generic").withNewGeneric().withSecret(secret).endGeneric().build());
spec.setTriggers(triggers);
}
return buildConfig;
}
Aggregations