Exemplo n.º 1
0
func BoxDeploy(name string, repoUrl string, pathspec string, stream *hub.Stream) (err error) {
	defer func() {
		stream.Close(err)
	}()

	box, err := farmer.FindBoxByName(name)
	if err != nil {
		return errors.New("Cannot find box '" + name + "'")
	}

	if box.State == farmer.StagingState {
		return errors.New("Box '" + name + "' is in Staging progress!")
	}

	box.OutputStream = stream
	box.ErrorStream = stream

	if repoUrl == "" {
		repoUrl = box.Production.RepoUrl
	}

	if pathspec == "" {
		pathspec = box.Production.Pathspec
	}

	if err = box.Release(repoUrl, pathspec); err != nil {
		return
	}

	dispatcher.Trigger("new_release", box)
	return nil
}
Exemplo n.º 2
0
func BoxDeploy(name string, pathspec string, stream *hub.Stream) (err error) {
	defer func() {
		if err != nil {
			stream.Write([]byte(err.Error()))
		}

		stream.Write([]byte("kthxbai"))
		stream.Close()
	}()

	box, err := farmer.FindBoxByName(name)

	if err != nil {
		return err
	}

	box.OutputStream = stream
	box.ErrorStream = stream
	box.Pathspec = pathspec

	if err := box.Deploy(); err != nil {
		return err
	}

	return db.DB.Save(box).Error
}
Exemplo n.º 3
0
// GET
func boxInspect(params martini.Params) (int, string) {
	box, err := farmer.FindBoxByName(params["name"])

	if err != nil {
		return 500, err.Error()
	}

	json, _ := json.Marshal(box)

	return 200, string(json)
}
Exemplo n.º 4
0
func DomainAdd(boxName string, url string, port string) error {
	box, err := farmer.FindBoxByName(boxName)
	if err != nil {
		return errors.New("Cannot find box '" + boxName + "'")
	}

	if err := reverse_proxy.AddDomain(box, url, port); err != nil {
		return err
	}

	return reverse_proxy.Restart()
}
Exemplo n.º 5
0
func DomainDelete(boxName string, url string) error {
	box, err := farmer.FindBoxByName(boxName)
	if err != nil {
		return err
	}

	if err := reverse_proxy.DeleteDomain(box, url); err != nil {
		return err
	}

	return reverse_proxy.Restart()
}
Exemplo n.º 6
0
func BoxDestroy(name string) (err error) {
	box, err := farmer.FindBoxByName(name)

	if err != nil {
		return err
	}

	if err := reverse_proxy.DeleteDomains(box); err != nil {
		return err
	}

	return box.Destroy()
}
Exemplo n.º 7
0
func BoxDelete(name string) error {
	box, err := farmer.FindBoxByName(name)

	if err != nil {
		return err
	}

	if err := box.Destroy(); err != nil {
		return err
	}

	return db.DB.Delete(box).Error
}
Exemplo n.º 8
0
func BoxInspect(boxName string) (BoxInspection, error) {
	box, err := farmer.FindBoxByName(boxName)
	if err != nil {
		return BoxInspection{}, err
	}

	return BoxInspection{
		Name:     box.Name,
		State:    box.State,
		RepoUrl:  box.Production.RepoUrl,
		Pathspec: box.Production.Pathspec,
		Home:     box.Production.Home,
		Ports:    box.Production.Ports,
		Domains:  box.Domains,
		Revision: strconv.Itoa(box.Revision),
		UpdateAt: box.Production.CreatedAt,
	}, nil
}
Exemplo n.º 9
0
func BoxDeploy(name string, repoUrl string, pathspec string, stream *hub.Stream) (err error) {
	defer func() {
		if err != nil {
			stream.Write([]byte(err.Error()))
		}

		stream.Write([]byte("kthxbai"))
		stream.Close()
	}()

	currentBox, err := farmer.FindBoxByName(name)
	if err != nil {
		return err
	}

	if pathspec != "" {
		currentBox.Pathspec = pathspec
	}

	if repoUrl != "" {
		currentBox.RepoUrl = repoUrl
	}

	currentBox.OutputStream = stream
	currentBox.ErrorStream = stream

	updatedBox, err := currentBox.Revision()
	if err != nil {
		updatedBox.DestroyRevision()
		return err
	}

	if err := reverse_proxy.ConfigureDomains(updatedBox); err != nil {
		updatedBox.DestroyRevision()
		reverse_proxy.ConfigureDomains(currentBox)
		return err
	}

	reverse_proxy.Restart()
	currentBox.DestroyRevision()

	return db.DB.Save(updatedBox).Error
}