use of org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl 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.CheServiceBuildContextImpl 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);
}
use of org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnEnvironmentStart.
@Test
public void shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnEnvironmentStart() throws Exception {
// given
EnvironmentImpl env = createEnv();
String machineName = "machineWithDockerfileFromApi";
String dockerfileContent = "this is dockerfile content";
when(recipeDownloader.getRecipe(anyString())).thenReturn(dockerfileContent);
//prepare CheServicesEnvironmentImpl which should return compose parser
CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
cheServicesEnvironment.getServices().get(machineName).withBuild(new CheServiceBuildContextImpl().withContext(API_ENDPOINT + "/recipe/12345"));
// when
startEnv(env, cheServicesEnvironment);
// then
ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
CheServiceImpl actualService = captor.getValue();
assertNull(actualService.getBuild().getContext());
assertNull(actualService.getBuild().getDockerfilePath());
assertEquals(actualService.getBuild().getDockerfileContent(), dockerfileContent);
}
use of org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl in project che by eclipse.
the class CheEnvironmentValidatorTest method invalidServicesEnvironmentProvider.
@DataProvider
public static Object[][] invalidServicesEnvironmentProvider() {
// Format of result array:
// [ [InvalidCheServicesEnvironmentObject, ExceptionMessage], ... ]
CheServicesEnvironmentImpl env;
Map.Entry<String, CheServiceImpl> serviceEntry;
CheServiceImpl service;
List<List<Object>> data = new ArrayList<>();
env = createServicesEnv();
env.setServices(null);
data.add(asList(env, "Environment 'env' should contain at least 1 machine"));
env = createServicesEnv();
env.setServices(emptyMap());
data.add(asList(env, "Environment 'env' should contain at least 1 machine"));
env = createServicesEnv();
serviceEntry = getAnyService(env);
env.getServices().put("invalid service name", serviceEntry.getValue());
data.add(asList(env, "Name of machine 'invalid service name' in environment 'env' is invalid"));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setImage(null);
service.setBuild(null);
data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setImage("");
service.setBuild(null);
data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setImage(null);
service.setBuild(new CheServiceBuildContextImpl());
data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setImage("");
service.setBuild(new CheServiceBuildContextImpl());
data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setPorts(new ArrayList<>(singletonList("8080:8080")));
data.add(asList(env, format("Ports binding is forbidden but found in machine '%s' of environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setVolumes(new ArrayList<>(singletonList("volume")));
data.add(asList(env, format("Volumes binding is forbidden but found in machine '%s' of environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setNetworks(new ArrayList<>(singletonList("network1")));
data.add(asList(env, format("Networks configuration is forbidden but found in machine '%s' of environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setImage(null);
service.setBuild(new CheServiceBuildContextImpl(null, "dockerfile", null, null));
data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setImage("");
service.setBuild(new CheServiceBuildContextImpl("", "dockerfile", null, null));
data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setImage("");
service.setBuild(new CheServiceBuildContextImpl(null, null, null, null));
data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
env = createServicesEnv();
serviceEntry = getAnyService(env);
service = serviceEntry.getValue();
service.setImage("");
service.setBuild(new CheServiceBuildContextImpl("some url", null, "some content", new HashMap<String, String>() {
{
put("argkey", "argvalue");
}
}));
data.add(asList(env, format("Machine '%s' in environment 'env' contains mutually exclusive dockerfile content and build context.", serviceEntry.getKey())));
return data.stream().map(list -> list.toArray(new Object[list.size()])).toArray(value -> new Object[data.size()][]);
}
use of org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl in project che by eclipse.
the class DockerfileEnvironmentParserTest method shouldBeAbleToParseDockerfileEnvironmentFromContent.
@Test
public void shouldBeAbleToParseDockerfileEnvironmentFromContent() throws ServerException {
Environment environment = createDockerfileEnvConfig(DEFAULT_DOCKERFILE, null, DEFAULT_MACHINE_NAME);
CheServicesEnvironmentImpl expected = new CheServicesEnvironmentImpl();
expected.getServices().put(DEFAULT_MACHINE_NAME, new CheServiceImpl().withBuild(new CheServiceBuildContextImpl().withDockerfileContent(DEFAULT_DOCKERFILE)));
// when
CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
// then
assertEquals(cheServicesEnvironment, expected);
}
Aggregations