Пример #1
0
func ComposeArch(name string, c *ComposeV2Yaml) {
	a := architecture.MakeArch(name, "compose yaml")
	nets := make(map[string][]string)
	for n, v := range c.Services {
		//fmt.Println("Compose: ", n, v.Image, v.Build, v.Links)
		co := v.Image
		if co == "" {
			co = v.Build
		}
		var links []string // change db:redis into db
		for _, l := range v.Links {
			links = append(links, strings.Split(l, ":")[0])
		}
		var networks []string
		for _, name := range v.Networks {
			nets[name] = append(nets[name], n) // map of which services refer to a network
			networks = append(networks, name)  // list of networks this service refers to
		}
		var volumes []string
		for _, nv := range v.Volumes {
			name := strings.Split(nv, ":")[0] // get root volume name
			volumes = append(volumes, name)   // list of volumes this service refers to
		}
		if n == "db" {
			architecture.AddContainer(a, n, "machine", "instance", co, "process", "staash", 1, 1, volumes)
		} else {
			if n == "redis" {
				architecture.AddContainer(a, n, "machine", "instance", co, "process", "store", 1, 1, links)
			} else {
				architecture.AddContainer(a, n, "machine", "instance", co, "process", "monolith", 1, 3, links)
			}
		}
		external := false
		for _, port := range v.Ports {
			if len(strings.Split(port, ":")) >= 2 {
				external = true
			}
		}
		if external {
			var extlink []string
			extlink = append(extlink, n)
			architecture.AddContainer(a, "www-"+n, "external", "", "", "", "denominator", 0, 0, extlink)
		}
	}
	for n, _ := range c.Networks {
		architecture.AddContainer(a, n, "network", "", "", "", "elb", 1, 0, nets[n])
	}
	for n, _ := range c.Volumes {
		architecture.AddContainer(a, n, "volume", "", "", "", "store", 1, 0, nil)
	}
	architecture.WriteFile(a, name)
}
Пример #2
0
func try(t string) {
	var c ComposeServices
	err := yaml.Unmarshal([]byte(t), &c)
	if err != nil {
		fmt.Println(err)
	}
	a := architecture.MakeArch("test", "compose yaml")
	for n, v := range c {
		fmt.Println("Compose: ", n, v.Image, v.Build, v.Links)
		c := v.Image
		if c == "" {
			c = v.Build
		}
		var links []string // change db:redis into db
		for _, l := range v.Links {
			links = append(links, strings.Split(l, ":")[0])
		}
		architecture.AddContainer(a, n, "machine", "instance", c, "process", "monolith", 1, 3, links)
	}
	fmt.Println(*a)
}