This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
/
application.go
88 lines (70 loc) · 2.51 KB
/
application.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
package actions
import (
"fmt"
"github.com/AlexsJones/gravitywell/configuration"
"github.com/AlexsJones/gravitywell/kinds"
"github.com/AlexsJones/gravitywell/shared"
"github.com/AlexsJones/gravitywell/vcs"
logger "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"io/ioutil"
"strings"
)
func ApplicationProcessor(commandFlag configuration.CommandFlag,
opt configuration.Options, clusterName string, application kinds.Application) {
executeDeployment(application, opt, clusterName, commandFlag)
}
func loadActionList(path string) kinds.ActionList {
logger.Info(fmt.Sprintf("Loading %s", path))
bytes, err := ioutil.ReadFile(path)
if err != nil {
logger.Error(err)
}
appc := kinds.ActionList{}
err = yaml.Unmarshal(bytes, &appc)
if err != nil {
logger.Error(err)
}
return appc
}
func selectAndExecute(execute kinds.Execute, deployment kinds.Application, opt configuration.Options,
clusterName string, commandFlag configuration.CommandFlag, repoName string) {
if execute.Kind == "" {
fmt.Printf(shared.PrettyPrint(deployment))
logger.Fatalf(fmt.Sprintf("kind missing from execute block: (Check file indentation)[%s][%s]",
deployment.VCS.Git, clusterName))
}
if execute.Configuration == nil {
logger.Fatal("Configuration is missing within Execute block")
}
switch strings.ToLower(execute.Kind) {
case "shell":
ExecuteShellAction(execute, opt, repoName)
case "kubernetes":
ExecuteKubernetesAction(execute, clusterName, deployment, commandFlag, opt, repoName)
case "runactionlist":
tp, ok := execute.Configuration["Path"]
if !ok {
logger.Error("Could not find RunActionList Path")
return
}
al := loadActionList(tp)
executeActionList(al, deployment, opt, clusterName, commandFlag, repoName)
}
}
func executeActionList(actionList kinds.ActionList, deployment kinds.Application, opt configuration.Options,
clusterName string, commandFlag configuration.CommandFlag, remoteVCSRepoName string) {
for _, a := range actionList.Executions {
selectAndExecute(a, deployment, opt, clusterName, commandFlag, remoteVCSRepoName)
}
}
func executeDeployment(deployment kinds.Application, opt configuration.Options,
clusterName string, commandFlag configuration.CommandFlag) {
logger.Info(fmt.Sprintf("Loading deployment %s\n", deployment.Name))
remoteVCSRepoName, err := vcs.FetchRepo(deployment.VCS.Git, deployment.VCS.GitReference, opt)
if err != nil {
logger.Error(err.Error())
return
}
executeActionList(deployment.ActionList, deployment, opt, clusterName, commandFlag, remoteVCSRepoName)
}