/
main.go
90 lines (67 loc) · 1.66 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
package main
import (
"fmt"
"os"
"github.com/crowley-io/pack/compose"
"github.com/crowley-io/pack/configuration"
"github.com/crowley-io/pack/docker"
"github.com/crowley-io/pack/install"
"github.com/crowley-io/pack/publish"
"github.com/fatih/color"
cli "github.com/jawher/mow.cli"
)
var (
// Version export pack binary version
Version string
)
func start(module string) {
color.New(color.Bold).PrintfFunc()("\n [crowley-pack] -> %s\n\n", module)
}
func exit(err error, exit int) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
cli.Exit(exit)
}
}
func run(dck docker.Docker, cnf *configuration.Configuration) error {
ls := docker.NewLogStream()
start("install")
if err := install.Install(dck, ls, cnf); err != nil {
return err
}
start("compose")
if err := compose.Compose(dck, ls, cnf); err != nil {
return err
}
start("publish")
if err := publish.Publish(dck, ls, cnf); err != nil {
return err
}
return nil
}
func handle(parse func() (*configuration.Configuration, error)) {
c, err := parse()
exit(err, 253)
d, err := docker.New(c)
exit(err, 254)
if err = run(d, c); err != nil {
exit(err, 255)
}
}
func main() {
app := cli.App("crowley-pack", "Docker build system.")
app.Version("v version", fmt.Sprintf("crowley-pack %s", Version))
app.Command("push", "Compose an image and publish on a registry", func(cmd *cli.Cmd) {
remote, nocache, nopull := getPushOptions(cmd)
cmd.Action = func() {
handle(createRemoteConfigurationParser(remote, nocache, nopull))
}
})
path := getPathOption(app)
app.Action = func() {
handle(createFileConfigurationParser(path))
}
if err := app.Run(os.Args); err != nil {
exit(err, 1)
}
}