Search in sources :

Example 86 with ImageConfiguration

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

the class OpenshiftBuildServiceTest method checkTarPackage.

@Test
public void checkTarPackage() throws Exception {
    int nTries = 0;
    boolean bTestComplete = false;
    do {
        try {
            nTries++;
            BuildService.BuildServiceConfig config = defaultConfig.build();
            WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, true, true);
            OpenShiftMockServer mockServer = collector.getMockServer();
            OpenShiftClient client = mockServer.createOpenShiftClient();
            final OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
            ImageConfiguration imageWithEnv = new ImageConfiguration.Builder(image).buildConfig(new BuildImageConfiguration.Builder(image.getBuildConfiguration()).env(Collections.singletonMap("FOO", "BAR")).build()).build();
            service.createBuildArchive(imageWithEnv);
            final List<ArchiverCustomizer> customizer = new LinkedList<>();
            new Verifications() {

                {
                    archiveService.createDockerBuildArchive(withInstanceOf(ImageConfiguration.class), withInstanceOf(MojoParameters.class), withCapture(customizer));
                    assertTrue(customizer.size() == 1);
                }
            };
            customizer.get(0).customize(tarArchiver);
            final List<File> file = new LinkedList<>();
            new Verifications() {

                {
                    String path;
                    tarArchiver.addFile(withCapture(file), path = withCapture());
                    assertEquals(".s2i/environment", path);
                }
            };
            assertEquals(1, file.size());
            List<String> lines;
            try (FileReader reader = new FileReader(file.get(0))) {
                lines = IOUtils.readLines(reader);
            }
            assertTrue(lines.contains("FOO=BAR"));
            bTestComplete = true;
        } catch (Fabric8ServiceException exception) {
            Throwable rootCause = getRootCause(exception);
            logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
            // Let's wait for a while, and then retry again
            if (rootCause != null && rootCause instanceof IOException) {
                continue;
            }
        }
    } while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
Also used : BuildService(io.fabric8.maven.core.service.BuildService) ArchiverCustomizer(io.fabric8.maven.docker.assembly.ArchiverCustomizer) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) IOException(java.io.IOException) Verifications(mockit.Verifications) LinkedList(java.util.LinkedList) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Example 87 with ImageConfiguration

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

the class ContainerHandler method getContainerPorts.

private List<ContainerPort> getContainerPorts(ImageConfiguration imageConfig) {
    BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
    List<String> ports = buildConfig.getPorts();
    if (!ports.isEmpty()) {
        List<ContainerPort> ret = new ArrayList<>();
        PortMapping portMapping = new PortMapping(ports, project.getProperties());
        JSONArray portSpecs = portMapping.toJson();
        for (int i = 0; i < portSpecs.length(); i++) {
            JSONObject portSpec = portSpecs.getJSONObject(i);
            ret.add(extractContainerPort(portSpec));
        }
        return ret;
    } else {
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) PortMapping(io.fabric8.maven.docker.access.PortMapping) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 88 with ImageConfiguration

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

the class PrometheusEnricherTest method testDetectPrometheusPort.

@Test
public void testDetectPrometheusPort() throws Exception {
    final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(PrometheusEnricher.ENRICHER_NAME, new TreeMap()));
    final BuildImageConfiguration imageConfig = new BuildImageConfiguration.Builder().ports(Arrays.asList(PrometheusEnricher.PROMETHEUS_PORT)).build();
    // Setup mock behaviour
    new Expectations() {

        {
            context.getConfig();
            result = config;
            imageConfiguration.getBuildConfiguration();
            result = imageConfig;
            context.getImages();
            result = Arrays.asList(imageConfiguration);
        }
    };
    PrometheusEnricher enricher = new PrometheusEnricher(context);
    Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
    assertEquals(2, annotations.size());
    assertEquals("9779", annotations.get(Annotations.Management.PROMETHEUS_PORT));
    assertEquals("true", annotations.get(Annotations.Management.PROMETHEUS_SCRAPE));
}
Also used : Expectations(mockit.Expectations) TreeMap(java.util.TreeMap) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 89 with ImageConfiguration

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

the class DefaultServiceEnricherTest method setupExpectations.

private void setupExpectations(final boolean withPorts, String... configParams) {
    // Setup mock behaviour
    final TreeMap config = new TreeMap();
    for (int i = 0; i < configParams.length; i += 2) {
        config.put(configParams[i], configParams[i + 1]);
    }
    new Expectations() {

        {
            context.getConfig();
            result = new ProcessorConfig(null, null, Collections.singletonMap("fmp-service", config));
            imageConfiguration.getBuildConfiguration();
            result = getBuildConfig(withPorts);
            context.getImages();
            result = Arrays.asList(imageConfiguration);
        }
    };
}
Also used : Expectations(mockit.Expectations) TreeMap(java.util.TreeMap) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 90 with ImageConfiguration

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

the class ImageEnricher method mergeImageConfigurationWithContainerSpec.

// Add missing information to the given containers as found
// configured
private void mergeImageConfigurationWithContainerSpec(List<Container> containers) {
    List<ImageConfiguration> images = getImages();
    int idx = 0;
    for (ImageConfiguration imageConfiguration : images) {
        Container container = getContainer(idx, containers);
        mergeImagePullPolicy(imageConfiguration, container);
        mergeImage(imageConfiguration, container);
        mergeContainerName(imageConfiguration, container);
        mergeEnvVariables(container);
        idx++;
    }
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration)

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