forked from radu-matei/vscode-draft-remote-debug-samples
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbrigade.js
More file actions
118 lines (100 loc) · 4.09 KB
/
brigade.js
File metadata and controls
118 lines (100 loc) · 4.09 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
const { events, Job, Group } = require('brigadier')
events.on("push", (brigadeEvent, project) => {
// variables from the Github push
var dockerId = project.secrets.registryUrl
var dockerPwd = project.secrets.registryPassword
var gitPayload = JSON.parse(brigadeEvent.payload)
var image = "squillace/golang"
var gitSHA = brigadeEvent.revision.commit.substr(0,7)
var imageTag = String(gitSHA)
console.log("ID: " + dockerId)
console.log("Password: " + dockerPwd)
console.log(`==> gitHub webook with commit ID ${gitSHA}`)
// Let's notice the event
var slackJob = new Job("slack-notify-github-push", "technosophos/slack-notify:latest", ["/slack-notify"])
slackJob.storage.enabled = false
slackJob.env = {
SLACK_WEBHOOK: project.secrets.slackWebhook,
SLACK_USERNAME: "brigade-demo",
SLACK_MESSAGE: "Detected a git push on " + image + " with commit hash " + imageTag,
SLACK_COLOR: "#0000ff"
}
// setup container build brigade job
var docker = new Job("job-runner-docker")
docker.storage.enabled = false
docker.privileged = true
docker.image = "chzbrgr71/dockernd:golang"
docker.tasks = [
"dockerd-entrypoint.sh &",
"echo waiting && sleep 20",
`cd /src/golang/`,
`docker login -u ${dockerId} -p ${dockerPwd}`,
`docker build -t ${image}:${imageTag} .`,
`docker push ${image}:${imageTag}`,
"killall dockerd"
]
// Let's notice the event and test someting after the build.
var slackJobTest1 = new Job("slack-notify-image-built", "technosophos/slack-notify:latest", ["/slack-notify"])
slackJobTest1.storage.enabled = false
slackJobTest1.env = {
SLACK_WEBHOOK: project.secrets.slackWebhook,
SLACK_USERNAME: "brigade-demo",
SLACK_MESSAGE: "Docker build successful; running image test 1 ...",
SLACK_COLOR: "#0000ff"
}
// Let's notice the event and test someting after the build.
var slackJobTest2 = new Job("slack-notify-test", "technosophos/slack-notify:latest", ["/slack-notify"])
slackJobTest2.storage.enabled = false
slackJobTest2.env = {
SLACK_WEBHOOK: project.secrets.slackWebhook,
SLACK_USERNAME: "brigade-demo",
SLACK_MESSAGE: "Running container image test ...",
SLACK_COLOR: "#0000ff"
}
// Let's notice the event and test someting after the build.
var slackJobTest3 = new Job("slack-notify-test-again", "technosophos/slack-notify:latest", ["/slack-notify"])
slackJobTest3.storage.enabled = false
slackJobTest3.env = {
SLACK_WEBHOOK: project.secrets.slackWebhook,
SLACK_USERNAME: "brigade-demo",
SLACK_MESSAGE: "Test completed successfully. Deploying to Production...",
SLACK_COLOR: "#0000ff"
}
// brigade job. Helm chart
var helm = new Job("job-runner-helm")
helm.storage.enabled = false
helm.image = "lachlanevenson/k8s-helm:v2.8.2"
helm.tasks = [
`helm upgrade --install --reuse-values golang-prod ./src/golang/charts/go-prod --set image.repository=${image} --set image.tag=${imageTag} --namespace=default`
]
var pipeline = new Group()
pipeline.add(slackJob)
pipeline.add(docker)
pipeline.add(slackJobTest1)
pipeline.add(slackJobTest2)
pipeline.add(helm)
pipeline.runEach()
})
events.on("after", (event, project) => {
var slack = new Job("slack-notify-after", "technosophos/slack-notify:latest", ["/slack-notify"])
slack.storage.enabled = false
slack.env = {
SLACK_WEBHOOK: project.secrets.slackWebhook,
SLACK_USERNAME: "brigade-demo",
SLACK_MESSAGE: "Brigade pipeline finished",
SLACK_COLOR: "#0000ff"
}
slack.run()
})
events.on("error", (event, project) => {
console.log(" **** ERROR EVENT called")
var slack = new Job("slack-notify-error", "technosophos/slack-notify:latest", ["/slack-notify"])
slack.storage.enabled = false
slack.env = {
SLACK_WEBHOOK: project.secrets.slackWebhook,
SLACK_USERNAME: "brigade-demo",
SLACK_MESSAGE: "An error occurred. ",
SLACK_COLOR: "#0000ff"
}
slack.run()
})