-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.go
88 lines (72 loc) · 1.52 KB
/
run.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
package main
import (
"fmt"
ng "github.com/goombaio/namegenerator"
"github.com/urfave/cli/v2"
"time"
)
func run(c *cli.Context) error {
a := c.Args()
image, name, context, file, args := c.String("image"), c.String("name"), c.String("context"), c.String("file"), a.Slice()
ba := c.StringSlice("build-args")
env := c.StringSlice("environment")
vol := c.StringSlice("volume")
net := c.String("network")
rest := make([]string, 0, len(args))
cmd := make([]string, 0, len(args))
for _, v := range ba {
rest = append(rest, "b:--build-arg")
rest = append(rest, "b:"+v)
}
for _, v := range env {
rest = append(rest, "r:-e")
rest = append(rest, "r:"+v)
}
for _, v := range vol {
rest = append(rest, "r:-v")
rest = append(rest, "r:"+v)
}
if net != "" {
rest = append(rest, "r:--net")
rest = append(rest, "r:"+net)
}
after := false
for _, v := range args {
if v == "---" {
after = true
continue
}
if after {
rest = append(rest, v)
} else {
cmd = append(cmd, v)
}
}
if image == "" {
seed := time.Now().UTC().UnixNano()
ng := ng.NewNameGenerator(seed)
image = ng.Generate()
}
if context == "" {
context = "."
}
if file == "" {
file = "Dockerfile"
}
err := n.Run(context, file, image, name, cmd, rest)
if len(err) > 0 {
return e(err)
}
return nil
}
func runComplete(c cli.Context) {
if c.NArg() < 2 {
seed := time.Now().UTC().UnixNano()
ng := ng.NewNameGenerator(seed)
if c.NArg() == 0 {
for i := 0; i < 5; i++ {
fmt.Println(ng.Generate())
}
}
}
}