示例#1
0
func newConveyor(t testing.TB) *Conveyor {
	db := sqlx.MustConnect("postgres", databaseURL)
	if err := core.Reset(db); err != nil {
		t.Fatal(err)
	}

	c := core.New(db)
	c.BuildQueue = core.NewBuildQueue(100)
	c.Logger = logs.Discard

	ch := make(chan core.BuildContext)
	c.BuildQueue.Subscribe(ch)

	w := worker.New(c, worker.Options{
		Builder: builder.BuilderFunc(func(ctx context.Context, w io.Writer, options builder.BuildOptions) (string, error) {
			io.WriteString(w, "Pulling base image\n")
			return "remind101/acme-inc:1234", nil
		}),
		BuildRequests: ch,
	})

	go w.Start()

	return &Conveyor{
		Conveyor: c,
		worker:   w,
	}
}
示例#2
0
func newBuildQueue(c *cli.Context) conveyor.BuildQueue {
	u := urlParse(c.String("queue"))

	switch u.Scheme {
	case "memory":
		return conveyor.NewBuildQueue(100)
	case "sqs":
		q := conveyor.NewSQSBuildQueue(defaults.DefaultConfig)
		if u.Host == "" {
			q.QueueURL = os.Getenv("SQS_QUEUE_URL")
		} else {
			url := *u
			url.Scheme = "https"
			q.QueueURL = url.String()
		}
		return q
	default:
		must(fmt.Errorf("Unknown queue: %v", u.Scheme))
		return nil
	}
}