Example #1
0
func Query(c *cli.Context) error {

	// Project
	st, err := discovery.GetStore(c)
	if err != nil {
		return err
	}
	args := []string{}
	if c.String("name") != "" {
		args = append(args, c.String("name"))
	}
	p, err := getProject(args, st)
	if err != nil {
		return err
	}

	// Controller
	o, err := swarm.New(st)
	if err != nil {
		return err
	}
	ctr := Controller{orch: o, project: p}

	// Query
	query := strings.Join(c.Args(), " ")
	log.Infoln("Query for:", query)
	if err = ctr.project.Query(query); err != nil {
		return err
	}

	return nil
}
Example #2
0
func Remove(c *cli.Context) error {

	// Project
	st, err := discovery.GetStore(c)
	if err != nil {
		return err
	}
	p, err := getProject(c.Args(), st)
	if err != nil {
		return nil
	}

	// Controller
	o, err := swarm.New(st)
	if err != nil {
		return err
	}
	ctr := Controller{orch: o, project: p}

	// Stop
	if err = ctr.Stop(); err != nil {
		return nil
	}
	fmt.Println("Project deleted:", p.ID)

	return nil
}
Example #3
0
func WriteModeInStore(c *cli.Context, service_name string, input_mode string) error {
	st, err := discovery.GetStore(c)
	if err != nil {
		return err
	}
	err = st.Write("input_mode", input_mode, fmt.Sprintf("services/%s", service_name))
	if err != nil {
		return err
	}
	return err
}
Example #4
0
func WriteCommandInStore(c *cli.Context, service_name string, command string) error {
	st, err := discovery.GetStore(c)
	if err != nil {
		return err
	}
	err = st.Write("command", command, fmt.Sprintf("services/%s", service_name))
	if err != nil {
		return err
	}
	return err
}
Example #5
0
// Launch a docker build from a Dockerfile
func DockerBuild(c *cli.Context, tmp_dir_path, imageName string) (err error) {
	// Get store from cli
	st, err := discovery.GetStore(c)
	if err != nil {
		return err
	}

	// Get swarm from store
	sw, err := swarm.New(st)
	if err != nil {
		return err
	}

	fmt.Printf("Building Docker image named '%s' from Dockerfile located at %s/Dockerfile\n", imageName, tmp_dir_path)
	_, err = sw.BuildImg(imageName, tmp_dir_path)
	check(err)
	return
}
Example #6
0
func List(c *cli.Context) error {
	log.Debugln("Listing")

	st, err := discovery.GetStore(c)
	if err != nil {
		return err
	}
	projects, err := st.List("projects", "")

	all := c.Bool("a")
	fmt.Printf("PROJECT ID\t\tPIPE\t\t\t\t\tSTATUS\t\tNAME\n")
	for _, id := range projects {
		p, err := GetProject(id, st)
		if err != nil {
			continue
		}
		if !all && !p.Running() {
			continue
		}
		msg := p.ID[0:12]
		msg += "\t\t"
		pipes, err := p.GetPipes()
		if err != nil {
			return nil
		}
		msg += strings.Join(pipes, " | ")
		msg += "\t\t\t"
		if p.Running() {
			msg += "Running"
		} else {
			msg += "Exited"
		}
		msg += "\t\t"
		msg += p.Name
		fmt.Println(msg)
	}

	return nil
}
Example #7
0
func Run(c *cli.Context) error {
	daemon := c.Bool("d")
	if daemon {
		log.Debugln("Running project in daemon")
	} else {
		log.Debugln("Running project")
	}

	// Services
	if len(c.Args()) == 0 {
		msg := fmt.Sprintf(
			"You need to provide a workflow, ie. %s",
			"\"service1 | service2 | service3\"",
		)
		return errors.New(msg)
	}
	services := []string{}
	var query string
	for i, service := range strings.Split(c.Args()[0], "|") {
		if i == 0 {
			serviceFull := strings.Split(service, " ")
			service = serviceFull[0]
			if len(serviceFull) > 1 {
				query = strings.Join(serviceFull[1:], " ")
			}
		}
		service = strings.TrimSpace(service)
		services = append(services, service)
	}
	// TODO: check if services exists in store
	log.Debugln("Services", services)

	// Project
	name := c.String("name")
	st, err := discovery.GetStore(c)
	if err != nil {
		return err
	}
	p, err := NewProject(name, st)
	if err != nil {
		return err
	}
	log.Debugln(p)
	if err = p.SetServices(services); err != nil {
		return err
	}
	log.Debugf("Project %s (%s)\n", p.ID, p.Name)
	if daemon {
		fmt.Printf("Project %s (%s)\n", p.ID, p.Name)
	}

	// Controller
	o, err := swarm.New(st)
	if err != nil {
		return err
	}
	ctr := Controller{orch: o, project: p}

	// Run
	api, err := ctr.LaunchAPI()
	if err != nil {
		return err
	}
	for _, service := range ctr.project.Services {
		if err = ctr.launchService(service); err != nil {
			return err
		}
	}
	log.Debugf("API listening on: http://%s\n", api.Addr())

	if daemon {
		fmt.Printf("API listening on: http://%s\n", api.Addr())
		return nil
	}

	// Query
	if query != "" {
		if err = ctr.project.Query(query); err != nil {
			return err
		}
	}

	// Stop
	if err = ctr.Stop(); err != nil {
		return nil
	}

	return nil
}