-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild_type.go
More file actions
77 lines (67 loc) · 1.62 KB
/
build_type.go
File metadata and controls
77 lines (67 loc) · 1.62 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
package gitreceive
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/drycc/controller-sdk-go/api"
"github.com/drycc/pkg/log"
)
// defaultStacks is default stacks json, order represents priority
var defaultStacks = `[
{
"name": "buildpack",
"image": "drycc/imagebuilder:canary"
},
{
"name": "container",
"image": "drycc/imagebuilder:canary"
}
]`
// Stacks for drycc
var Stacks []map[string]string
// initStack load stack by config
func initStack() error {
data, err := ioutil.ReadFile("/etc/imagebuilder/images.json")
if err == nil {
return json.Unmarshal(data, &Stacks)
}
return json.Unmarshal([]byte(defaultStacks), &Stacks)
}
func getStack(dirName string, config api.Config) map[string]string {
if len(Stacks) == 0 {
initStack()
}
log.Debug("Stacks: %s", Stacks)
log.Debug("Config values %s", config.Values)
if stackInterface, ok := config.Values["DRYCC_STACK"]; ok {
if strStack, ok := stackInterface.(string); ok {
for _, stack := range Stacks {
if stack["name"] == strStack {
return stack
}
}
}
}
if _, err := os.Stat(fmt.Sprintf("%s/Dockerfile", dirName)); err == nil {
for _, stack := range Stacks {
if stack["name"] == "container" {
return stack
}
}
}
if _, err := os.Stat(fmt.Sprintf("%s/Procfile", dirName)); err == nil {
for _, stack := range Stacks {
if stack["name"] == "buildpack" {
return stack
}
}
} else if _, err := os.Stat(fmt.Sprintf("%s/project.toml", dirName)); err == nil {
for _, stack := range Stacks {
if stack["name"] == "buildpack" {
return stack
}
}
}
return Stacks[0]
}