-
Notifications
You must be signed in to change notification settings - Fork 19
/
models.go
96 lines (84 loc) · 3.2 KB
/
models.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
package buildpackapplifecycle
import (
"strings"
)
const (
DetectFailMsg = "None of the buildpacks detected a compatible application"
CompileFailMsg = "Failed to compile droplet"
ReleaseFailMsg = "Failed to build droplet release"
SupplyFailMsg = "Failed to run all supply scripts"
NoSupplyScriptFailMsg = "Error: one of the buildpacks chosen to supply dependencies does not support multi-buildpack apps"
MissingFinalizeWarnMsg = "Warning: the last buildpack is not compatible with multi-buildpack apps and cannot make use of any dependencies supplied by the buildpacks specified before it"
FinalizeFailMsg = "Failed to run finalize script"
DETECT_FAIL_CODE = 222
COMPILE_FAIL_CODE = 223
RELEASE_FAIL_CODE = 224
SUPPLY_FAIL_CODE = 225
FINALIZE_FAIL_CODE = 226
)
func ExitCodeFromError(err error) int {
errMsg := err.Error()
switch {
case strings.Contains(errMsg, DetectFailMsg):
return DETECT_FAIL_CODE
case strings.Contains(errMsg, CompileFailMsg):
return COMPILE_FAIL_CODE
case strings.Contains(errMsg, ReleaseFailMsg):
return RELEASE_FAIL_CODE
case strings.Contains(errMsg, SupplyFailMsg):
return SUPPLY_FAIL_CODE
case strings.Contains(errMsg, NoSupplyScriptFailMsg):
return SUPPLY_FAIL_CODE
case strings.Contains(errMsg, FinalizeFailMsg):
return FINALIZE_FAIL_CODE
default:
return 1
}
}
type LifecycleMetadata struct {
BuildpackKey string `json:"buildpack_key,omitempty"`
DetectedBuildpack string `json:"detected_buildpack"`
Buildpacks []BuildpackMetadata `json:"buildpacks"`
}
type BuildpackMetadata struct {
Key string `json:"key" yaml:"key"`
Name string `json:"name" yaml:"name"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Config *BuildpackConfig `json:"config,omitempty" yaml:"config,omitempty"`
}
type BuildpackConfig struct {
EntrypointPrefix string `json:"entrypoint_prefix,omitempty" yaml:"entrypoint_prefix,omitempty"`
}
type ProcessTypes map[string]string
type Sidecar struct {
Name string `yaml:"name" json:"name"`
ProcessTypes []string `yaml:"process_types" json:"process_types"`
Command string `yaml:"command" json:"command"`
Memory int `yaml:"memory,omitempty" json:"memory,omitempty"`
}
type Process struct {
Type string `yaml:"type" json:"type"`
Command string `yaml:"command" json:"command"`
}
type StagingResult struct {
LifecycleMetadata `json:"lifecycle_metadata"`
ProcessTypes `json:"process_types"`
ProcessList []Process `json:"processes,omitempty"`
Sidecars []Sidecar `json:"sidecars,omitempty"`
ExecutionMetadata string `json:"execution_metadata"`
LifecycleType string `json:"lifecycle_type"`
}
func UpdateStagingResult(result StagingResult, lifeMeta LifecycleMetadata) StagingResult {
result.LifecycleMetadata = lifeMeta
result.LifecycleType = "buildpack"
result.ExecutionMetadata = ""
return result
}
func NewStagingResult(procTypes ProcessTypes, lifeMeta LifecycleMetadata) StagingResult {
return StagingResult{
LifecycleType: "buildpack",
LifecycleMetadata: lifeMeta,
ProcessTypes: procTypes,
ExecutionMetadata: "",
}
}