forked from dogestry/dogestry
/
main.go
92 lines (75 loc) · 1.94 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
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
"strings"
"github.com/dogestry/dogestry/cli"
"github.com/dogestry/dogestry/config"
"github.com/dogestry/dogestry/utils"
)
type pullHosts []string
func (h *pullHosts) String() string {
return fmt.Sprintf("%v", *h)
}
func (h *pullHosts) Set(value string) error {
for _, host := range strings.Split(value, ",") {
*h = append(*h, host)
}
return nil
}
var (
flConfigFile string
flVersion bool
flPullHosts pullHosts
flLockFile string
flUseMetaService bool
)
func init() {
const (
versionDefault = false
versionUsage = "print version"
)
flag.StringVar(&flConfigFile, "config", "", "the dogestry config file (defaults to 'dogestry.cfg' in the current directory). Config is optional - if using s3 you can use env vars or signed URLs.")
flag.BoolVar(&flVersion, "version", versionDefault, versionUsage)
flag.BoolVar(&flVersion, "v", versionDefault, versionUsage+" (short)")
flag.Var(&flPullHosts, "pullhosts", "a comma-separated list of docker hosts where the image will be pulled")
flag.StringVar(&flLockFile, "lockfile", "", "lockfile to use while executing command, prevents parallel executions")
flag.BoolVar(&flUseMetaService, "use-metaservice", false, "use tha AWS metadata service to get credentials")
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Usage = func() {
fmt.Fprintln(os.Stderr, cli.HelpMessage)
}
flag.Parse()
if flVersion {
err := cli.PrintVersion()
if err != nil {
log.Fatal(err)
}
return
}
args := flag.Args()
cfg, err := config.NewConfig(flUseMetaService)
if err != nil {
log.Fatal(err)
}
dogestryCli, err := cli.NewDogestryCli(cfg, flPullHosts)
if err != nil {
log.Fatal(err)
}
if flLockFile != "" {
utils.LockByFile(dogestryCli, args, flLockFile)
} else {
err = dogestryCli.RunCmd(args...)
if err == nil {
dogestryCli.Cleanup()
} else {
dogestryCli.Cleanup()
log.Fatal(err)
}
}
}