public ContainerBuilder extend(Path location, String service) { Path extendLocation = this.dockerComposeRootLocation.resolve(location); DockerCompositions dockerCompositions = DockerComposeConverter.create(extendLocation).convert(); CubeContainer cubeContainer = dockerCompositions.getContainers().get(service); if (cubeContainer == null) { throw new IllegalArgumentException(String.format("Service name %s is not present at %s", service, extendLocation.toAbsolutePath())); } else { ContainerBuilder containerBuilder = new ContainerBuilder(dockerComposeRootLocation, configuration); configuration.merge(cubeContainer); } return this; }
public ContainerBuilder extend(Path location, String service) { Path extendLocation = this.dockerComposeRootLocation.resolve(location); DockerCompositions dockerCompositions = DockerComposeConverter.create(extendLocation).convert(); CubeContainer cubeContainer = dockerCompositions.getContainers().get(service); if (cubeContainer == null) { throw new IllegalArgumentException(String.format("Service name %s is not present at %s", service, extendLocation.toAbsolutePath())); } else { ContainerBuilder containerBuilder = new ContainerBuilder(dockerComposeRootLocation, configuration); configuration.merge(cubeContainer); } return this; }
private static DockerCompositions applyExtendsRules(DockerCompositions dockerCompositions) { for (Map.Entry<String, CubeContainer> containerEntry : dockerCompositions.getContainers().entrySet()) { CubeContainer container = containerEntry.getValue(); if (container.getExtends() != null) { String extendsContainer = container.getExtends(); if (dockerCompositions.get(extendsContainer) == null) { throw new IllegalArgumentException( containerEntry.getKey() + " extends a non existing container definition " + extendsContainer); } CubeContainer extendedContainer = dockerCompositions.get(extendsContainer); container.merge(extendedContainer); } } return dockerCompositions; }
private static DockerCompositions applyExtendsRules(DockerCompositions dockerCompositions) { for (Map.Entry<String, CubeContainer> containerEntry : dockerCompositions.getContainers().entrySet()) { CubeContainer container = containerEntry.getValue(); if (container.getExtends() != null) { String extendsContainer = container.getExtends(); if (dockerCompositions.get(extendsContainer) == null) { throw new IllegalArgumentException( containerEntry.getKey() + " extends a non existing container definition " + extendsContainer); } CubeContainer extendedContainer = dockerCompositions.get(extendsContainer); container.merge(extendedContainer); } } return dockerCompositions; }
public void merge(DockerCompositions otherContainers) { // merge networks for (Map.Entry<String, Network> thisNetwork : networks.entrySet()) { if (otherContainers.getNetwork(thisNetwork.getKey()) != null) { thisNetwork.getValue().merge(otherContainers.getNetwork(thisNetwork.getKey())); } } Map<String, Network> addAllNetworks = new HashMap<>(); for (Map.Entry<String, Network> otherNetwork : otherContainers.getNetworks().entrySet()) { if (getNetwork(otherNetwork.getKey()) == null) { addAllNetworks.put(otherNetwork.getKey(), otherNetwork.getValue()); } } networks.putAll(addAllNetworks); // merge containers for (Map.Entry<String, CubeContainer> thisContainer : containers.entrySet()) { if (otherContainers.get(thisContainer.getKey()) != null) { thisContainer.getValue().merge(otherContainers.get(thisContainer.getKey())); } } Map<String, CubeContainer> addAll = new HashMap<String, CubeContainer>(); for (Map.Entry<String, CubeContainer> otherContainer : otherContainers.getContainers().entrySet()) { if (get(otherContainer.getKey()) == null) { addAll.put(otherContainer.getKey(), otherContainer.getValue()); } } containers.putAll(addAll); }
public void merge(DockerCompositions otherContainers) { // merge networks for (Map.Entry<String, Network> thisNetwork : networks.entrySet()) { if (otherContainers.getNetwork(thisNetwork.getKey()) != null) { thisNetwork.getValue().merge(otherContainers.getNetwork(thisNetwork.getKey())); } } Map<String, Network> addAllNetworks = new HashMap<>(); for (Map.Entry<String, Network> otherNetwork : otherContainers.getNetworks().entrySet()) { if (getNetwork(otherNetwork.getKey()) == null) { addAllNetworks.put(otherNetwork.getKey(), otherNetwork.getValue()); } } networks.putAll(addAllNetworks); // merge containers for (Map.Entry<String, CubeContainer> thisContainer : containers.entrySet()) { if (otherContainers.get(thisContainer.getKey()) != null) { thisContainer.getValue().merge(otherContainers.get(thisContainer.getKey())); } } Map<String, CubeContainer> addAll = new HashMap<String, CubeContainer>(); for (Map.Entry<String, CubeContainer> otherContainer : otherContainers.getContainers().entrySet()) { if (get(otherContainer.getKey()) == null) { addAll.put(otherContainer.getKey(), otherContainer.getValue()); } } containers.putAll(addAll); }
public void register(@Observes DockerClientExecutor executor, CubeDockerConfiguration configuration, Injector injector, CubeRegistry registry) { //TODO, add key here generation here DockerCompositions containerConfigurations = configuration.getDockerContainersContent(); for (Map.Entry<String, CubeContainer> containerConfiguration : containerConfigurations.getContainers() .entrySet()) { registry.addCube( injector.inject( new DockerCube( containerConfiguration.getKey(), containerConfiguration.getValue(), executor))); } } }
public void register(@Observes DockerClientExecutor executor, CubeDockerConfiguration configuration, Injector injector, CubeRegistry registry) { //TODO, add key here generation here DockerCompositions containerConfigurations = configuration.getDockerContainersContent(); for (Map.Entry<String, CubeContainer> containerConfiguration : containerConfigurations.getContainers() .entrySet()) { registry.addCube( injector.inject( new DockerCube( containerConfiguration.getKey(), containerConfiguration.getValue(), executor))); } } }
final Map<String, CubeContainer> containers = dockerContainersContent.getContainers(); for (Map.Entry<String, CubeContainer> container : containers.entrySet()) {
final Map<String, CubeContainer> containers = dockerContainersContent.getContainers(); for (Map.Entry<String, CubeContainer> container : containers.entrySet()) {
final Set<Map.Entry<String, CubeContainer>> containers = dockerContainersContent.getContainers().entrySet();
final Set<Map.Entry<String, CubeContainer>> containers = dockerContainersContent.getContainers().entrySet();
@Test public void shouldTransformSimpleDockerComposeV2FormatNetworkByDefault() throws URISyntaxException { URI simpleDockerCompose = DockerComposeConverterTest.class.getResource("/myapp/simple-docker-compose-v2.yml").toURI(); DockerComposeConverter dockerComposeConverter = DockerComposeConverter.create(Paths.get(simpleDockerCompose)); DockerCompositions convert = dockerComposeConverter.convert(); CubeContainer webapp = convert.getContainers().get("webapp"); assertThat(webapp, is(notNullValue())); assertThat(webapp.getNetworkMode()).endsWith("_default"); Map<String, Network> networks = convert.getNetworks(); assertThat(networks).hasSize(1); assertThat(networks.keySet().iterator().next()).endsWith("_default"); }
@Test public void shouldTransformSimpleDockerComposeV2FormatMultipleNetworks() throws URISyntaxException { URI simpleDockerCompose = DockerComposeConverterTest.class.getResource("/myapp/docker-compose-multiple-networks.yml").toURI(); DockerComposeConverter dockerComposeConverter = DockerComposeConverter.create(Paths.get(simpleDockerCompose)); DockerCompositions convert = dockerComposeConverter.convert(); CubeContainer webapp = convert.getContainers().get("pingpong"); assertThat(webapp, is(notNullValue())); assertThat(webapp.getNetworkMode()).isEqualTo("front"); assertThat(webapp.getNetworks()).contains("front", "back"); Map<String, Network> networks = convert.getNetworks(); assertThat(networks).hasSize(2); assertThat(networks).containsOnlyKeys("front", "back"); }
final Set<Map.Entry<String, CubeContainer>> containers = dockerContainersContent.getContainers().entrySet();
private FileEntry createDockerCompositionSchema(CubeDockerConfiguration cubeDockerConfiguration, ReporterConfiguration reporterConfiguration) { final mxGraph graph = new mxGraph(); final Object parent = graph.getDefaultParent(); graph.setAutoSizeCells(true); graph.getModel().beginUpdate(); try { final DockerCompositions dockerContainersContent = cubeDockerConfiguration.getDockerContainersContent(); final Map<String, CubeContainer> containers = dockerContainersContent.getContainers(); final Map<String, Object> insertedVertex = new HashMap<>(); for (Map.Entry<String, CubeContainer> containerEntry : containers.entrySet()) { String containerId = containerEntry.getKey(); CubeContainer cubeContainer = containerEntry.getValue(); updateGraph(graph, parent, insertedVertex, containerId, cubeContainer); } } finally { graph.getModel().endUpdate(); } mxIGraphLayout layout = new mxHierarchicalLayout(graph, SwingConstants.WEST); layout.execute(graph.getDefaultParent()); return generateCompositionSchemaImage(graph, reporterConfiguration); }
try { DockerCompositions dockerCompositions = cubeDockerConfiguration.getDockerContainersContent(); final Map<String, CubeContainer> containers = dockerCompositions.getContainers(); final Map<String, Object> insertedVertex = new HashMap<>(); for (Map.Entry<String, CubeContainer> container: containers.entrySet()) {
@Test public void should_be_able_to_create_http_await_strategy() { String containerDefinition = "tomcat:\n" + " image: tutum/tomcat:7.0\n" + " exposedPorts: [8089/tcp]\n" + " await:\n" + " strategy: http\n" + " iterations: 10\n" + " sleepPollingTime: 200 s\n" + " url: http://localhost:8080/ping\n" + " responseCode: 201\n" + " match: 'Server startup'\n" + " headers: \n" + " X-Cube: Docker\n"; final DockerCompositions load = ConfigUtil.load(new ByteArrayInputStream(containerDefinition.getBytes())); final CubeContainer tomcat = load.getContainers().get("tomcat"); HttpAwaitStrategy awaitStrategy = new HttpAwaitStrategy(cube, dockerClientExecutor, tomcat.getAwait()); assertThat(awaitStrategy.getPollIterations(), is(10)); assertThat(awaitStrategy.getUrl(), is("http://localhost:8080/ping")); assertThat(awaitStrategy.getResponseCode(), is(201)); assertThat(awaitStrategy.getMatcher(), is("Server startup")); assertThat((String) awaitStrategy.getHeaders().get("X-Cube"), is("Docker")); }
@Test public void shouldTransformSimpleDockerComposeV2FormatWithNetworks() throws URISyntaxException, IOException { URI simpleDockerCompose = DockerComposeConverterTest.class.getResource("/simple-docker-compose-v2.yml").toURI(); DockerComposeConverter dockerComposeConverter = DockerComposeConverter.create(Paths.get(simpleDockerCompose)); DockerCompositions convert = dockerComposeConverter.convert(); CubeContainer webapp = convert.getContainers().get("webapp"); assertThat(webapp.getBuildImage(), is(notNullValue())); assertThat(webapp.getPortBindings(), is(notNullValue())); Collection<PortBinding> ports = webapp.getPortBindings(); assertThat(ports, containsInAnyOrder(PortBinding.valueOf("8000->8000"))); assertThat(webapp.getDevices(), is(notNullValue())); assertThat(webapp.getVolumes(), is(notNullValue())); Collection<String> webappVolumes = (Collection<String>) webapp.getVolumes(); assertThat(webappVolumes, containsInAnyOrder("/data")); CubeContainer webapp2 = convert.getContainers().get("webapp2"); assertThat(webapp2.getImage(), is(notNullValue())); assertThat(webapp2.getPortBindings(), is(notNullValue())); assertThat(webapp2.getLinks(), is(notNullValue())); Collection<Link> links = webapp2.getLinks(); assertThat(links, containsInAnyOrder(Link.valueOf("webapp:webapp"))); assertThat(webapp2.getEnv(), is(notNullValue())); Collection<String> env = webapp2.getEnv(); assertThat(env, containsInAnyOrder("RACK_ENV=development")); Map<String, Network> networks = convert.getNetworks(); Network network = networks.get("front-tier"); assertThat(network.getDriver(), is("bridge")); Network network2 = networks.get("back-tier"); assertThat(network2.getDriver(), is("bridge")); }
@Test public void shouldTransformSimpleDockerComposeV2FormatWithNetworksByDefaultDriver() throws URISyntaxException, IOException { URI simpleDockerCompose = DockerComposeConverterTest.class.getResource("/simple-docker-compose-networks-v2.yml").toURI(); DockerComposeConverter dockerComposeConverter = DockerComposeConverter.create(Paths.get(simpleDockerCompose)); DockerCompositions convert = dockerComposeConverter.convert(); CubeContainer webapp = convert.getContainers().get("webapp"); assertThat(webapp.getBuildImage(), is(notNullValue())); assertThat(webapp.getPortBindings(), is(notNullValue())); Collection<PortBinding> ports = webapp.getPortBindings(); assertThat(ports, containsInAnyOrder(PortBinding.valueOf("8000->8000"))); assertThat(webapp.getDevices(), is(notNullValue())); assertThat(webapp.getVolumes(), is(notNullValue())); Collection<String> webappVolumes = (Collection<String>) webapp.getVolumes(); assertThat(webappVolumes, containsInAnyOrder("/data")); CubeContainer webapp2 = convert.getContainers().get("webapp2"); assertThat(webapp2.getImage(), is(notNullValue())); assertThat(webapp2.getPortBindings(), is(notNullValue())); assertThat(webapp2.getLinks(), is(notNullValue())); Collection<Link> links = webapp2.getLinks(); assertThat(links, containsInAnyOrder(Link.valueOf("webapp:webapp"))); assertThat(webapp2.getEnv(), is(notNullValue())); Collection<String> env = webapp2.getEnv(); assertThat(env, containsInAnyOrder("RACK_ENV=development")); Map<String, Network> networks = convert.getNetworks(); Network network = networks.get("front-tier"); assertThat(network.getDriver(), is("bridge")); Network network2 = networks.get("back-tier"); assertThat(network2.getDriver(), is("bridge")); }