Search in sources :

Example 11 with VolumeConfig

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

the class RunService method createContainerConfig.

// visible for testing
ContainerCreateConfig createContainerConfig(String imageName, RunImageConfiguration runConfig, PortMapping mappedPorts, GavLabel gavLabel, Properties mavenProps, File baseDir) throws DockerAccessException {
    try {
        ContainerCreateConfig config = new ContainerCreateConfig(imageName).hostname(runConfig.getHostname()).domainname(runConfig.getDomainname()).user(runConfig.getUser()).workingDir(runConfig.getWorkingDir()).entrypoint(runConfig.getEntrypoint()).exposedPorts(mappedPorts.getContainerPorts()).environment(runConfig.getEnvPropertyFile(), runConfig.getEnv(), mavenProps).labels(mergeLabels(runConfig.getLabels(), gavLabel)).command(runConfig.getCmd()).hostConfig(createContainerHostConfig(runConfig, mappedPorts, baseDir));
        RunVolumeConfiguration volumeConfig = runConfig.getVolumeConfiguration();
        if (volumeConfig != null) {
            resolveRelativeVolumeBindings(baseDir, volumeConfig);
            config.binds(volumeConfig.getBind());
        }
        NetworkConfig networkConfig = runConfig.getNetworkingConfig();
        if (networkConfig.isCustomNetwork() && networkConfig.hasAliases()) {
            ContainerNetworkingConfig networkingConfig = new ContainerNetworkingConfig().aliases(networkConfig);
            config.networkingConfig(networkingConfig);
        }
        return config;
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(String.format("Failed to create contained configuration for [%s]", imageName), e);
    }
}
Also used : RunVolumeConfiguration(io.fabric8.maven.docker.config.RunVolumeConfiguration) NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) ContainerNetworkingConfig(io.fabric8.maven.docker.access.ContainerNetworkingConfig)

Example 12 with VolumeConfig

use of io.fabric8.maven.core.config.VolumeConfig in project fabric8-maven-plugin by fabric8io.

the class PodTemplateHandlerTest method podWithoutEmptyTypeTemplateHandlerTest.

@Test
public void podWithoutEmptyTypeTemplateHandlerTest() {
    ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
    PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
    // empty type
    VolumeConfig volumeConfig1 = new VolumeConfig.Builder().name("test").mounts(mounts).build();
    volumes1.clear();
    volumes1.add(volumeConfig1);
    ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").controllerName("testing").withServiceAccount("test-account").withReplicas(5).volumes(volumes1).build();
    PodTemplateSpec podTemplateSpec = podTemplateHandler.getPodTemplate(config, images);
    // Assertion
    assertEquals("test-account", podTemplateSpec.getSpec().getServiceAccountName());
    assertTrue(podTemplateSpec.getSpec().getVolumes().isEmpty());
    assertNotNull(podTemplateSpec.getSpec().getContainers());
}
Also used : PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig) Test(org.junit.Test)

Example 13 with VolumeConfig

use of io.fabric8.maven.core.config.VolumeConfig in project fabric8-maven-plugin by fabric8io.

the class ContainerHandlerTest method getVolumeMountWithNameAndMountTest.

@Test
public void getVolumeMountWithNameAndMountTest() {
    ContainerHandler handler = new ContainerHandler(project, envVarHandler, probeHandler);
    List<String> mounts = new ArrayList<>();
    mounts.add("/path/etc");
    images.clear();
    images.add(imageConfiguration1);
    // volume config with name and single mount
    VolumeConfig volumeConfig3 = new VolumeConfig.Builder().name("third").mounts(mounts).build();
    volumes1.clear();
    volumes1.add(volumeConfig3);
    ResourceConfig config3 = new ResourceConfig.Builder().volumes(volumes1).build();
    containers = handler.getContainers(config3, images);
    assertEquals(1, containers.get(0).getVolumeMounts().size());
    assertEquals("third", containers.get(0).getVolumeMounts().get(0).getName());
    assertEquals("/path/etc", containers.get(0).getVolumeMounts().get(0).getMountPath());
}
Also used : ArrayList(java.util.ArrayList) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig) Test(org.junit.Test)

Example 14 with VolumeConfig

use of io.fabric8.maven.core.config.VolumeConfig in project fabric8-maven-plugin by fabric8io.

the class ContainerHandlerTest method getVolumeMountWithoutNameTest.

@Test
public void getVolumeMountWithoutNameTest() {
    ContainerHandler handler = new ContainerHandler(project, envVarHandler, probeHandler);
    images.clear();
    images.add(imageConfiguration1);
    List<String> mounts = new ArrayList<>();
    mounts.add("/path/etc");
    // volume config without name but with mount
    VolumeConfig volumeConfig2 = new VolumeConfig.Builder().mounts(mounts).build();
    volumes1.clear();
    volumes1.add(volumeConfig2);
    ResourceConfig config2 = new ResourceConfig.Builder().volumes(volumes1).build();
    containers = handler.getContainers(config2, images);
    assertEquals(1, containers.get(0).getVolumeMounts().size());
    assertEquals(null, containers.get(0).getVolumeMounts().get(0).getName());
    assertEquals("/path/etc", containers.get(0).getVolumeMounts().get(0).getMountPath());
}
Also used : ArrayList(java.util.ArrayList) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig) Test(org.junit.Test)

Example 15 with VolumeConfig

use of io.fabric8.maven.core.config.VolumeConfig in project fabric8-maven-plugin by fabric8io.

the class DeploymentHandlerTest method before.

@Before
public void before() {
    // volume config with name and multiple mount
    mounts.add("/path/system");
    mounts.add("/path/sys");
    ports.add("8080");
    ports.add("9090");
    tags.add("latest");
    tags.add("test");
    VolumeConfig volumeConfig1 = new VolumeConfig.Builder().name("test").mounts(mounts).type("hostPath").path("/test/path").build();
    volumes1.add(volumeConfig1);
    // container name with alias
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().ports(ports).from("fabric8/maven:latest").cleanup("try").tags(tags).compression("gzip").build();
    ImageConfiguration imageConfiguration = new ImageConfiguration.Builder().name("test").alias("test-app").buildConfig(buildImageConfiguration).registry("docker.io").build();
    images.add(imageConfiguration);
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Before(org.junit.Before)

Aggregations

VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)15 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)7 Test (org.junit.Test)7 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)6 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)6 ArrayList (java.util.ArrayList)6 Before (org.junit.Before)6 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)3 RunVolumeConfiguration (io.fabric8.maven.docker.config.RunVolumeConfiguration)2 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)1 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)1 VolumeType (io.fabric8.maven.core.config.VolumeType)1 ContainerCreateConfig (io.fabric8.maven.docker.access.ContainerCreateConfig)1 ContainerNetworkingConfig (io.fabric8.maven.docker.access.ContainerNetworkingConfig)1 NetworkConfig (io.fabric8.maven.docker.config.NetworkConfig)1 VolumeConfiguration (io.fabric8.maven.docker.config.VolumeConfiguration)1 HashMap (java.util.HashMap)1