Example #1
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()
}
Example #2
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()
}
Example #3
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
}