Exemple #1
0
// Process builds a list of packages to emerge between commits
func (g *Gentoo) Process(build *boson.Build) ([]string, []string) { //returns args and volumes to mount

	workdir := build.Config.WorkDir
	config := build.Config
	var ebuilds []string
	var volumes []string
	log.Info("Commit: " + build.Commit)
	diffs, _ := utils.Git([]string{"diff", build.PrevCommit, build.Commit, "--name-only"}, workdir)
	files := strings.Split(diffs, "\n")

	for _, v := range files {
		filename, _ := filepath.Abs(workdir + "/" + v)
		_, err := ioutil.ReadFile(filename)
		if err == nil {
			if strings.Contains(v, ".ebuild") { // We just need ebuilds
				eparts := strings.Split(strings.Replace(v, ".ebuild", "", -1), "/")
				ebuilds = append(ebuilds, "="+eparts[0]+"/"+eparts[2])
				build.Extras = append(build.Extras, "="+eparts[0]+"/"+eparts[2])
			}
		}
	}

	for _, e := range ebuilds {
		log.Debug(e)
	}

	volumes = append(volumes, workdir+":/usr/local/portage:ro") //my volume dir to mount
	if config.SeparateArtifacts == true {
		//in such case, we explicitally want to separate each artifacts directory (in gentoo , our artifact is /usr/portage/packages)
		volumes = append(volumes, config.Artifacts+"/"+build.Commit+":"+artifactsdir)
	} else {
		volumes = append(volumes, config.Artifacts+":"+artifactsdir)
	}
	return ebuilds, volumes
}
Exemple #2
0
func main() {

	var c int
	var configurationFile string
	OptErr = 0
	for {
		if c = Getopt("c:h"); c == EOF {
			break
		}
		switch c {
		case 'c':
			configurationFile = OptArg
		case 'h':
			println("usage: " + os.Args[0] + " [-c my-boson-file.yaml -h]")
			os.Exit(1)
		}
	}

	if configurationFile == "1" {
		fmt.Println("I can't work without a configuration file")
		os.Exit(1)
	}

	backend2 := logging.NewLogBackend(os.Stderr, "", 0)
	backend2Formatter := logging.NewBackendFormatter(backend2, debugformat)
	backenddebug2Formatter := logging.NewBackendFormatter(backend2, normalformat)

	if os.Getenv("DEBUG") == "1" {
		logging.SetBackend(backenddebug2Formatter)

	} else {
		logging.SetBackend(backend2Formatter)
	}

	log.Info("Loading config")

	config, err := utils.LoadConfig(configurationFile)

	if err != nil {
		panic(err)
	}

	// Bootstrapper for plugins
	log.Info("Available preprocessors:")

	for i := range boson.Preprocessors {
		log.Info("\t *" + i)
		boson.Preprocessors[i].OnStart()
	}

	os.MkdirAll(config.TmpDir, 666)
	client := jdb.NewDB("./" + configurationFile + ".db")
	builder := boson.NewBuilder(&config)
	if ok, _ := utils.Exists(config.WorkDir); ok == true { //if already exists, using fetch && reset
		utils.GitAlignToUpstream(config.WorkDir)
	} else { //otherwise simply clone the repo
		log.Info(utils.Git([]string{"clone", config.Repository, config.WorkDir}, config.TmpDir))
	}
	if _, ok := boson.Preprocessors[config.PreProcessor]; ok {

		if os.Getenv("BOSON_FROM") != "" && os.Getenv("BOSON_TO") != "" {
			builder.Run(builder.NewBuild(os.Getenv("BOSON_TO"), os.Getenv("BOSON_FROM")))
		} else if os.Getenv("BOSON_FROM") != "" {

			head := utils.GitHead(config.WorkDir)
			ok, err := builder.Run(builder.NewBuild(head, os.Getenv("BOSON_FROM")))
			if ok == true && err == nil {
				os.Exit(0)
			} else {
				os.Exit(42)
			}

		} else { //defaulting to ticker mode

			ticker := time.NewTicker(time.Second * time.Duration(config.PollTime))
			for _ = range ticker.C {
				log.Debug(" Cloning " + config.Repository + " to " + config.WorkDir)
				head := utils.GitHead(config.WorkDir)

				if ok, _ := utils.Exists(config.WorkDir); ok == true { //if already exists, using fetch && reset
					utils.GitAlignToUpstream(config.WorkDir)
				} else { //otherwise simply clone the repo
					log.Info(utils.Git([]string{"clone", config.Repository, config.WorkDir}, config.TmpDir))
				}

				lastbuild, _ := client.GetBuild("LATEST_PASSED")
				log.Info("Head now is at " + head)
				if head == lastbuild.Commit {
					log.Info("nothing to do")
					continue
				}
				build := builder.NewBuild(head, lastbuild.Commit)
				if ok, _ = builder.Run(build); ok == true { //Save the build status to id
					result := jdb.Build{Id: "LATEST_PASSED", Passed: true, Commit: build.Commit}
					client.SaveBuild(result)
					result = jdb.Build{Id: build.Commit, Passed: true, Commit: build.PrevCommit}
					client.SaveBuild(result)
				} else {
					result := jdb.Build{Id: "LATEST_PASSED", Passed: false, Commit: build.Commit}
					client.SaveBuild(result)
					result = jdb.Build{Id: build.Commit, Passed: false, Commit: build.PrevCommit}
					client.SaveBuild(result)
				}

			}
		}
	} else { //Provisioning
		if builder.Provision(builder.NewBuild("", "")) == true {
			os.Exit(0)
		} else {
			os.Exit(42)
		}
	}

}