コード例 #1
0
ファイル: runner.go プロジェクト: kelsieflynn/flynn-test-1
func (r *Runner) start() error {
	r.githubToken = os.Getenv("GITHUB_TOKEN")
	if r.githubToken == "" {
		return errors.New("GITHUB_TOKEN not set")
	}

	awsAuth, err := aws.EnvAuth()
	if err != nil {
		return err
	}
	r.s3Bucket = s3.New(awsAuth, aws.USEast).Bucket(logBucket)

	if r.dockerFS == "" {
		var err error
		bc := r.bc
		bc.Network, err = r.allocateNet()
		if err != nil {
			return err
		}
		if r.dockerFS, err = cluster.BuildFlynn(bc, "", util.Repos, os.Stdout); err != nil {
			return fmt.Errorf("could not build flynn: %s", err)
		}
		r.releaseNet(bc.Network)
		defer os.RemoveAll(r.dockerFS)
	}

	db, err := bolt.Open(args.DBPath, 0600, &bolt.Options{Timeout: 5 * time.Second})
	if err != nil {
		return fmt.Errorf("could not open db: %s", err)
	}
	r.db = db
	defer r.db.Close()

	if err := r.db.Update(func(tx *bolt.Tx) error {
		_, err := tx.CreateBucketIfNotExists([]byte("pending-builds"))
		return err
	}); err != nil {
		return fmt.Errorf("could not create pending-builds bucket: %s", err)
	}

	for i := 0; i < maxBuilds; i++ {
		r.buildCh <- struct{}{}
	}

	if err := r.buildPending(); err != nil {
		log.Printf("could not build pending builds: %s", err)
	}

	go r.watchEvents()

	http.Handle("/", handlers.CombinedLoggingHandler(os.Stdout, http.HandlerFunc(r.httpEventHandler)))
	log.Println("Listening on :80...")
	if err := http.ListenAndServe(":80", nil); err != nil {
		return fmt.Errorf("ListenAndServer: %s", err)
	}
	return nil
}
コード例 #2
0
ファイル: runner.go プロジェクト: kelsieflynn/flynn-test-1
func (r *Runner) build(b *Build) (err error) {
	r.updateStatus(b, "pending", "")

	<-r.buildCh
	defer func() {
		r.buildCh <- struct{}{}
	}()

	var buildLog bytes.Buffer
	defer func() {
		if err != nil {
			fmt.Fprintf(&buildLog, "build error: %s\n", err)
		}
		url := r.uploadToS3(buildLog, b)
		if err == nil {
			r.updateStatus(b, "success", url)
		} else {
			r.updateStatus(b, "failure", url)
		}
	}()

	log.Printf("building %s[%s]\n", b.Repo, b.Commit)

	out := io.MultiWriter(os.Stdout, &buildLog)
	repos := map[string]string{b.Repo: b.Commit}
	bc := r.bc
	bc.Network, err = r.allocateNet()
	if err != nil {
		return err
	}
	defer r.releaseNet(bc.Network)
	newDockerfs, err := cluster.BuildFlynn(bc, r.dockerFS, repos, out)
	defer os.RemoveAll(newDockerfs)
	if err != nil {
		msg := fmt.Sprintf("could not build flynn: %s\n", err)
		buildLog.WriteString(msg)
		return errors.New(msg)
	}

	cmd := exec.Command(
		args.TestsPath,
		"--user", r.bc.User,
		"--rootfs", r.bc.RootFS,
		"--dockerfs", newDockerfs,
		"--kernel", r.bc.Kernel,
		"--cli", args.CLI,
		"--network", bc.Network,
		"--nat", r.bc.NatIface,
		"--debug",
	)
	cmd.Stdout = out
	cmd.Stderr = out
	return cmd.Run()
}