use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class MachineProviderImplTest method shouldAddEnvVarsFromMachineConfigToContainerOnNonDevInstanceCreationFromRecipe.
@Test
public void shouldAddEnvVarsFromMachineConfigToContainerOnNonDevInstanceCreationFromRecipe() throws Exception {
// given
Map<String, String> envVarsFromConfig = new HashMap<>();
envVarsFromConfig.put("ENV_VAR1", "123");
envVarsFromConfig.put("ENV_VAR2", "234");
final boolean isDev = false;
CheServiceImpl service = createService();
service.setEnvironment(envVarsFromConfig);
// when
createInstanceFromRecipe(service, isDev);
// then
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
assertTrue(asList(argumentCaptor.getValue().getContainerConfig().getEnv()).containsAll(envVarsFromConfig.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList())));
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class DockerImageEnvironmentParser method parse.
@Override
public CheServicesEnvironmentImpl parse(Environment environment) throws IllegalArgumentException, ServerException {
EnvironmentRecipe recipe = environment.getRecipe();
if (!"dockerimage".equals(recipe.getType())) {
throw new IllegalArgumentException(format("Docker image environment parser doesn't support recipe type '%s'", recipe.getType()));
}
CheServicesEnvironmentImpl cheServiceEnv = new CheServicesEnvironmentImpl();
CheServiceImpl service = new CheServiceImpl();
cheServiceEnv.getServices().put(getMachineName(environment), service);
service.setImage(recipe.getLocation());
return cheServiceEnv;
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class DockerfileEnvironmentParser method parse.
@Override
public CheServicesEnvironmentImpl parse(Environment environment) throws IllegalArgumentException, ServerException {
EnvironmentRecipe recipe = environment.getRecipe();
if (!"dockerfile".equals(recipe.getType())) {
throw new IllegalArgumentException(format("Dockerfile environment parser doesn't support recipe type '%s'", recipe.getType()));
}
if (!"text/x-dockerfile".equals(recipe.getContentType())) {
throw new IllegalArgumentException(format("Content type '%s' of recipe of environment is unsupported." + " Supported values are: text/x-dockerfile", recipe.getContentType()));
}
CheServicesEnvironmentImpl cheServiceEnv = new CheServicesEnvironmentImpl();
CheServiceImpl service = new CheServiceImpl();
cheServiceEnv.getServices().put(getMachineName(environment), service);
if (recipe.getLocation() != null) {
service.setBuild(new CheServiceBuildContextImpl().withContext(recipe.getLocation()));
} else {
service.setBuild(new CheServiceBuildContextImpl().withDockerfileContent(recipe.getContent()));
}
return cheServiceEnv;
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class ComposeEnvironmentParserTest method createTestEnv.
private CheServicesEnvironmentImpl createTestEnv() {
CheServicesEnvironmentImpl cheServicesEnvironment = new CheServicesEnvironmentImpl();
CheServiceImpl cheService1 = new CheServiceImpl();
String buildContext = "http://host.com:port/location/of/dockerfile/or/git/repo/";
cheService1.setBuild(new CheServiceBuildContextImpl().withContext(buildContext).withDockerfilePath("dockerfile/Dockerfile_alternate").withArgs(emptyMap()));
cheService1.setCommand(asList("tail", "-f", "/dev/null"));
cheService1.setContainerName("some_name");
cheService1.setDependsOn(asList("machine2", "machine3"));
cheService1.setEntrypoint(asList("/bin/bash", "-c"));
cheService1.setEnvironment(ImmutableMap.of("env1", "123", "env2", "345"));
cheService1.setExpose(asList("3000", "8080"));
cheService1.setImage("codenvy/ubuntu_jdk8");
cheService1.setLabels(ImmutableMap.of("com.example.department", "Finance", "com.example.description", "Accounting webapp", "com.example.label-with-empty-value", ""));
cheService1.setLinks(asList("machine1", "machine2:db"));
cheService1.setMemLimit(2147483648L);
cheService1.setNetworks(asList("some-network", "other-network"));
cheService1.setPorts(asList("3000", "3000-3005"));
cheService1.setVolumes(asList("/opt/data:/var/lib/mysql", "~/configs:/etc/configs/:ro"));
cheService1.setVolumesFrom(asList("machine2:ro", "machine3"));
CheServiceImpl cheService2 = new CheServiceImpl();
cheService2.setImage("codenvy/ubuntu_jdk8");
CheServiceImpl cheService3 = new CheServiceImpl();
cheService3.setImage("codenvy/ubuntu_jdk8");
cheServicesEnvironment.setServices(ImmutableMap.of("machine1", cheService1, "machine2", cheService2, "machine3", cheService3));
return cheServicesEnvironment;
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class ComposeEnvironmentParser method asCheEnvironment.
private CheServicesEnvironmentImpl asCheEnvironment(ComposeEnvironment composeEnvironment) {
Map<String, CheServiceImpl> services = Maps.newHashMapWithExpectedSize(composeEnvironment.getServices().size());
for (Map.Entry<String, ComposeServiceImpl> composeServiceEntry : composeEnvironment.getServices().entrySet()) {
ComposeServiceImpl service = composeServiceEntry.getValue();
CheServiceImpl cheService = new CheServiceImpl().withCommand(service.getCommand()).withContainerName(service.getContainerName()).withDependsOn(service.getDependsOn()).withEntrypoint(service.getEntrypoint()).withEnvironment(service.getEnvironment()).withExpose(service.getExpose()).withImage(service.getImage()).withLabels(service.getLabels()).withLinks(service.getLinks()).withMemLimit(service.getMemLimit()).withNetworks(service.getNetworks()).withPorts(service.getPorts()).withVolumes(service.getVolumes()).withVolumesFrom(service.getVolumesFrom());
if (service.getBuild() != null) {
cheService.setBuild(new CheServiceBuildContextImpl().withContext(service.getBuild().getContext()).withDockerfilePath(service.getBuild().getDockerfile()).withArgs(service.getBuild().getArgs()));
}
services.put(composeServiceEntry.getKey(), cheService);
}
return new CheServicesEnvironmentImpl(services);
}
Aggregations