func BoxCreate(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() }() box := farmer.Box{ Name: name, OutputStream: stream, ErrorStream: stream, RepoUrl: repoUrl, Pathspec: pathspec, CodeDirectory: os.Getenv("FARMER_BOX_DATA_LOCATION") + "/" + name, CgroupParent: "level1", } if err := db.DB.Save(&box).Error; err != nil { return err } if err := box.Create(); err != nil { os.RemoveAll(box.CodeDirectory) db.DB.Delete(&box) return err } return db.DB.Save(&box).Error }
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 }
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 }