use of org.eclipse.che.plugin.docker.client.json.network.EndpointConfig in project che by eclipse.
the class MachineProviderImpl method createContainer.
private String createContainer(String workspaceId, String machineName, boolean isDev, String image, String networkName, CheServiceImpl service) throws IOException {
long machineMemorySwap = memorySwapMultiplier == -1 ? -1 : (long) (service.getMemLimit() * memorySwapMultiplier);
addSystemWideContainerSettings(workspaceId, isDev, service);
EndpointConfig endpointConfig = new EndpointConfig().withAliases(machineName).withLinks(toArrayIfNotNull(service.getLinks()));
NetworkingConfig networkingConfig = new NetworkingConfig().withEndpointsConfig(singletonMap(networkName, endpointConfig));
HostConfig hostConfig = new HostConfig();
hostConfig.withMemorySwap(machineMemorySwap).withMemory(service.getMemLimit()).withNetworkMode(networkName).withLinks(toArrayIfNotNull(service.getLinks())).withPortBindings(service.getPorts().stream().collect(toMap(Function.identity(), value -> new PortBinding[0]))).withVolumesFrom(toArrayIfNotNull(service.getVolumesFrom()));
ContainerConfig config = new ContainerConfig();
config.withImage(image).withExposedPorts(service.getExpose().stream().distinct().collect(toMap(Function.identity(), value -> emptyMap()))).withHostConfig(hostConfig).withCmd(toArrayIfNotNull(service.getCommand())).withEntrypoint(toArrayIfNotNull(service.getEntrypoint())).withLabels(service.getLabels()).withNetworkingConfig(networkingConfig).withEnv(service.getEnvironment().entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).toArray(String[]::new));
List<String> bindMountVolumes = new ArrayList<>();
Map<String, Volume> nonBindMountVolumes = new HashMap<>();
for (String volume : service.getVolumes()) {
// If volume contains colon then it is bind volume, otherwise - non bind-mount volume.
if (volume.contains(":")) {
bindMountVolumes.add(volume);
} else {
nonBindMountVolumes.put(volume, new Volume());
}
}
hostConfig.setBinds(bindMountVolumes.toArray(new String[bindMountVolumes.size()]));
config.setVolumes(nonBindMountVolumes);
addStaticDockerConfiguration(config);
return docker.createContainer(CreateContainerParams.create(config).withContainerName(service.getContainerName())).getId();
}
Aggregations