-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreleases.go
More file actions
157 lines (139 loc) · 4.2 KB
/
releases.go
File metadata and controls
157 lines (139 loc) · 4.2 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package cmd
import (
"fmt"
"strings"
"time"
"github.com/drycc/controller-sdk-go/releases"
)
// ReleasesList lists an app's releases.
func (d *DryccCmd) ReleasesList(appID, ptypes string, results int) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
if results == defaultLimit {
results = s.Limit
}
releases, count, err := releases.List(s.Client, appID, ptypes, results)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
if count == 0 {
d.Println(fmt.Sprintf("No releases found in %s app.", appID))
} else {
table := d.getDefaultFormatTable([]string{"OWNER", "STATE", "VERSION", "CREATED", "SUMMARY"})
for _, r := range releases {
summary := r.Summary
if len(summary) > 64 {
summary = fmt.Sprintf("%s[...]", summary[:64])
}
table.Append([]string{r.Owner, r.State, fmt.Sprintf("v%d", r.Version), d.formatTime(r.Created), summary})
}
table.Render()
}
return nil
}
// ReleasesInfo prints info about a specific release.
func (d *DryccCmd) ReleasesInfo(appID string, version int) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
r, err := releases.Get(s.Client, appID, version)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
table := d.getDefaultFormatTable([]string{})
table.Append([]string{"App:", r.App})
table.Append([]string{"UUID:", r.UUID})
table.Append([]string{"State:", r.State})
table.Append([]string{"Owner:", r.Owner})
table.Append([]string{"Build:", r.Build})
table.Append([]string{"Config:", r.Config})
table.Append([]string{"Created:", d.formatTime(r.Created)})
table.Append([]string{"Updated:", d.formatTime(r.Updated)})
table.Append([]string{"Summary:", d.wrapString(r.Summary)})
if r.Exception != "" {
table.Append([]string{"Exception:", d.wrapString(r.Exception)})
}
table.Append([]string{"Version:", fmt.Sprintf("v%v", r.Version)})
table.Render()
// Conditions
if len(r.Conditions) != 0 {
// table event
te := d.getDefaultFormatTable([]string{})
te.Append([]string{"Conditions:"})
for _, c := range r.Conditions {
ptypes := "<none>"
if len(c.Ptypes) != 0 {
ptypes = strings.Join(c.Ptypes, ",")
}
exception := "<none>"
if c.Exception != "" {
exception = c.Exception
}
te.Append([]string{d.indentString("- created:", 2), d.formatTime(c.Created)})
te.Append([]string{d.indentString("state:", 4), c.State})
te.Append([]string{d.indentString("action:", 4), c.Action})
te.Append([]string{d.indentString("ptypes:", 4), d.wrapString(ptypes)})
te.Append([]string{d.indentString("exception:", 4), d.wrapString(exception)})
}
te.Render()
}
return nil
}
// ReleasesDeploy force deploy lastest release.
func (d *DryccCmd) ReleasesDeploy(appID string, targets []string, force bool, confirm string) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
if len(targets) == 0 && (confirm == "" || confirm != "yes") {
d.Printf(` ! WARNING: Potentially Deploy Action
! This command will deploy all processes of the application ptype
! To proceed, type "yes" !
> `)
fmt.Scanln(&confirm)
if confirm != "yes" {
return fmt.Errorf("cancel the deploy action")
}
}
d.Printf("Deploying process types... but first, %s!\n", drinkOfChoice())
startTime := time.Now()
quit := progress(d.WOut)
ptypes := strings.Join(targets, ",")
targetMap := map[string]interface{}{
"ptypes": ptypes,
"force": force,
}
err = releases.Deploy(s.Client, appID, targetMap)
quit <- true
<-quit
if err != nil {
return err
}
d.Printf("done in %ds\n", int(time.Since(startTime).Seconds()))
return nil
}
// ReleasesRollback rolls an app back to a previous release.
func (d *DryccCmd) ReleasesRollback(appID string, targets []string, version int) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
ptypes := strings.Join(targets, ",")
if version == -1 {
d.Print("Rolling back one release... ")
} else {
d.Printf("Rolling back to v%d... ", version)
}
quit := progress(d.WOut)
newVersion, err := releases.Rollback(s.Client, appID, ptypes, version)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Printf("done, v%d\n", newVersion)
return nil
}