Example #1
0
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
}
Example #2
0
func AddDomain(box *farmer.Box, url string, port string) error {
	if err := box.AddDomain(url, port); err != nil {
		return err
	}

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

	return db.DB.Save(&box).Error
}
Example #3
0
func DeleteDomain(box *farmer.Box, url string) error {
	domain := &farmer.Domain{
		BoxID: box.ID,
		Url:   url,
	}

	if err := db.DB.Find(domain).Error; err != nil {
		return err
	}

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

	os.Remove(configFile(domain.Url, domain.Port))

	return db.DB.Delete(domain).Error
}
Example #4
0
func BoxCreate(name string, repoUrl string, pathspec string, stream *hub.Stream) (err error) {
	defer func() {
		stream.Close(err)
	}()

	box := farmer.Box{
		Name:         name,
		Directory:    os.Getenv("FARMER_BOX_DATA_LOCATION") + "/" + name,
		OutputStream: stream,
		ErrorStream:  stream,
		UpdateTime:   time.Now().Local().Format(farmer.TimeFormat),
	}
	box.KeepReleases, _ = strconv.Atoi(os.Getenv("FARMER_BOX_KEEP_RELEASES"))

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

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

	return
}