Search in sources :

Example 16 with Generator

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

the class BaseGeneratorTest method addFromIstagModeWithoutSelector.

@Test
public void addFromIstagModeWithoutSelector() {
    Properties props = new Properties();
    props.put("fabric8.generator.fromMode", "istag");
    for (String from : new String[] { null, "test_namespace/test_image:2.0" }) {
        setupContext(props, false, from, null);
        BuildImageConfiguration.Builder builder = new BuildImageConfiguration.Builder();
        BaseGenerator generator = createGenerator(null);
        generator.addFrom(builder);
        BuildImageConfiguration config = builder.build();
        assertEquals(from == null ? null : "test_image:2.0", config.getFrom());
        Map<String, String> fromExt = config.getFromExt();
        if (from == null) {
            assertNull(fromExt);
        } else {
            assertFromExt(fromExt, "test_image:2.0", "test_namespace");
        }
    }
}
Also used : Properties(java.util.Properties) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 17 with Generator

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

the class BaseGeneratorTest method addFromIstagWithNameWithoutTag.

@Test
public void addFromIstagWithNameWithoutTag() {
    Properties props = new Properties();
    setupContext(props, false, "test_namespace/test_image", "istag");
    BuildImageConfiguration.Builder builder = new BuildImageConfiguration.Builder();
    BaseGenerator generator = createGenerator(null);
    generator.addFrom(builder);
    BuildImageConfiguration config = builder.build();
    assertEquals("test_image:latest", config.getFrom());
}
Also used : Properties(java.util.Properties) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 18 with Generator

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

the class BaseGeneratorTest method addFromIstagModeWithSelector.

@Test
public void addFromIstagModeWithSelector() {
    Properties props = new Properties();
    props.put("fabric8.generator.fromMode", "istag");
    for (String from : new String[] { null, "test_namespace/test_image:2.0" }) {
        setupContext(props, false, from, null);
        BuildImageConfiguration.Builder builder = new BuildImageConfiguration.Builder();
        BaseGenerator generator = createGenerator(new TestFromSelector(ctx, false));
        generator.addFrom(builder);
        BuildImageConfiguration config = builder.build();
        assertEquals(from == null ? "selectorIstagFromUpstream" : "test_image:2.0", config.getFrom());
        Map<String, String> fromExt = config.getFromExt();
        if (from != null) {
            assertFromExt(fromExt, "test_image:2.0", "test_namespace");
        } else {
            assertFromExt(fromExt, "selectorIstagFromUpstream", "openshift");
        }
    }
}
Also used : Properties(java.util.Properties) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 19 with Generator

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

the class WebAppGenerator method customize.

@Override
public List<ImageConfiguration> customize(List<ImageConfiguration> configs, boolean prePackagePhase) {
    if (getContext().getMode() == PlatformMode.openshift && getContext().getStrategy() == OpenShiftBuildStrategy.s2i) {
        throw new IllegalArgumentException("S2I not yet supported for the webapp-generator. Use -Dfabric8.mode=kubernetes or " + "-Dfabric8.build.strategy=docker for OpenShift mode. Please refer to the reference manual at " + "https://maven.fabric8.io for details about build modes.");
    }
    // Late initialization to avoid unnecessary directory scanning
    AppServerHandler handler = getAppServerHandler(getContext());
    log.info("Using %s as base image for webapp", handler.getFrom());
    ImageConfiguration.Builder imageBuilder = new ImageConfiguration.Builder();
    BuildImageConfiguration.Builder buildBuilder = new BuildImageConfiguration.Builder().from(getFrom(handler)).ports(handler.exposedPorts()).cmd(getDockerRunCommand(handler)).env(getEnv(handler));
    if (!prePackagePhase) {
        buildBuilder.assembly(createAssembly(handler));
    }
    addLatestTagIfSnapshot(buildBuilder);
    imageBuilder.name(getImageName()).alias(getAlias()).buildConfig(buildBuilder.build());
    configs.add(imageBuilder.build());
    return configs;
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) CustomAppServerHandler(io.fabric8.maven.generator.webapp.handler.CustomAppServerHandler) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 20 with Generator

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

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromConfig.

/**
 * The main class is determined via config in a non-fat-jar deployment
 * @throws MojoExecutionException
 */
@Test
public void testMainClassDeterminationFromConfig() throws MojoExecutionException {
    new MockBuild();
    new MockProcessorConfig("the.main.ClassName");
    new MockMavenProject();
    final GeneratorContext generatorContext = new GeneratorContext.Builder().project(new MavenProject()).config(new ProcessorConfig()).strategy(OpenShiftBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    final List<ImageConfiguration> images = new ArrayList<ImageConfiguration>();
    List<ImageConfiguration> customized = generator.customize(images, false);
    assertEquals("1 images returned", (long) 1, (long) customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheImageName", imageConfig.getName());
    assertEquals("Main Class set as environment variable", "the.main.ClassName", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

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