-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.go
78 lines (59 loc) · 1.38 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main // import "github.com/CenturyLinkLabs/dray"
import (
"flag"
"net/url"
"os"
"strings"
"github.com/CenturyLinkLabs/dray/api"
"github.com/CenturyLinkLabs/dray/job"
log "github.com/Sirupsen/logrus"
)
const (
defaultDockerEndpoint = "unix:///var/run/docker.sock"
defaultLogLevel = log.InfoLevel
)
func init() {
log.SetOutput(os.Stdout)
log.SetLevel(defaultLogLevel)
}
func main() {
log.SetLevel(logLevel())
port := flag.Int("p", 3000, "port on which the server will run")
flag.Parse()
r := job.NewJobRepository(redisHost())
e := job.NewExecutor(dockerEndpoint())
jm := job.NewJobManager(r, e)
s := api.NewServer(jm)
s.Start(*port)
}
func redisHost() string {
redisPort := os.Getenv("REDIS_PORT")
if len(redisPort) == 0 {
log.Error("Missing required REDIS_PORT environment variable")
}
u, err := url.Parse(redisPort)
if err != nil {
log.Errorf("Invalid Redis URL: %s", err)
panic(err)
}
return u.Host
}
func dockerEndpoint() string {
endpoint := os.Getenv("DOCKER_HOST")
if len(endpoint) == 0 {
endpoint = defaultDockerEndpoint
}
return endpoint
}
func logLevel() log.Level {
levelString := os.Getenv("LOG_LEVEL")
if len(levelString) == 0 {
return defaultLogLevel
}
level, err := log.ParseLevel(strings.ToLower(levelString))
if err != nil {
log.Errorf("Invalid log level: %s", levelString)
return defaultLogLevel
}
return level
}