-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.go
106 lines (89 loc) · 2.33 KB
/
deploy.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
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"strings"
"time"
log "github.com/Sirupsen/logrus"
"github.com/kohey18/kangol/awsecs"
"github.com/kohey18/kangol/task"
)
func deploy(conf, tag string, debug bool) {
deployment, taskDefinition, err := task.ReadConfig(conf, appendTags(tag))
if err != nil {
log.Fatal(err.Error())
}
service := deployment.Service
cluster := deployment.Cluster
count := deployment.Count
oldRevision, err := awsecs.GetOldRevision(service, cluster)
if err != nil {
log.Fatal(err.Error())
}
log.Info("Now Revision is ... ", oldRevision)
revision := ""
if debug {
log.Info("Stop All Tasks at debug mode ....")
stopTaskError := awsecs.UpdateService(service, cluster, oldRevision, 0)
if stopTaskError != nil {
log.Fatal("Stop All Tasks Error -> ", stopTaskError.Error())
}
_, err := awsecs.PollingDeployment(service, cluster)
if err != nil {
log.Fatal("Stop All Tasks Error -> ", err.Error())
}
}
if conf != "" {
newRevision, err := awsecs.RegisterTaskDefinition(taskDefinition)
if err != nil {
log.Fatal(err.Error())
}
revision = newRevision
} else {
revision = oldRevision
}
log.Info("Deploying Revision is ... ", revision)
log.Info("Deploy Start ....")
getRevisionError := awsecs.UpdateService(service, cluster, revision, count)
if getRevisionError != nil {
log.Fatal("UpdateService Error -> ", getRevisionError.Error())
}
_, deployError := awsecs.PollingDeployment(service, cluster)
if deployError != nil {
rollback := awsecs.UpdateService(service, cluster, oldRevision, count)
if rollback != nil {
log.Fatal("Deploy Error & RollBack Revision Error -> ", getRevisionError.Error())
} else {
log.Info("RollBack Revision -> ", oldRevision)
log.Fatal("Deploy Error -> ", deployError.Error())
}
} else {
log.Info("Deploy SUCCESS -> ", service)
}
}
func appendTags(tag string) map[string]string {
tags := make(map[string]string)
if tag == "" {
return tags
}
nameTags := strings.Split(tag, ",")
for _, v := range nameTags {
nameAndTag := strings.Split(v, ":")
tags[nameAndTag[0]] = nameAndTag[1]
}
return tags
}
func loading(finished chan bool) {
loop:
for {
select {
case <-finished:
break loop
default:
array := []string{"|", "/", "-", "\\"}
for _, v := range array {
fmt.Printf("%s\033[1D", v)
time.Sleep(80 * time.Millisecond)
}
}
}
}