Пример #1
0
func main() {
	root := "/var/lib/demo/apps"

	services, _ := discoverd.Services("shelf", discoverd.DefaultTimeout)
	if len(services) < 1 {
		panic("Shelf is not discoverable")
	}
	shelfHost := services[0].Addr

	app := os.Args[2]
	os.MkdirAll(root+"/"+app, 0755)

	fmt.Printf("-----> Building %s...\n", app)

	scheduleAndAttach(sc.RandomJobID(app+"-build."), docker.Config{
		Image:        "flynn/slugbuilder",
		Cmd:          []string{"http://" + shelfHost + "/" + app + ".tgz"},
		Tty:          false,
		AttachStdin:  true,
		AttachStdout: true,
		AttachStderr: true,
		OpenStdin:    true,
		StdinOnce:    true,
	})

	fmt.Printf("-----> Deploying %s ...\n", app)

	jobid := sc.RandomJobID(app + "-web.")

	stopIfExists(jobid)
	scheduleWithTcpPort(jobid, docker.Config{
		Image:        "flynn/slugrunner",
		Cmd:          []string{"start", "web"},
		Tty:          false,
		AttachStdin:  false,
		AttachStdout: false,
		AttachStderr: false,
		OpenStdin:    false,
		StdinOnce:    false,
		Env: []string{
			"SLUG_URL=http://" + shelfHost + "/" + app + ".tgz",
			"SD_NAME=" + app,
		},
	})

	time.Sleep(1 * time.Second)
	fmt.Printf("=====> Application deployed:\n")
	fmt.Printf("       http://10.0.2.15:%s\n", getPort(jobid))
	fmt.Println("")

}
Пример #2
0
func batchHandler(w http.ResponseWriter, r *http.Request) {
	sched, err := jobs.New()
	if error500(w, err) {
		return
	}

	s, err := services.Services("flynn-lorne", services.DefaultTimeout)
	if error500(w, err) {
		return
	}
	hostid := s[0].Attrs["id"]
	jobid := jobs.RandomJobID("batch")

	host, err := hosts.New(hostid)
	if error500(w, err) {
		return
	}

	conn, attachWait, err := host.Attach(&lorne.AttachReq{
		JobID: jobid,
		Flags: lorne.AttachFlagStdout | lorne.AttachFlagStderr | lorne.AttachFlagStdin | lorne.AttachFlagStream,
	}, true)
	if error500(w, err) {
		return
	}

	config := docker.Config{
		Image:        strings.TrimPrefix(r.URL.Path, "/batch/"),
		Cmd:          strings.Split(r.URL.RawQuery, "+"),
		Tty:          false,
		AttachStdin:  false,
		AttachStdout: false,
		AttachStderr: false,
		OpenStdin:    false,
		StdinOnce:    false,
	}

	schedReq := &sampi.ScheduleReq{
		Incremental: true,
		HostJobs: map[string][]*sampi.Job{
			hostid: {{ID: jobid, Config: &config}}},
	}
	_, err = sched.Schedule(schedReq)
	if error500(w, err) {
		return
	}

	err = attachWait()
	if error500(w, err) {
		return
	}

	fw := FlushWriter(w)
	scanner := bufio.NewScanner(conn)
	for scanner.Scan() {
		fmt.Fprintln(fw, scanner.Text())
	}
	conn.Close()
	fw.Write([]byte("\n"))
}