// NewEmpire returns a new Empire instance suitable for testing. It ensures that // the database is clean before returning. func NewEmpire(t testing.TB) *empire.Empire { opts := empire.Options{ DB: DatabaseURL, AWSConfig: nil, Docker: empire.DockerOptions{ Auth: &docker.AuthConfigurations{ Configs: map[string]docker.AuthConfiguration{ "https://index.docker.io/v1/": docker.AuthConfiguration{ Username: "", Password: "", }, }, }, }, } e, err := empire.New(opts) if err != nil { t.Fatal(err) } if err := e.Reset(); err != nil { t.Fatal(err) } return e }
// NewEmpire returns a new Empire instance suitable for testing. It ensures that // the database is clean before returning. func NewEmpire(t testing.TB) *empire.Empire { db, err := empire.OpenDB(DatabaseURL) if err != nil { t.Fatal(err) } if err := db.MigrateUp(); err != nil { t.Fatal(err) } // Log queries if verbose mode is set. if testing.Verbose() { db.Debug() } e := empire.New(db) e.Scheduler = scheduler.NewFakeScheduler() e.ProcfileExtractor = ExtractProcfile(nil) e.RunRecorder = empire.RecordTo(ioutil.Discard) if err := e.Reset(); err != nil { t.Fatal(err) } return e }
func Example() { // Open a postgres connection. db, _ := empire.OpenDB("postgres://localhost/empire?sslmode=disable") // Migrate the database schema. _ = db.MigrateUp() // Initialize a new Empire instance. e := empire.New(db) // Run operations against Empire. apps, _ := e.Apps(empire.AppsQuery{}) fmt.Println(apps) // Output: // [] }
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 }
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 }
func newEmpire(c *cli.Context) (*empire.Empire, error) { opts := empire.Options{} opts.Docker.Socket = c.String(FlagDockerSocket) opts.Docker.CertPath = c.String(FlagDockerCert) opts.AWSConfig = aws.NewConfig() if c.Bool(FlagAWSDebug) { opts.AWSConfig.WithLogLevel(1) } opts.ECS.Cluster = c.String(FlagECSCluster) opts.ECS.ServiceRole = c.String(FlagECSServiceRole) opts.ELB.InternalSecurityGroupID = c.String(FlagELBSGPrivate) opts.ELB.ExternalSecurityGroupID = c.String(FlagELBSGPublic) opts.ELB.InternalSubnetIDs = c.StringSlice(FlagEC2SubnetsPrivate) opts.ELB.ExternalSubnetIDs = c.StringSlice(FlagEC2SubnetsPublic) opts.ELB.InternalZoneID = c.String(FlagRoute53InternalZoneID) opts.DB = c.String(FlagDB) opts.Secret = c.String(FlagSecret) opts.LogsStreamer = c.String(FlagLogsStreamer) auth, err := dockerAuth(c.String(FlagDockerAuth)) if err != nil { return nil, err } opts.Docker.Auth = auth e, err := empire.New(opts) if err != nil { return e, err } reporter, err := newReporter(c.String(FlagReporter)) if err != nil { return e, err } e.Reporter = reporter return e, nil }
// NewEmpire returns a new Empire instance suitable for testing. It ensures that // the database is clean before returning. func NewEmpire(t testing.TB) *empire.Empire { db, err := empire.OpenDB(DatabaseURL) if err != nil { t.Fatal(err) } // TODO: Run db.MigrateUp once migrations are in the binary. // Log queries if verbose mode is set. if testing.Verbose() { db.Debug() } e := empire.New(db, empire.DefaultOptions) e.Scheduler = scheduler.NewFakeScheduler() e.ExtractProcfile = ExtractProcfile if err := e.Reset(); err != nil { t.Fatal(err) } return e }