Ejemplo n.º 1
0
func init() {
	var err error
	log.Out = os.Stderr

	conf = config.Load()

	// Add Papertrail connection for logging
	if conf.Papertrail.Port != 0 {
		hook, err := logrus_papertrail.NewPapertrailHook(conf.Papertrail.Host, conf.Papertrail.Port, "GoBuilder Starter")
		if err != nil {
			log.WithFields(logrus.Fields{
				"host": hostname,
			}).Panic("Unable to create papertrail connection")
			os.Exit(1)
		}

		log.Hooks.Add(hook)
	} else {
		log.WithFields(logrus.Fields{
			"host": hostname,
		}).Info("Failed to read papertrail_port, using only STDERR")
	}

	connectRedis()

	awsAuth, err := aws.EnvAuth()
	if err != nil {
		log.WithFields(logrus.Fields{
			"host": hostname,
			"err":  err,
		}).Panic("Unable to read AWS credentials")
		os.Exit(1)
	}
	s3Bucket = s3.New(awsAuth, aws.EUWest).Bucket("gobuild.luzifer.io")

	dockerClient, err = docker.NewClient("unix:///var/run/docker.sock")
	if err != nil {
		log.WithFields(logrus.Fields{
			"host": hostname,
			"err":  err,
		}).Panic("Unable to connect to docker daemon")
		os.Exit(1)
	}

	currentJobs = make(chan bool, maxConcurrentBuilds)

	hostname, err = os.Hostname()
}
Ejemplo n.º 2
0
func init() {
	var err error
	log.Out = os.Stderr
	log.Formatter = &logrus.TextFormatter{ForceColors: true}

	cfg = config.Load()

	if cfg.Papertrail.Port != 0 {
		hook, err := logrus_papertrail.NewPapertrailHook(cfg.Papertrail.Host, cfg.Papertrail.Port, "GoBuilder Frontend")
		if err != nil {
			log.Panic("Unable to create papertrail connection")
			os.Exit(1)
		}

		log.Hooks.Add(hook)
	}

	redisClient, err = goredis.DialURL(cfg.RedisURL)
	if err != nil {
		log.WithFields(logrus.Fields{
			"url": cfg.RedisURL,
		}).Panic("Unable to connect to Redis")
		os.Exit(1)
	}

	sessionStoreAuthenticationKey := cfg.Session.AuthKey
	if sessionStoreAuthenticationKey == "" {
		sessionStoreAuthenticationKey = string(securecookie.GenerateRandomKey(32))
		log.Warn("The cookie authentication key was autogenerated. This will break sessions!")
	}
	sessionStoreEncryptionKey := cfg.Session.EncryptKey
	if sessionStoreEncryptionKey == "" {
		sessionStoreEncryptionKey = string(securecookie.GenerateRandomKey(32))
		log.Warn("The cookie encryption key was autogenerated. This will break sessions!")
	}

	sessionStore = sessions.NewCookieStore(
		[]byte(sessionStoreAuthenticationKey),
		[]byte(sessionStoreEncryptionKey),
	)

	gob.Register(&flashContext{})
}