Search in sources :

Example 26 with ImageConfiguration

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

the class PropertyConfigHandlerTest method testPortsFromConfigAndProperties.

@Test
public void testPortsFromConfigAndProperties() {
    imageConfiguration = new ImageConfiguration.Builder().externalConfig(new HashMap<String, String>()).buildConfig(new BuildImageConfiguration.Builder().ports(Arrays.asList("1234")).build()).runConfig(new RunImageConfiguration.Builder().ports(Arrays.asList("jolokia.port:1234")).build()).build();
    makeExternalConfigUse(PropertyMode.Override);
    List<ImageConfiguration> configs = resolveImage(imageConfiguration, props("docker.name", "demo", "docker.ports.1", "9090", "docker.ports.2", "0.0.0.0:80:80", "docker.from", "busybox"));
    assertEquals(1, configs.size());
    RunImageConfiguration runConfig = configs.get(0).getRunConfiguration();
    List<String> portsAsList = runConfig.getPorts();
    String[] ports = new ArrayList<>(portsAsList).toArray(new String[portsAsList.size()]);
    assertArrayEquals(new String[] { "9090", "0.0.0.0:80:80", "jolokia.port:1234" }, ports);
    BuildImageConfiguration buildConfig = configs.get(0).getBuildConfiguration();
    ports = new ArrayList<>(buildConfig.getPorts()).toArray(new String[buildConfig.getPorts().size()]);
    assertArrayEquals(new String[] { "9090", "80", "1234" }, ports);
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

Example 27 with ImageConfiguration

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

the class PropertyConfigHandlerTest method testNoOptimise.

@Test
public void testNoOptimise() throws Exception {
    String[] testData = new String[] { k(ConfigKey.NAME), "image", k(ConfigKey.OPTIMISE), "false", k(ConfigKey.FROM), "base" };
    ImageConfiguration config = resolveExternalImageConfig(testData);
    assertEquals(false, config.getBuildConfiguration().optimise());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

Example 28 with ImageConfiguration

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

the class DockerBuildServiceTest method testSuccessfulBuild.

@Test
public void testSuccessfulBuild() throws Exception {
    new Expectations() {

        {
            hub.getBuildService();
            result = buildService;
        }
    };
    final BuildService.BuildContext context = new BuildService.BuildContext.Builder().build();
    final io.fabric8.maven.core.service.BuildService.BuildServiceConfig config = new io.fabric8.maven.core.service.BuildService.BuildServiceConfig.Builder().dockerBuildContext(context).build();
    final String imageName = "image-name";
    final ImageConfiguration image = new ImageConfiguration.Builder().name(imageName).buildConfig(new BuildImageConfiguration.Builder().from("from").build()).build();
    DockerBuildService service = new DockerBuildService(hub, config);
    service.build(image);
    new FullVerificationsInOrder() {

        {
            buildService.buildImage(image, context);
            buildService.tagImage(imageName, image);
        }
    };
}
Also used : Expectations(mockit.Expectations) BuildService(io.fabric8.maven.docker.service.BuildService) FullVerificationsInOrder(mockit.FullVerificationsInOrder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Example 29 with ImageConfiguration

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

the class DefaultControllerEnricher method addMissingResources.

@Override
public void addMissingResources(KubernetesListBuilder builder) {
    final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()));
    final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getConfig(Config.pullPolicy)).withReplicas(Configs.asInt(getConfig(Config.replicaCount))).build();
    final List<ImageConfiguration> images = getImages();
    // Check if at least a replica set is added. If not add a default one
    if (!KubernetesResourceUtil.checkForKind(builder, POD_CONTROLLER_KINDS)) {
        // At least one image must be present, otherwise the resulting config will be invalid
        if (!Lists.isNullOrEmpty(images)) {
            String type = getConfig(Config.type);
            if ("deployment".equalsIgnoreCase(type)) {
                log.info("Adding a default Deployment");
                builder.addToDeploymentItems(deployHandler.getDeployment(config, images));
            } else if ("statefulSet".equalsIgnoreCase(type)) {
                log.info("Adding a default StatefulSet");
                builder.addToStatefulSetItems(statefulSetHandler.getStatefulSet(config, images));
            } else if ("daemonSet".equalsIgnoreCase(type)) {
                log.info("Adding a default DaemonSet");
                builder.addToDaemonSetItems(daemonSetHandler.getDaemonSet(config, images));
            } else if ("replicaSet".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicaSet");
                builder.addToReplicaSetItems(rsHandler.getReplicaSet(config, images));
            } else if ("replicationController".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicationController");
                builder.addToReplicationControllerItems(rcHandler.getReplicationController(config, images));
            } else if ("job".equalsIgnoreCase(type)) {
                log.info("Adding a default Job");
                builder.addToJobItems(jobHandler.getJob(config, images));
            }
        }
    } else if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
        final StatefulSetSpec spec = statefulSetHandler.getStatefulSet(config, images).getSpec();
        if (spec != null) {
            builder.accept(new TypedVisitor<StatefulSetBuilder>() {

                @Override
                public void visit(StatefulSetBuilder statefulSetBuilder) {
                    statefulSetBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                    mergeStatefulSetSpec(statefulSetBuilder, spec);
                }
            });
            if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                final PodSpec podSpec = spec.getTemplate().getSpec();
                builder.accept(new TypedVisitor<PodSpecBuilder>() {

                    @Override
                    public void visit(PodSpecBuilder builder) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    } else {
        final DeploymentSpec spec = deployHandler.getDeployment(config, images).getSpec();
        if (spec != null) {
            builder.accept(new TypedVisitor<DeploymentBuilder>() {

                @Override
                public void visit(DeploymentBuilder deploymentBuilder) {
                    deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                    mergeDeploymentSpec(deploymentBuilder, spec);
                }
            });
            if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                final PodSpec podSpec = spec.getTemplate().getSpec();
                builder.accept(new TypedVisitor<PodSpecBuilder>() {

                    @Override
                    public void visit(PodSpecBuilder builder) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    }
}
Also used : TypedVisitor(io.fabric8.kubernetes.api.builder.TypedVisitor) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) StatefulSetSpec(io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Example 30 with ImageConfiguration

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

the class DefaultControllerEnricherTest method setupExpectations.

protected void setupExpectations(final BuildImageConfiguration buildConfig, final TreeMap controllerConfig) {
    new Expectations() {

        {
            project.getArtifactId();
            result = "fmp-controller-test";
            project.getBuild().getOutputDirectory();
            result = Files.createTempDir().getAbsolutePath();
            context.getProject();
            result = project;
            context.getConfig();
            result = new ProcessorConfig(null, null, Collections.singletonMap("fmp-controller", controllerConfig));
            imageConfiguration.getBuildConfiguration();
            result = buildConfig;
            imageConfiguration.getName();
            result = "helloworld";
            context.getImages();
            result = Arrays.asList(imageConfiguration);
        }
    };
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

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