Search in sources :

Example 6 with Generator

use of io.fabric8.maven.generator.api.Generator in project jointware by isdream.

the class KubernetesExecutor method doCreate.

/**
 **********************************************************************************
 *
 ***********************************************************************************
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object doCreate(Object client, String kind, Map<String, Map<String, Object>> params) throws Exception {
    Createable instance = (Createable) getKindModel(client, kind);
    KubernetesModelGenerator generator = new KubernetesModelGenerator(getObjectRef());
    Object param = generator.toObject(params, kind);
    return instance.create(param);
}
Also used : Createable(io.fabric8.kubernetes.client.dsl.Createable) KubernetesModelGenerator(com.github.isdream.jointware.kubernetes.KubernetesModelGenerator)

Example 7 with Generator

use of io.fabric8.maven.generator.api.Generator in project fabric8-maven-plugin by fabric8io.

the class GeneratorManager method generate.

public static List<ImageConfiguration> generate(List<ImageConfiguration> imageConfigs, GeneratorContext genCtx, boolean prePackagePhase) throws MojoExecutionException {
    List<ImageConfiguration> ret = imageConfigs;
    PluginServiceFactory<GeneratorContext> pluginFactory = genCtx.isUseProjectClasspath() ? new PluginServiceFactory<GeneratorContext>(genCtx, ClassUtil.createProjectClassLoader(genCtx.getProject(), genCtx.getLogger())) : new PluginServiceFactory<GeneratorContext>(genCtx);
    List<Generator> generators = pluginFactory.createServiceObjects("META-INF/fabric8/generator-default", "META-INF/fabric8/fabric8-generator-default", "META-INF/fabric8/generator", "META-INF/fabric8-generator");
    ProcessorConfig config = genCtx.getConfig();
    Logger log = genCtx.getLogger();
    List<Generator> usableGenerators = config.prepareProcessors(generators, "generator");
    log.verbose("Generators:");
    for (Generator generator : usableGenerators) {
        log.verbose(" - %s", generator.getName());
        if (generator.isApplicable(ret)) {
            log.info("Running generator %s", generator.getName());
            ret = generator.customize(ret, prePackagePhase);
        }
    }
    return ret;
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) Logger(io.fabric8.maven.docker.util.Logger) Generator(io.fabric8.maven.generator.api.Generator) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 8 with Generator

use of io.fabric8.maven.generator.api.Generator 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);
    }
}
Also used : GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 9 with Generator

use of io.fabric8.maven.generator.api.Generator 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;
}
Also used : ImageConfigResolver(io.fabric8.maven.docker.config.handler.ImageConfigResolver) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ImageNameFormatter(io.fabric8.maven.docker.util.ImageNameFormatter) List(java.util.List) ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConstraintViolationException(javax.validation.ConstraintViolationException) Date(java.util.Date)

Example 10 with Generator

use of io.fabric8.maven.generator.api.Generator in project fabric8-maven-plugin by fabric8io.

the class BaseGenerator method addFrom.

/**
 * Add the base image either from configuration or from a given selector
 *
 * @param builder for the build image configuration to add the from to.
 */
protected void addFrom(BuildImageConfiguration.Builder builder) {
    String fromMode = getConfigWithSystemFallbackAndDefault(Config.fromMode, "fabric8.generator.fromMode", getFromModeDefault(context.getMode()));
    String from = getConfigWithSystemFallbackAndDefault(Config.from, "fabric8.generator.from", null);
    if ("docker".equalsIgnoreCase(fromMode)) {
        String fromImage = from;
        if (fromImage == null) {
            fromImage = fromSelector != null ? fromSelector.getFrom() : null;
        }
        builder.from(fromImage);
        log.info("Using Docker image %s as base / builder", fromImage);
    } else if ("istag".equalsIgnoreCase(fromMode)) {
        Map<String, String> fromExt = new HashMap<>();
        if (from != null) {
            ImageName iName = new ImageName(from);
            // user/project is considered to be the namespace
            String tag = iName.getTag();
            if (StringUtils.isBlank(tag)) {
                tag = "latest";
            }
            fromExt.put(OpenShiftBuildStrategy.SourceStrategy.name.key(), iName.getSimpleName() + ":" + tag);
            if (iName.getUser() != null) {
                fromExt.put(OpenShiftBuildStrategy.SourceStrategy.namespace.key(), iName.getUser());
            }
            fromExt.put(OpenShiftBuildStrategy.SourceStrategy.kind.key(), "ImageStreamTag");
        } else {
            fromExt = fromSelector != null ? fromSelector.getImageStreamTagFromExt() : null;
        }
        if (fromExt != null) {
            String namespace = fromExt.get(OpenShiftBuildStrategy.SourceStrategy.namespace.key());
            if (namespace != null) {
                log.info("Using ImageStreamTag '%s' from namespace '%s' as builder image", fromExt.get(OpenShiftBuildStrategy.SourceStrategy.name.key()), namespace);
            } else {
                log.info("Using ImageStreamTag '%s' as builder image", fromExt.get(OpenShiftBuildStrategy.SourceStrategy.name.key()));
            }
            builder.fromExt(fromExt);
        }
    } else {
        throw new IllegalArgumentException(String.format("Invalid 'fromMode' in generator configuration for '%s'", getName()));
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Test (org.junit.Test)9 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)7 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)7 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)6 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)5 Properties (java.util.Properties)5 KubernetesModelGenerator (com.github.isdream.chameleon.container.kubernetes.KubernetesModelGenerator)4 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)4 ArrayList (java.util.ArrayList)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 MavenProject (org.apache.maven.project.MavenProject)3 KubernetesModelGenerator (com.github.isdream.jointware.kubernetes.KubernetesModelGenerator)2 KubernetesResource (io.fabric8.kubernetes.api.model.KubernetesResource)2 StringWriter (java.io.StringWriter)2 Method (java.lang.reflect.Method)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Visitable (io.fabric8.kubernetes.api.builder.Visitable)1 Visitor (io.fabric8.kubernetes.api.builder.Visitor)1 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1