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");
}
}
}
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());
}
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");
}
}
}
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;
}
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));
}
Aggregations