Beispiel #1
0
func main() {
	var listen string
	var dockerHost string
	var dockerTLSVerify bool
	var dockerCertPath string
	var debugMode bool
	var debugListen string
	var registryURL string
	var cachePath string
	var dsn string
	var sqlAdapter string

	flag.StringVar(&listen, "listen", ":3000", "host:port to listen on")
	flag.StringVar(&dockerHost, "docker-host", "unix:///var/run/docker.sock", "address of Docker host")
	flag.BoolVar(&dockerTLSVerify, "docker-tls-verify", false, "use TLS client for Docker")
	flag.StringVar(&dockerCertPath, "docker-cert-path", "", "path to the cert.pem, key.pem, and ca.pem for authenticating to Docker")
	flag.BoolVar(&debugMode, "debug", false, "enable /debug endpoints on DEBUG_LISTEN")
	flag.StringVar(&debugListen, "debug-listen", ":3001", "host:port to listen on for debug requests")
	flag.StringVar(&registryURL, "registry-url", "192.168.59.103:5000", "host:port of the registry for pushing images")
	flag.StringVar(&cachePath, "cache-path", "cache/", "path to the directory where cached repos will be stored")
	flag.StringVar(&dsn, "dsn", "file::memory:?cache=shared", "DSN string for connecting to the database")
	flag.StringVar(&sqlAdapter, "sql-adapter", "sqlite3", "adapter to use for the DSN string (currently only supports sqlite3)")
	flag.Parse()

	gin.DisableBindValidation()
	router := gin.Default()
	router.StaticFile("/", "static/index.html")
	router.Use(static.Serve("/", static.LocalFile("static", false)))

	client := dockerClient(dockerHost, dockerTLSVerify, dockerCertPath)
	db, err := sql.Open(sqlAdapter, dsn)
	if err != nil {
		panic(err)
	}
	buildRepo := builds.NewRepository(sqlAdapter, db)
	buildRepo.Migrate()
	logRepo := builds.NewLogRepository(sqlAdapter, db)
	logRepo.Migrate()
	streamRepo := streams.NewRepository()
	builder := builds.NewBuilder(registryURL, client, cachePath)
	buildQueue := builds.NewQueue(buildRepo, streamRepo, logRepo, builder)

	webhookHandler := api.NewWebhookHandler(buildRepo, buildQueue)
	router.POST("/webhooks/github", webhookHandler.Github)

	buildsResource := api.NewBuildsResource(buildRepo, buildQueue)
	router.GET("/builds", buildsResource.Index)
	router.POST("/builds", buildsResource.Create)
	router.GET("/builds/:id", buildsResource.Show)

	streamsResource := api.NewStreamsResource(buildRepo, streamRepo)
	router.GET("/builds/:id/streams/:type", streamsResource.Show)

	logsResource := api.NewLogsResource(buildRepo, logRepo)
	router.GET("/builds/:id/logs/:type", logsResource.Show)

	go buildQueue.Run()

	if debugMode {
		log.Println("Starting debug server on :3001")
		go http.ListenAndServe(debugListen, http.DefaultServeMux)
	}

	router.Run(listen)
}
Beispiel #2
0
func init() {
	rand.Seed(time.Now().UTC().UnixNano())
	gin.DisableBindValidation()
}