示例#1
0
// Find a container by inspecting dokku command output
func (s *ContainerStore) lookup(id string) (container *m.Container, err error) {
	// Gather output of `dokku ls` to read container list
	out, err := Exec("ls")
	if err != nil {
		err = fmt.Errorf("Error requesting container %q: %s", id, err)
		return
	}

	// TODO: find a better way to do this (maybe by inspecting the app folder?)
	for _, line := range out {
		if !strings.Contains(line, id) {
			// Line does not contain requested container; skip it
			continue
		}

		var cerr error
		container, cerr = m.ParseContainer(line)
		if cerr == nil {
			log.Printf(
				"Found container %q; type %q; %s",
				container.ID, container.Type, container.Status)
			return
		}
	}

	// If control reaches this stage, the container was not found
	err = fmt.Errorf("Could not find container %q", id)
	return
}
示例#2
0
// Find an app by inspecting dokku command output
func (s *AppStore) lookup(name string) (app *m.App, err error) {
	// First ensure the app exists
	out, err := Exec("apps")
	if err != nil {
		err = fmt.Errorf("Error requesting app %q: %s", name, err)
		return
	}

	exists := false
	for _, line := range out {
		if line == name {
			exists = true
		}
	}

	if !exists {
		// App does not exist; return nil
		return
	}

	// App exists; start gathering additional info
	app = new(m.App)
	app.Name = name
	// Set initial app status to undeployed
	// Status will be updated based on container statuses
	app.Status = m.Undeployed

	// Gather output of `dokku ls` to read container list
	out, err = Exec("ls")
	if err != nil {
		err = fmt.Errorf("Error requesting app %q: %s", name, err)
		return
	}

	// Find all containers for app
	// TODO: find a better way to do this (maybe by inspecting the app folder?)
	for _, line := range out {
		c, cerr := m.ParseContainer(line)
		if cerr == nil && c.App == name {
			log.Printf("Found container %q; type %q; %s", c.ID, c.Type, c.Status)
			app.Containers = append(app.Containers, c.GetID())

			if c.Status == m.Running {
				app.Status = m.Running
			}

			if c.Status == m.Stopped && app.Status == m.Undeployed {
				app.Status = m.Stopped
			}
		}
	}

	// Find domains for app
	out, err = Exec("domains", name)
	if err != nil {
		err = fmt.Errorf("Error requesting domains for app %q: %s", name, err)
		return
	}

	for _, line := range out {
		d, derr := m.NewDomain(line)
		if derr == nil {
			log.Printf("Found domain %q", d.Name)
			app.Domains = append(app.Domains, d.Name)
		}
	}

	return
}