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);
}
}
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());
}
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());
}
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());
}
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);
}
Aggregations