forked from play-with-docker/play-with-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
82 lines (67 loc) · 2.5 KB
/
api.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
79
80
81
82
package main
import (
"log"
"os"
"time"
"github.com/play-with-docker/play-with-docker/config"
"github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/handlers"
"github.com/play-with-docker/play-with-docker/id"
"github.com/play-with-docker/play-with-docker/k8s"
"github.com/play-with-docker/play-with-docker/provisioner"
"github.com/play-with-docker/play-with-docker/pwd"
"github.com/play-with-docker/play-with-docker/pwd/types"
"github.com/play-with-docker/play-with-docker/scheduler"
"github.com/play-with-docker/play-with-docker/scheduler/task"
"github.com/play-with-docker/play-with-docker/storage"
)
func main() {
config.ParseFlags()
e := initEvent()
s := initStorage()
df := initDockerFactory(s)
kf := initK8sFactory(s)
ipf := provisioner.NewInstanceProvisionerFactory(provisioner.NewWindowsASG(df, s), provisioner.NewDinD(id.XIDGenerator{}, df, s))
sp := provisioner.NewOverlaySessionProvisioner(df)
core := pwd.NewPWD(df, e, s, sp, ipf)
tasks := []scheduler.Task{
task.NewCheckPorts(e, df),
task.NewCheckSwarmPorts(e, df),
task.NewCheckSwarmStatus(e, df),
task.NewCollectStats(e, df, s),
task.NewCheckK8sClusterStatus(e, kf),
task.NewCheckK8sClusterExposedPorts(e, kf),
}
sch, err := scheduler.NewScheduler(tasks, s, e, core)
if err != nil {
log.Fatal("Error initializing the scheduler: ", err)
}
sch.Start()
d, err := time.ParseDuration(config.DefaultSessionDuration)
if err != nil {
log.Fatalf("Cannot parse duration %s. Got: %v", config.DefaultSessionDuration, err)
}
playground := types.Playground{Domain: config.PlaygroundDomain, DefaultDinDInstanceImage: config.DefaultDinDImage, AllowWindowsInstances: config.NoWindows, DefaultSessionDuration: d, AvailableDinDInstanceImages: []string{config.DefaultDinDImage}, Tasks: []string{".*"}}
if _, err := core.PlaygroundNew(playground); err != nil {
log.Fatalf("Cannot create default playground. Got: %v", err)
}
handlers.Bootstrap(core, e)
handlers.Register(nil)
}
func initStorage() storage.StorageApi {
s, err := storage.NewFileStorage(config.SessionsFile)
if err != nil && !os.IsNotExist(err) {
log.Fatal("Error initializing StorageAPI: ", err)
}
return s
}
func initEvent() event.EventApi {
return event.NewLocalBroker()
}
func initDockerFactory(s storage.StorageApi) docker.FactoryApi {
return docker.NewLocalCachedFactory(s)
}
func initK8sFactory(s storage.StorageApi) k8s.FactoryApi {
return k8s.NewLocalCachedFactory(s)
}