This repository has been archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.go
76 lines (66 loc) · 2.3 KB
/
deploy.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
package main
import (
"github.com/serverlessworkflow/sdk-go/model"
log "github.com/sirupsen/logrus"
"io/ioutil"
"os"
"strings"
)
const (
kogitoInstallKnativeBrokerCmdF = "install infra kogito-knative --apiVersion eventing.knative.dev/v1 --kind Broker --resource-name default"
defaultDataPath = "/home/kogito/data"
regularProjectTemplatePath = "/projects_template/regular-sw"
eventsProjectTemplatePath = "/projects_template/events-sw"
resourcesPath = "/src/main/resources"
knativeResourcesPath = "/knative"
workflowFileSuffix = ".sw.json"
// exposed via Kubernetes pod
envKeyNamespace = "DEPLOY_NAMESPACE"
envKeyDataPath = "PROJECTS_DATA_PATH"
)
func deploy(workflow model.Workflow, workflowFile []byte) error {
namespace := os.Getenv(envKeyNamespace)
projectTemplate := regularProjectTemplatePath
if err := execCmd("oc", "project", namespace); err != nil {
log.Error("Failed to set namespace", err)
return err
}
if len(workflow.Events) > 0 {
projectTemplate = eventsProjectTemplatePath
if err := deployEventsInfra(namespace); err != nil {
return err
}
}
if err := ioutil.WriteFile(getWorkflowFilePath(workflow, projectTemplate), workflowFile, 0644); err != nil {
log.Error("Failed to write Workflow file in project's path", err)
return err
}
if err := execCmd("kogito", "deploy", workflow.ID, getDataPath()+projectTemplate); err != nil {
log.Error("Failed to deploy Kogito service in the target cluster", err)
return err
}
return nil
}
func deployEventsInfra(namespace string) error {
// apply the knative broker
if err := execCmd("oc", "apply", "-f", getDataPath()+knativeResourcesPath, "-n", namespace); err != nil {
log.Error("Failed create Knative Eventing broker", err)
return err
}
// installs kogito infra that uses the same broker
if err := execCmd("kogito", strings.Split(kogitoInstallKnativeBrokerCmdF, " ")...); err != nil {
log.Error("Failed create Kogito Infra abstraction for Knative Broker", err)
return err
}
return nil
}
func getWorkflowFilePath(workflow model.Workflow, projectPath string) string {
return getDataPath() + projectPath + resourcesPath + "/" + workflow.ID + workflowFileSuffix
}
func getDataPath() string {
dataPath := os.Getenv(envKeyDataPath)
if len(dataPath) == 0 {
dataPath = defaultDataPath
}
return dataPath
}