예제 #1
0
파일: main.go 프로젝트: kaisne/gobuild
func init() {
	cfg := new(config)
	in, err := ioutil.ReadFile("config.yaml")
	if err != nil {
		lg.Fatal(err)
	}
	err = goyaml.Unmarshal(in, cfg)
	if err != nil {
		lg.Fatal(err)
	}

	flag.Parse()

	if *environment == "development" {
		opts = &cfg.Development
	} else {
		opts = &cfg.Production
	}

	fmt.Println("== environment:", *environment, "==")
	utils.Dump(opts)

	conf.ACCESS_KEY = opts.AccessKey
	conf.SECRET_KEY = opts.SecretKey

	// render html templates from templates directory
	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))
	InitRouter()
}
예제 #2
0
파일: build_get.go 프로젝트: matm/gobuild
// download src
func (b *Builder) get() (err error) {
	log.Debug("start get src to:", b.srcDir)
	exists := beeutils.FileExists(b.srcDir)
	b.sh.Command("go", "version").Run()
	if !exists {
		err = b.sh.Command("go", "get", "-v", "-d", b.project).Run()
		if err != nil {
			return
		}
	}
	b.sh.SetDir(b.srcDir)
	if b.ref == "-" {
		b.ref = "master"
	}
	// get code from remote
	if err = b.sh.Command("git", "fetch", "origin").Run(); err != nil {
		return
	}
	// change branch
	if err = b.sh.Command("git", "checkout", "-q", b.ref).Run(); err != nil {
		return
	}
	// update code
	if err = b.sh.Command("git", "merge", "origin/"+b.ref).Run(); err != nil {
		log.Warn("git merge error:", err)
		//return
	}
	// get sha
	out, err := sh.Command("git", "rev-parse", "HEAD", sh.Dir(b.srcDir)).Output()
	if err != nil {
		return
	}
	b.sha = strings.TrimSpace(string(out))

	// parse .gobuild
	b.rc = new(Assembly)
	rcfile := "public/gobuildrc"
	if b.sh.Test("f", ".gobuild") {
		rcfile = filepath.Join(b.srcDir, ".gobuild")
	}
	data, err := ioutil.ReadFile(rcfile)
	if err != nil {
		return
	}
	err = goyaml.Unmarshal(data, b.rc)
	return
}
예제 #3
0
파일: build_get.go 프로젝트: kaisne/gobuild
// download src
func (b *Builder) get() (err error) {
	exists := beeutils.FileExists(b.srcDir)
	b.sh.Command("date")
	if !exists {
		err = b.sh.Command("go", "get", "-v", "-d", b.project).Run()
		if err != nil {
			return
		}
	}
	b.sh.SetDir(b.srcDir)
	if b.ref == "-" {
		b.ref = "master"
	}
	if err = b.sh.Command("git", "fetch", "origin").Run(); err != nil {
		return
	}
	if err = b.sh.Command("git", "checkout", "-q", b.ref).Run(); err != nil {
		return
	}
	if err = b.sh.Command("git", "merge", "origin/"+b.ref).Run(); err != nil {
		return
	}
	out, err := sh.Command("git", "rev-parse", "HEAD", sh.Dir(b.srcDir)).Output()
	if err != nil {
		return
	}
	b.sha = strings.TrimSpace(string(out))

	// parse .gobuild
	b.rc = new(Assembly)
	rcfile := "public/gobuildrc"
	if b.sh.Test("f", ".gobuild") {
		rcfile = filepath.Join(b.srcDir, ".gobuild")
	}
	data, err := ioutil.ReadFile(rcfile)
	if err != nil {
		return
	}
	err = goyaml.Unmarshal(data, b.rc)
	return
}
예제 #4
0
파일: assembly.go 프로젝트: kaisne/gobuild
func (b *Builder) pack(bins []string, rcfile string) (path string, err error) {
	lg.Debug(bins)
	lg.Debug(rcfile)
	data, err := ioutil.ReadFile(rcfile)
	if err != nil {
		lg.Warn(err)
		lg.Debug("use default rc")
		data, err = ioutil.ReadFile("public/gobuildrc")
		if err != nil {
			lg.Error(err)
		}
	}
	ass := new(Assembly)
	err = goyaml.Unmarshal(data, ass)
	if err != nil {
		return
	}
	dir := filepath.Dir(rcfile)
	fs, err := ioutil.ReadDir(dir)
	if err != nil {
		return
	}
	var includes = bins // this may change slice bins
	for _, f := range fs {
		var ok = false
		for _, patten := range ass.Includes {
			if match(patten, f.Name()) {
				ok = true
				break
			}
		}

		if ok {
			includes = append(includes, filepath.Join(dir, f.Name()))
		}
	}
	return pkgZip(dir, includes)
}