-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuilds.go
More file actions
98 lines (80 loc) · 2.12 KB
/
builds.go
File metadata and controls
98 lines (80 loc) · 2.12 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
package cmd
import (
"fmt"
"os"
yaml "gopkg.in/yaml.v3"
"github.com/drycc/controller-sdk-go/builds"
)
// BuildsList lists an app's builds.
func (d *DryccCmd) BuildsList(appID string, results int) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
if results == defaultLimit {
results = s.Limit
}
builds, count, err := builds.List(s.Client, appID, results)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
if count > 0 {
table := d.getDefaultFormatTable([]string{"OWNER", "SHA", "CREATED"})
for _, build := range builds {
table.Append([]string{
safeGetString(build.Owner),
safeGetString(build.Sha),
d.formatTime(build.Created),
})
}
table.Render()
} else {
d.Println(fmt.Sprintf("No builds found in %s app.", appID))
}
return nil
}
// BuildsCreate creates a build for an app.
func (d *DryccCmd) BuildsCreate(appID, image, stack, procfile string, dryccfile string) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
procfileMap := make(map[string]string)
if _, err := os.Stat(procfile); err == nil {
contents, err := os.ReadFile(procfile)
if err != nil {
return err
}
if procfileMap, err = parseProcfile(contents); err != nil {
return err
}
}
dryccfileMap := make(map[string]interface{})
if _, err := os.Stat(dryccfile); err == nil {
contents, err := os.ReadFile(dryccfile)
if err != nil {
return err
}
if dryccfileMap, err = parseDryccfile(contents); err != nil {
return err
}
}
d.Print("Creating build... ")
quit := progress(d.WOut)
_, err = builds.New(s.Client, appID, image, stack, procfileMap, dryccfileMap)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}
func parseProcfile(procfile []byte) (map[string]string, error) {
procfileMap := make(map[string]string)
return procfileMap, yaml.Unmarshal(procfile, &procfileMap)
}
func parseDryccfile(dryccfile []byte) (map[string]interface{}, error) {
dryccfileMap := make(map[string]interface{})
return dryccfileMap, yaml.Unmarshal(dryccfile, &dryccfileMap)
}