Search in sources :

Example 21 with ImageConfiguration

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

the class ContainerTrackerTest method registerAtTracker.

private List<ContainerTracker.ContainerShutdownDescriptor> registerAtTracker(String[][] data) {
    List<ContainerTracker.ContainerShutdownDescriptor> descriptors = new ArrayList<>();
    for (String[] d : data) {
        ImageConfiguration imageConfig = getImageConfiguration(d[1], d[2], parseInt(d[3]), parseInt(d[4]), d[5], Boolean.parseBoolean(d[7]));
        tracker.registerContainer(d[0], imageConfig, getPomLabel(d[6]));
        descriptors.add(new ContainerTracker.ContainerShutdownDescriptor(imageConfig, d[0]));
    }
    return descriptors;
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration)

Example 22 with ImageConfiguration

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

the class BuildMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
    if (skipBuild) {
        return;
    }
    List<ImageConfiguration> resolvedImages = getResolvedImages();
    if (resolvedImages.isEmpty()) {
        // No Configuration found, so build one up dynamically.
        if (imageName == null) {
            /*
                 * Image name defaults to:
                 *     `${project.groupId}/${project.artifactId}:${project.version}`
                 */
            imageName = project.getGroupId() + "/" + project.getArtifactId() + ":" + project.getVersion();
        }
        ImageConfiguration aDefaultImageConfig = ImageConfiguration.getDefaultImageConfiguration(imageName, project.getBasedir().getAbsolutePath());
        processImageConfig(hub, aDefaultImageConfig);
        return;
    } else {
        // Iterate over all the ImageConfigurations and process one by one
        for (ImageConfiguration imageConfig : resolvedImages) {
            processImageConfig(hub, imageConfig);
        }
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration)

Example 23 with ImageConfiguration

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

the class StopMojo method getNetworksToRemove.

private Set<Network> getNetworksToRemove(QueryService queryService, PomLabel pomLabel) throws DockerAccessException {
    if (!autoCreateCustomNetworks) {
        return Collections.emptySet();
    }
    Set<Network> customNetworks = new HashSet<>();
    Set<Network> networks = queryService.getNetworks();
    for (ImageConfiguration image : getResolvedImages()) {
        final NetworkConfig config = image.getRunConfiguration().getNetworkingConfig();
        if (config.isCustomNetwork()) {
            Network network = getNetworkByName(networks, config.getCustomNetwork());
            if (network != null) {
                customNetworks.add(network);
                for (Container container : getContainersToStop(queryService, image)) {
                    if (!shouldStopContainer(container, pomLabel, image)) {
                        // it's sill in use don't collect it
                        customNetworks.remove(network);
                    }
                }
            }
        }
    }
    return customNetworks;
}
Also used : Container(io.fabric8.maven.docker.model.Container) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) Network(io.fabric8.maven.docker.model.Network) NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) HashSet(java.util.HashSet)

Example 24 with ImageConfiguration

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

the class PropertyConfigHandlerTest method testNoCleanup.

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

Example 25 with ImageConfiguration

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

the class PropertyConfigHandlerTest method testRunCommandsFromConfigAndProperties.

@Test
public void testRunCommandsFromConfigAndProperties() {
    imageConfiguration = new ImageConfiguration.Builder().externalConfig(new HashMap<String, String>()).buildConfig(new BuildImageConfiguration.Builder().runCmds(Arrays.asList("some", "configured", "value")).build()).build();
    makeExternalConfigUse(PropertyMode.Fallback);
    List<ImageConfiguration> configs = resolveImage(imageConfiguration, props("docker.from", "base", "docker.name", "demo", "docker.run.1", "this", "docker.run.2", "is", "docker.run.3", "ignored"));
    assertEquals(1, configs.size());
    BuildImageConfiguration buildConfig = configs.get(0).getBuildConfiguration();
    String[] runCommands = new ArrayList<>(buildConfig.getRunCmds()).toArray(new String[buildConfig.getRunCmds().size()]);
    assertArrayEquals(new String[] { "some", "configured", "value" }, runCommands);
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

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