This repository has been archived by the owner on Jun 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
96 lines (84 loc) · 2.02 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/op/go-logging"
)
var (
log = logging.MustGetLogger("zbundle")
)
func init() {
logging.SetLevel(logging.INFO, "")
}
func main() {
// 1- mount the flist
// 2- we need to export some env variables
// 3- how to run ? bash, etc.
app := cli.NewApp()
app.Name = "zbundle"
app.Usage = "run mini environments from flist"
app.UsageText = "zbundle [options] <flist> <args>"
app.Version = "1.0"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "id, i",
Usage: "[required] ID of the sandbox",
},
cli.StringFlag{
Name: "entry-point",
Value: "/etc/start",
Usage: "sandbox entry point",
},
cli.StringSliceFlag{
Name: "env, e",
Usage: "custom environemt variables",
},
cli.StringSliceFlag{
Name: "report, r",
Usage: "report error back on failures to the given url",
},
cli.StringFlag{
Name: "storage, s",
Value: "zdb://hub.grid.tf:9900",
Usage: "storage url to use",
},
cli.BoolFlag{
Name: "debug, d",
Usage: "run in debug mode",
},
cli.BoolFlag{
Name: "no-exit",
Usage: "do not terminate (unmount the sandbox) after /etc/start exits",
},
cli.IntFlag{
Name: "update",
Value: 30,
Usage: "Check for flist updates interval in minutes",
},
}
app.ArgsUsage = "flist"
app.Before = func(ctx *cli.Context) error {
logging.Reset()
backend := logging.NewLogBackend(os.Stdout, "", 0)
formatter := logging.MustStringFormatter("%{color}%{time:15:04:05.000} %{module} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}")
logging.SetBackend(logging.NewBackendFormatter(backend, formatter))
if ctx.GlobalBool("debug") {
logging.SetLevel(logging.DEBUG, "")
} else {
logging.SetLevel(logging.INFO, "")
}
//validate required inputs
for _, key := range []string{"id"} {
value := ctx.GlobalString(key)
if value == "" {
return fmt.Errorf("flag --%s is required", key)
}
}
return nil
}
app.Action = action
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}