예제 #1
0
func main() {
	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	must(err)
	distBase := filepath.Join(dir, "..")

	port := flag.Uint("port", 8080, "port to listen on")
	templateDir := flag.String("templateDir", filepath.Join(distBase, "web", "templates"), "path to html templates")
	storeDir := flag.String("storeDir", filepath.Join(distBase, "db"), "directory for saving persistent data")
	buildsDir := flag.String("buildsDir", filepath.Join(distBase, "builds"), "directory for saving build output")
	assetsDir := flag.String("assetsDir", filepath.Join(distBase, "web", "assets"), "path to static web assets")
	gooseCmd := flag.String("gooseCmd", filepath.Join(distBase, "bin", "goose"), `path to "goose" database migration tool`)
	debugMode := flag.Bool("debugMode", false, "do not parse templates up front. Only for development use")
	flag.Parse()

	bootMsg := ` _    _                 _ _                                 _____ _____
| |  | |               | | |                               /  __ \_   _|
| |  | | ___   ___   __| | |__   ___  _   _ ___  ___ ______| /  \/ | |
| |/\| |/ _ \ / _ \ / _` + "`" + ` | '_ \ / _ \| | | / __|/ _ \______| |     | |
\  /\  / (_) | (_) | (_| | | | | (_) | |_| \__ \  __/      | \__/\_| |_
 \/  \/ \___/ \___/ \__,_|_| |_|\___/ \__,_|___/\___|       \____/\___/
`

	fmt.Println(bootMsg)
	if *debugMode {
		log.Println("Starting in debug mode")
	}

	dbDir := filepath.Join(*storeDir, "sqlite")
	must(os.MkdirAll(dbDir, 0755))

	migrateCmd := exec.Command(*gooseCmd, "up")
	migrateCmd.Dir = filepath.Join(*storeDir, "..")
	must(migrateCmd.Run())

	jobRepo, err := db.NewJobRepository(filepath.Join(dbDir, "store.db"))
	must(err)

	// Only Interrupt handled, as this is available on all major platforms and is the most common way of stopping Woodhouse-CI
	exitChan := make(chan os.Signal)
	signal.Notify(exitChan, os.Interrupt)
	go func(c <-chan os.Signal) {
		log.Printf("Caught signal %s. Closing database connections. Goodbye!\n", <-c)
		must(jobRepo.Close())
		os.Exit(0)
	}(exitChan)

	handler := web.New(&jobs.Service{
		JobRepository:   jobRepo,
		Runner:          runner.NewDockerRunner(vcs.GitCloner{}),
		BuildRepository: builds.NewRepository(*buildsDir),
	}, *templateDir, !*debugMode)

	server := negroni.New(negroni.NewRecovery(), negroni.NewLogger(), negroni.NewStatic(http.Dir(*assetsDir)))
	server.UseHandler(handler)
	server.Run(fmt.Sprintf("0.0.0.0:%d", *port))
}
예제 #2
0
)

var _ = Describe("Handlers", func() {
	var (
		server *httptest.Server
		page   *agouti.Page

		jobService *fake_job_service.FakeJobService
	)

	BeforeEach(func() {
		cwd, err := os.Getwd()
		Expect(err).NotTo(HaveOccurred())

		jobService = new(fake_job_service.FakeJobService)
		handler := web.New(jobService, filepath.Join(cwd, "templates"), true)
		server = httptest.NewServer(handler)

		page, err = agoutiDriver.NewPage()
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		Expect(page.Destroy()).To(Succeed())
		server.Close()
	})

	// TODO is this covered by integration tests?
	PDescribe("listing jobs", func() {})

	Describe("creating a job", func() {