Search in sources :

Example 86 with Builder

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);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) BuildOutput(io.fabric8.openshift.api.model.BuildOutput) BuildStrategy(io.fabric8.openshift.api.model.BuildStrategy) OpenShiftBuildStrategy(io.fabric8.maven.core.config.OpenShiftBuildStrategy) BuildOutputBuilder(io.fabric8.openshift.api.model.BuildOutputBuilder) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) BuildConfigSpec(io.fabric8.openshift.api.model.BuildConfigSpec)

Example 87 with Builder

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);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) Build(io.fabric8.openshift.api.model.Build) File(java.io.File) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 88 with Builder

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();
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata)

Example 89 with Builder

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();
}
Also used : ReplicaSetSpec(io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet)

Example 90 with Builder

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();
    }
}
Also used : Path(java.nio.file.Path) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ComposeService(io.fabric8.maven.core.service.ComposeService) ConstraintViolationException(javax.validation.ConstraintViolationException) File(java.io.File)

Aggregations

Test (org.junit.Test)60 ProfileBuilder (io.fabric8.api.ProfileBuilder)34 Profile (io.fabric8.api.Profile)33 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)27 FabricService (io.fabric8.api.FabricService)24 InputStream (java.io.InputStream)21 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 HashMap (java.util.HashMap)19 Map (java.util.Map)19 Logger (org.slf4j.Logger)19 CommandSupport (io.fabric8.itests.support.CommandSupport)18 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)17 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)16 IOException (java.io.IOException)16 Action (org.apache.felix.gogo.commands.Action)16 AbstractCommand (org.apache.felix.gogo.commands.basic.AbstractCommand)16