-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
74 lines (60 loc) · 2.28 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
package main
import (
"log"
"os"
nomad "github.com/hashicorp/nomad/api"
"gopkg.in/alecthomas/kingpin.v2"
)
const Version = "1.1.0"
var (
app = kingpin.New("nomad-dtree", "Tool for handling nomad dependencies")
run = app.Command("run", "Run the nomad jobs")
stop = app.Command("stop", "Stop the nomad jobs")
stopPurge = stop.Flag("purge", "Purge the job").Bool()
stopDeep = stop.Flag("deep", "Stop all dependent jobs").Bool()
job = app.Flag("job", "Job").String()
rootFile = app.Flag("root-ca-file", "RootCA File").Envar("ROOT_CA_FILE").String()
certFile = app.Flag("cert-file", "Cert File").Envar("CERT_FILE").String()
keyFile = app.Flag("key-file", "Key File").Envar("KEY_FILE").String()
nomadAddr = app.Flag("nomad-addr", "Nomad Server Addr").Envar("NOMAD_ADDR").Required().String()
storeDriver = app.Flag("store", "store for nomad jobs").Envar("STORE_DRIVER").Default("Filesystem").String()
consulAddr = app.Flag("consul-addr", "Consul Address").Envar("CONSUL_ADDRESS").String()
consulDepFilepath = app.Flag("consul-depfile-path", "Consul Dependency Filepath").Envar("CONSUL_DEP_FILEPATH").String()
consulJobsPath = app.Flag("consul-jobs-path", "Consul Jobs path").Envar("CONSUL_JOBS_PATH").String()
fsDepFilepath = app.Flag("fs-depfile-path", "Filesystem Dependency File Path").Envar("FS_DEP_FILEPATH").String()
fsJobsPath = app.Flag("fs-jobs-path", "Filesystem Path to jobs location").Envar("FS_JOBS_PATH").String()
)
func main() {
log.SetFlags(log.Lshortfile | log.LstdFlags)
cmd := kingpin.MustParse(app.Parse(os.Args[1:]))
config := &nomad.Config{
Address: *nomadAddr,
TLSConfig: &nomad.TLSConfig{
CACert: *rootFile,
ClientCert: *certFile,
ClientKey: *keyFile,
Insecure: true,
},
}
storeConfig := &StoreConfig{
Driver: *storeDriver,
ConsulAddr: *consulAddr,
ConsulDepPath: *consulDepFilepath,
ConsulJobsPath: *consulJobsPath,
FsDepPath: *fsDepFilepath,
FsJobsPath: *fsJobsPath,
}
cmdConfig := &CmdConfig{
Command: cmd,
StopPurge: *stopPurge,
StopDeep: *stopDeep,
}
runner, err := NewRunner(config, storeConfig, cmdConfig)
if err != nil {
log.Fatal(err)
}
rerr := runner.run_tree(*job)
if rerr != nil {
log.Fatal(rerr)
}
}