-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuilds.go
More file actions
127 lines (106 loc) · 3.36 KB
/
builds.go
File metadata and controls
127 lines (106 loc) · 3.36 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
package cmd
import (
"fmt"
"os"
yaml "gopkg.in/yaml.v3"
drycc "github.com/drycc/controller-sdk-go"
"github.com/drycc/controller-sdk-go/builds"
)
// BuildsInfo lists an app's builds.
func (d *DryccCmd) BuildsInfo(appID string, version int) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
build, err := builds.Get(s.Client, appID, version)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
table := d.getDefaultFormatTable([]string{})
table.Append([]string{"App:", build.App})
table.Append([]string{"Sha:", build.Sha})
table.Append([]string{"UUID:", build.UUID})
table.Append([]string{"Owner:", build.Owner})
table.Append([]string{"Image:", build.Image})
table.Append([]string{"Stack:", build.Stack})
table.Append([]string{"Created:", build.Created})
table.Append([]string{"Updated:", build.Updated})
table.Render()
if len(build.Dockerfile) != 0 {
table = d.getDefaultFormatTable([]string{})
table.Append([]string{"Dockerfile:"})
table.Append([]string{d.indentString(build.Dockerfile, 2)})
table.Render()
}
if len(build.Procfile) != 0 {
table = d.getDefaultFormatTable([]string{})
table.Append([]string{"Procfile:"})
table.Append([]string{d.indentString(d.toYamlString(build.Procfile, 2), 2)})
table.Render()
}
if len(build.Dryccfile) != 0 {
table = d.getDefaultFormatTable([]string{})
table.Append([]string{"Dryccfile:"})
table.Append([]string{d.indentString(d.toYamlString(build.Dryccfile, 2), 2)})
table.Render()
}
return nil
}
// BuildsCreate creates a build for an app.
func (d *DryccCmd) BuildsCreate(appID, image, stack, procfile, dryccpath, confirm 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 info, err := os.Stat(dryccpath); err == nil && info.IsDir() {
if dryccfileMap, err = drycc.ParseDryccfile(dryccpath); err != nil {
return err
}
}
// check procfileMap dryccfileMap stack is exist
err = buildConfirmAction(s.Client, appID, procfileMap, dryccfileMap, confirm)
if 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 buildConfirmAction(c *drycc.Client, appID string, procfileMap map[string]string,
dryccfileMap map[string]interface{}, confirm string) error {
build, _ := builds.Get(c, appID, 0)
if ((len(build.Procfile) != 0 && len(procfileMap) == 0) || (len(build.Dryccfile) != 0 && len(dryccfileMap) == 0)) && (confirm == "" || confirm != "yes") {
// hint
fmt.Printf(` ! WARNING: Potentially Build Create Action
! The Procfile or drycc file is empty, not last time
! To proceed, type "yes" !
> `)
fmt.Scanln(&confirm)
if confirm != "yes" {
return fmt.Errorf("cancel the build create action")
}
}
return nil
}