use of io.fabric8.maven.docker.config.CopyConfiguration.Builder 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.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method build.
@Override
public void build(ImageConfiguration imageConfig) throws Fabric8ServiceException {
try {
ImageName imageName = new ImageName(imageConfig.getName());
File dockerTar = createBuildArchive(imageConfig);
KubernetesListBuilder builder = new KubernetesListBuilder();
// Check for buildconfig / imagestream and create them if necessary
String buildName = updateOrCreateBuildConfig(config, client, builder, imageConfig);
checkOrCreateImageStream(config, client, builder, getImageStreamName(imageName));
applyResourceObjects(config, client, builder);
// Start the actual build
Build build = startBuild(client, dockerTar, buildName);
// Wait until the build finishes
waitForOpenShiftBuildToComplete(client, build);
// Create a file with generated image streams
addImageStreamToFile(getImageStreamFile(config), imageName, client);
} catch (Fabric8ServiceException e) {
throw e;
} catch (Exception ex) {
throw new Fabric8ServiceException("Unable to build the image using the OpenShift build service", ex);
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.
the class ValidationUtil method createValidationMessage.
public static String createValidationMessage(Set<ConstraintViolation<?>> constraintViolations) {
if (constraintViolations.isEmpty()) {
return "No Constraint Validations!";
}
StringBuilder builder = new StringBuilder("Constraint Validations: ");
for (ConstraintViolation<?> violation : constraintViolations) {
if (builder.length() > 0) {
builder.append(", ");
}
Object leafBean = violation.getLeafBean();
if (leafBean instanceof HasMetadata) {
HasMetadata hasMetadata = (HasMetadata) leafBean;
ObjectMeta metadata = hasMetadata.getMetadata();
if (metadata != null) {
leafBean = "" + hasMetadata.getKind() + ": " + metadata;
}
}
builder.append(violation.getPropertyPath() + " " + violation.getMessage() + " on bean: " + leafBean);
}
return builder.toString();
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.
the class ReplicSetOpenShiftConverter method convert.
@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
ReplicaSet resource = (ReplicaSet) item;
ReplicationControllerBuilder builder = new ReplicationControllerBuilder();
builder.withMetadata(resource.getMetadata());
ReplicaSetSpec spec = resource.getSpec();
if (spec != null) {
ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder> specBuilder = builder.withNewSpec();
Integer replicas = spec.getReplicas();
if (replicas != null) {
specBuilder.withReplicas(replicas);
}
LabelSelector selector = spec.getSelector();
if (selector != null) {
Map<String, String> matchLabels = selector.getMatchLabels();
if (matchLabels != null && !matchLabels.isEmpty()) {
specBuilder.withSelector(matchLabels);
}
}
PodTemplateSpec template = spec.getTemplate();
if (template != null) {
specBuilder.withTemplate(template);
}
specBuilder.endSpec();
}
return builder.build();
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method generateAppResources.
private KubernetesListBuilder generateAppResources(List<ImageConfiguration> images, EnricherManager enricherManager) throws IOException, MojoExecutionException {
Path composeFilePath = checkComposeConfig();
ComposeService composeUtil = new ComposeService(komposeBinDir, composeFilePath, log);
try {
File[] resourceFiles = KubernetesResourceUtil.listResourceFragments(resourceDir);
File[] composeResourceFiles = composeUtil.convertToKubeFragments();
File[] allResources = ArrayUtils.addAll(resourceFiles, composeResourceFiles);
KubernetesListBuilder builder;
// Add resource files found in the fabric8 directory
if (allResources != null && allResources.length > 0) {
if (resourceFiles != null && resourceFiles.length > 0) {
log.info("using resource templates from %s", resourceDir);
}
if (composeResourceFiles != null && composeResourceFiles.length > 0) {
log.info("using resource templates generated from compose file");
}
builder = readResourceFragments(allResources);
} else {
builder = new KubernetesListBuilder();
}
// Add locally configured objects
if (resources != null) {
// TODO: Allow also support resources to be specified via XML
addConfiguredResources(builder, images);
}
// Create default resources for app resources only
enricherManager.createDefaultResources(builder);
// Enrich descriptors
enricherManager.enrich(builder);
return builder;
} catch (ConstraintViolationException e) {
String message = ValidationUtil.createValidationMessage(e.getConstraintViolations());
log.error("ConstraintViolationException: %s", message);
throw new MojoExecutionException(message, e);
} catch (Fabric8ServiceException e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
composeUtil.cleanComposeResources();
}
}
Aggregations