-
Notifications
You must be signed in to change notification settings - Fork 3
/
fabrica.go
53 lines (45 loc) · 1.41 KB
/
fabrica.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
package main
import (
"flag"
"github.com/ogra1/fabrica/config"
"github.com/ogra1/fabrica/datastore"
"github.com/ogra1/fabrica/datastore/sqlite"
"github.com/ogra1/fabrica/service"
"github.com/ogra1/fabrica/service/key"
"github.com/ogra1/fabrica/service/lxd"
"github.com/ogra1/fabrica/service/repo"
"github.com/ogra1/fabrica/service/system"
"github.com/ogra1/fabrica/service/watch"
"github.com/ogra1/fabrica/web"
"os"
)
func main() {
var mode string
flag.StringVar(&mode, "mode", "web", "Mode of operation: web, watch, keygen")
flag.Parse()
if mode == "keygen" {
service.GenerateHostKey()
os.Exit(0)
}
settings := config.ReadParameters()
// Set up the dependency chain
db, _ := sqlite.NewDatabase()
systemSrv := system.NewSystemService(db)
lxdSrv := lxd.NewLXD(db, systemSrv)
buildSrv := repo.NewBuildService(db, lxdSrv)
keySrv := key.NewKeyService(db)
// Set up the service based on the mode
if mode == "watch" {
watchDaemon(db, buildSrv, keySrv)
} else {
webService(settings, buildSrv, lxdSrv, systemSrv, keySrv)
}
}
func webService(settings *config.Settings, buildSrv *repo.BuildService, lxdSrv lxd.Service, systemSrv system.Srv, keySrv key.Srv) {
srv := web.NewWebService(settings, buildSrv, lxdSrv, systemSrv, keySrv)
srv.Start()
}
func watchDaemon(db datastore.Datastore, buildSrv repo.BuildSrv, keySrv key.Srv) {
watchSrv := watch.NewWatchService(db, buildSrv, keySrv)
watchSrv.Watch()
}