Search in sources :

Example 1 with FromSelector

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

the class JavaRunGeneratorTest method fromSelector.

@Test
public void fromSelector() throws IOException {
    Object[] data = { "3.1.123", PlatformMode.kubernetes, null, "java.upstream.docker", "3.1.redhat-101", PlatformMode.kubernetes, null, "java.redhat.docker", "3.1.123", PlatformMode.openshift, OpenShiftBuildStrategy.docker, "java.upstream.docker", "3.1.redhat-101", PlatformMode.openshift, OpenShiftBuildStrategy.docker, "java.redhat.docker", "3.1.123", PlatformMode.openshift, OpenShiftBuildStrategy.s2i, "java.upstream.s2i", "3.1.redhat-101", PlatformMode.openshift, OpenShiftBuildStrategy.s2i, "java.redhat.s2i" };
    Properties imageProps = getDefaultImageProps();
    for (int i = 0; i < data.length; i += 4) {
        prepareExpectation((String) data[i], (PlatformMode) data[i + 1], (OpenShiftBuildStrategy) data[i + 2]);
        final GeneratorContext context = ctx;
        FromSelector selector = new FromSelector.Default(context, "java");
        String from = selector.getFrom();
        assertEquals(imageProps.getProperty((String) data[i + 3]), from);
    }
}
Also used : GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) FromSelector(io.fabric8.maven.generator.api.FromSelector) Test(org.junit.Test)

Example 2 with FromSelector

use of io.fabric8.maven.generator.api.FromSelector 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

ImageName (io.fabric8.maven.docker.util.ImageName)1 FromSelector (io.fabric8.maven.generator.api.FromSelector)1 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1