Search in sources :

Example 41 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.

the class StatefulSetHandlerTest method before.

@Before
public void before() {
    // volume config with name and multiple mount
    mounts.add("/path/system");
    mounts.add("/path/sys");
    ports.add("8080");
    ports.add("9090");
    tags.add("latest");
    tags.add("test");
    VolumeConfig volumeConfig1 = new VolumeConfig.Builder().name("test").mounts(mounts).type("hostPath").path("/test/path").build();
    volumes1.add(volumeConfig1);
    // container name with alias
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().ports(ports).from("fabric8/maven:latest").cleanup("try").tags(tags).compression("gzip").build();
    ImageConfiguration imageConfiguration = new ImageConfiguration.Builder().name("test").alias("test-app").buildConfig(buildImageConfiguration).registry("docker.io").build();
    images.add(imageConfiguration);
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Before(org.junit.Before)

Example 42 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.

the class ContainerHandler method getContainers.

List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images) {
    List<Container> ret = new ArrayList<>();
    for (ImageConfiguration imageConfig : images) {
        if (imageConfig.getBuildConfiguration() != null) {
            Probe livenessProbe = probeHandler.getProbe(config.getLiveness());
            Probe readinessProbe = probeHandler.getProbe(config.getReadiness());
            Container container = new ContainerBuilder().withName(KubernetesResourceUtil.extractContainerName(project, imageConfig)).withImage(getImageName(imageConfig)).withImagePullPolicy(getImagePullPolicy(config)).withEnv(envVarHandler.getEnvironmentVariables(config.getEnv())).withSecurityContext(createSecurityContext(config)).withPorts(getContainerPorts(imageConfig)).withVolumeMounts(getVolumeMounts(config)).withLivenessProbe(livenessProbe).withReadinessProbe(readinessProbe).build();
            ret.add(container);
        }
    }
    return ret;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) Probe(io.fabric8.kubernetes.api.model.Probe)

Example 43 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration 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 44 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration 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 45 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration 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

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)50 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)38 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)24 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 Test (org.junit.Test)13 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)10 File (java.io.File)9 IOException (java.io.IOException)9 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)8 ArrayList (java.util.ArrayList)8 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)7 Before (org.junit.Before)7 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)6 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)6 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)5 Expectations (mockit.Expectations)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 ExecException (io.fabric8.maven.docker.access.ExecException)4 WatchImageConfiguration (io.fabric8.maven.docker.config.WatchImageConfiguration)4