示例#1
0
文件: factories.go 项目: mhahn/empire
func newEmpire(db *empire.DB, c *Context) (*empire.Empire, error) {
	docker, err := newDockerClient(c)
	if err != nil {
		return nil, err
	}

	scheduler, err := newScheduler(db, c)
	if err != nil {
		return nil, err
	}

	logs, err := newLogsStreamer(c)
	if err != nil {
		return nil, err
	}

	streams, err := newEventStreams(c)
	if err != nil {
		return nil, err
	}

	runRecorder, err := newRunRecorder(c)
	if err != nil {
		return nil, err
	}

	e := empire.New(db)
	e.Scheduler = scheduler
	e.Secret = []byte(c.String(FlagSecret))
	e.EventStream = empire.AsyncEvents(streams)
	e.ProcfileExtractor = empire.PullAndExtract(docker)
	e.Environment = c.String(FlagEnvironment)
	e.RunRecorder = runRecorder
	e.MessagesRequired = c.Bool(FlagMessagesRequired)

	switch c.String(FlagAllowedCommands) {
	case "procfile":
		e.AllowedCommands = empire.AllowCommandProcfile
	default:
	}

	if logs != nil {
		e.LogsStreamer = logs
	}

	return e, nil
}
示例#2
0
func newEmpire(c *cli.Context) (*empire.Empire, error) {
	db, err := newDB(c)
	if err != nil {
		return nil, err
	}

	docker, err := newDockerClient(c)
	if err != nil {
		return nil, err
	}

	reporter, err := newReporter(c)
	if err != nil {
		return nil, err
	}

	scheduler, err := newScheduler(c)
	if err != nil {
		return nil, err
	}

	logs, err := newLogsStreamer(c)
	if err != nil {
		return nil, err
	}

	events, err := newEventStream(c)
	if err != nil {
		return nil, err
	}

	e := empire.New(db, empire.Options{
		Secret: c.String(FlagSecret),
	})
	e.Reporter = reporter
	e.Scheduler = scheduler
	e.LogsStreamer = logs
	e.EventStream = empire.AsyncEvents(events)
	e.ExtractProcfile = empire.PullAndExtract(docker)
	e.Logger = newLogger()

	return e, nil
}