-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.go
92 lines (84 loc) · 1.82 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
// TODO: Test
import (
"fmt"
"log"
"strings"
"./compose"
)
func init() {
log.SetPrefix(">> Docker Flow: ")
log.SetFlags(0)
}
var logFatal = log.Fatal
var logPrintln = log.Println
var logPrintf = log.Printf
var deployed = false
func main() {
// createdFlow := false
flow := getFlow()
sc := getServiceDiscovery()
opts, err := GetOpts()
if err != nil {
logFatal(err)
}
dc := compose.GetDockerCompose()
for _, step := range opts.Flow {
switch strings.ToLower(step) {
case FLOW_DEPLOY:
if err := flow.Deploy(opts, dc); err != nil {
logFatal(err)
}
deployed = true
// TODO: Move to flow
logPrintln("Cleaning...")
if _, err := sc.PutColor(
opts.ServiceDiscoveryAddress,
opts.ServiceName,
opts.NextColor,
); err != nil {
logFatal(err)
}
// TODO: End Move to flow
case FLOW_SCALE:
if !deployed {
logPrintln(fmt.Sprintf("Scaling (%s)...", opts.CurrentTarget))
if err := flow.Scale(opts, dc, opts.CurrentTarget, true); err != nil {
logFatal(err)
}
}
case FLOW_STOP_OLD:
// TODO: Move to flow
if opts.BlueGreen {
target := opts.CurrentTarget
color := opts.CurrentColor
if !deployed {
target = opts.NextTarget
color = opts.NextColor
}
logPrintln(fmt.Sprintf("Stopping old (%s)...", target))
if err := dc.CreateFlowFile(
opts.ComposePath,
opts.ServiceName,
opts.Target,
opts.SideTargets,
color,
opts.BlueGreen,
); err != nil {
logFatal(err)
}
if err := dc.StopTargets(opts.Host, opts.CertPath, opts.Project, []string{target}); err != nil {
logFatal(err)
}
if err := dc.RemoveFlow(); err != nil {
logFatal(err)
}
}
// TODO: End Move to flow
case FLOW_PROXY:
if err := flow.Proxy(opts, haProxy); err != nil {
logFatal(err)
}
}
}
}