コード例 #1
0
ファイル: main.go プロジェクト: craigfurman/Woodhouse-CI
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
			buildNumber    int
			outputDest     io.WriteCloser
			exitStatusChan chan uint32
			createErr      error
		)

		JustBeforeEach(func() {
			buildNumber, outputDest, exitStatusChan, createErr = repo.Create(jobId)
		})

		Context("when the builds directory already exists", func() {
			BeforeEach(func() {
				var err error
				buildsDir, err = ioutil.TempDir("", "builds")
				Expect(err).NotTo(HaveOccurred())
				repo = builds.NewRepository(buildsDir)
			})

			AfterEach(func() {
				Expect(os.RemoveAll(buildsDir)).To(Succeed())
			})

			It("does not error", func() {
				Expect(createErr).NotTo(HaveOccurred())
			})

			It("is the first build for this job", func() {
				Expect(buildNumber).To(Equal(1))
			})

			Context("when another build for the same job is created", func() {