コード例 #1
0
ファイル: runner.go プロジェクト: justintung/flynn
func (r *Runner) removeHost(c *cluster.Cluster, w http.ResponseWriter, q url.Values, ps httprouter.Params) error {
	hostID := ps.ByName("host")
	if err := c.RemoveHost(hostID); err != nil {
		return err
	}
	w.WriteHeader(200)
	return nil
}
コード例 #2
0
ファイル: runner.go プロジェクト: justintung/flynn
func (r *Runner) addReleaseHosts(c *cluster.Cluster, w http.ResponseWriter, q url.Values, ps httprouter.Params) error {
	res, err := c.Boot(cluster.ClusterTypeRelease, 3, nil, false)
	if err != nil {
		return err
	}
	instance, err := c.AddVanillaHost(args.RootFS)
	if err != nil {
		return err
	}
	res.Instances = append(res.Instances, instance)
	return json.NewEncoder(w).Encode(res)
}
コード例 #3
0
ファイル: runner.go プロジェクト: justintung/flynn
func (r *Runner) addHost(c *cluster.Cluster, w http.ResponseWriter, q url.Values, ps httprouter.Params) (err error) {
	var instance *cluster.Instance
	if q.Get("vanilla") == "" {
		instance, err = c.AddHost()
	} else {
		instance, err = c.AddVanillaHost(args.RootFS)
	}
	if err != nil {
		return err
	}
	return json.NewEncoder(w).Encode(instance)
}
コード例 #4
0
ファイル: main.go プロジェクト: justintung/flynn
func createFlynnrc(c *cluster.Cluster) error {
	tmpfile, err := ioutil.TempFile("", "flynnrc-")
	if err != nil {
		return err
	}
	path := tmpfile.Name()

	config, err := c.CLIConfig()
	if err != nil {
		os.RemoveAll(path)
		return err
	}

	if err := config.SaveTo(path); err != nil {
		os.RemoveAll(path)
		return err
	}

	flynnrc = path
	return nil
}
コード例 #5
0
ファイル: client.go プロジェクト: justintung/flynn
func NewClient(endpoint string) (*Client, error) {
	authKey := os.Getenv("TEST_RUNNER_AUTH_KEY")
	if authKey == "" {
		return nil, errors.New("missing TEST_RUNNER_AUTH_KEY environment variable")
	}

	httpClient := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{ServerName: "ci.flynn.io"}}}
	client := &Client{
		Client: &httpclient.Client{
			ErrNotFound: ErrNotFound,
			URL:         endpoint,
			Key:         authKey,
			HTTP:        httpClient,
		},
	}
	var cluster tc.Cluster
	if err := client.Get("", &cluster); err != nil {
		return nil, err
	}
	client.cluster = &cluster
	client.size = cluster.Size()
	return client, nil
}
コード例 #6
0
ファイル: runner.go プロジェクト: justintung/flynn
func (r *Runner) build(b *Build) (err error) {
	logFile, err := ioutil.TempFile("", "build-log")
	if err != nil {
		return err
	}
	b.LogFile = logFile.Name()

	buildLog := buildlog.NewLog(logFile)
	mainLog, err := buildLog.NewFile("build.log")
	if err != nil {
		return err
	}

	r.updateStatus(b, "pending")

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

	start := time.Now()
	fmt.Fprintf(mainLog, "Starting build of %s at %s\n", b.Commit, start.Format(time.RFC822))
	var c *cluster.Cluster
	defer func() {
		b.Duration = time.Since(start)
		b.DurationFormatted = formatDuration(b.Duration)
		fmt.Fprintf(mainLog, "build finished in %s\n", b.DurationFormatted)
		if err != nil {
			fmt.Fprintf(mainLog, "build error: %s\n", err)
			fmt.Fprintln(mainLog, "DUMPING LOGS")
			c.DumpLogs(buildLog)
		}
		c.Shutdown()
		buildLog.Close()
		b.LogURL = r.uploadToS3(logFile, b, buildLog.Boundary())
		logFile.Close()
		os.RemoveAll(b.LogFile)
		b.LogFile = ""
		if err == nil {
			log.Printf("build %s passed!\n", b.ID)
			r.updateStatus(b, "success")
			r.ircMsgs <- fmt.Sprintf("PASS: %s %s", b.Description, b.URL())
		} else {
			log.Printf("build %s failed: %s\n", b.ID, err)
			r.updateStatus(b, "failure")
			r.ircMsgs <- fmt.Sprintf("FAIL: %s %s", b.Description, b.URL())
		}
	}()

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

	out := &iotool.SafeWriter{W: io.MultiWriter(os.Stdout, mainLog)}
	bc := r.bc
	bc.Network = r.allocateNet()
	defer r.releaseNet(bc.Network)

	c = cluster.New(bc, out)
	log.Println("created cluster with ID", c.ID)
	r.clusters[c.ID] = c
	defer func() {
		delete(r.clusters, c.ID)
	}()

	rootFS, err := c.BuildFlynn(r.rootFS, b.Commit, b.Merge, true)
	defer removeRootFS(rootFS)
	if err != nil {
		return fmt.Errorf("could not build flynn: %s", err)
	}

	if _, err := c.Boot(cluster.ClusterTypeDefault, 3, buildLog, false); err != nil {
		return fmt.Errorf("could not boot cluster: %s", err)
	}

	config, err := c.CLIConfig()
	if err != nil {
		return fmt.Errorf("could not generate flynnrc: %s", err)
	}

	var script bytes.Buffer
	testRunScript.Execute(&script, map[string]interface{}{"Cluster": c, "Config": config.Clusters[0], "ListenPort": listenPort})
	return c.RunWithEnv(script.String(), &cluster.Streams{
		Stdout: out,
		Stderr: out,
	}, map[string]string{"TEST_RUNNER_AUTH_KEY": r.authKey})
}
コード例 #7
0
ファイル: runner.go プロジェクト: josephwinston/flynn
func (r *Runner) dumpLogs(c *cluster.Cluster, w http.ResponseWriter, q url.Values, ps httprouter.Params) error {
	c.DumpLogs(w)
	return nil
}