-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
120 lines (100 loc) · 4.28 KB
/
Jenkinsfile
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
119
120
library(
identifier: '[email protected]',
retriever: modernSCM([$class: 'GitSCMSource',
remote: 'https://github.com/SmartColumbusOS/pipeline-lib',
credentialsId: 'jenkins-github-user'])
)
properties([
pipelineTriggers([scos.dailyBuildTrigger('12-13')]), //UTC
])
def image
def doStageIf = scos.&doStageIf
def doStageIfRelease = doStageIf.curry(scos.changeset.isRelease)
def doStageUnlessRelease = doStageIf.curry(!scos.changeset.isRelease)
def doStageIfPromoted = doStageIf.curry(scos.changeset.isMaster)
node('infrastructure') {
ansiColor('xterm') {
scos.doCheckoutStage()
doStageUnlessRelease('Build') {
image = docker.build("scos/cota-streaming-ui:${env.GIT_COMMIT_HASH}")
}
doStageUnlessRelease('Deploy to Dev') {
scos.withDockerRegistry {
image.push()
image.push('latest')
}
deployUiTo(environment: 'dev')
runSmokeTestAgainst('dev')
}
doStageIfPromoted('Deploy to Staging') {
def environment = 'staging'
deployUiTo(environment: environment)
runSmokeTestAgainst(environment)
scos.applyAndPushGitHubTag(environment)
scos.withDockerRegistry {
image.push(environment)
}
}
doStageIfRelease('Deploy to Production') {
def releaseTag = env.BRANCH_NAME
def promotionTag = 'prod'
deployUiTo(environment: 'prod', internal: false)
runSmokeTestAgainst('prod')
scos.applyAndPushGitHubTag(promotionTag)
scos.withDockerRegistry {
image = scos.pullImageFromDockerRegistry("scos/cota-streaming-ui", env.GIT_COMMIT_HASH)
image.push(releaseTag)
image.push(promotionTag)
}
}
}
}
def deployUiTo(params = [:]) {
def environment = params.get('environment')
if (environment == null) throw new IllegalArgumentException("environment must be specified")
def internal = params.get('internal', true)
scos.withEksCredentials(environment) {
def terraformOutputs = scos.terraformOutput(environment)
def subnets = terraformOutputs.public_subnets.value.join(/\\,/)
def allowInboundTrafficSG = terraformOutputs.allow_all_security_group.value
def certificateARNs = [terraformOutputs.root_tls_certificate_arn.value,terraformOutputs.tls_certificate_arn.value].join(/\\,/)
def ingressScheme = internal ? 'internal' : 'internet-facing'
def dnsZone = terraformOutputs.internal_dns_zone_name.value
def rootDnsZone = terraformOutputs.root_dns_zone_name.value
def wafARN = terraformOutputs.eks_cluster_waf_acl_arn.value
sh("""#!/bin/bash
set -e
helm upgrade --install cota-streaming-ui ./chart \
--namespace cota-services \
--set env="${environment}" \
--namespace=cota-services \
--set ingress.enabled="true" \
--set ingress.scheme="${ingressScheme}" \
--set ingress.subnets="${subnets}" \
--set ingress.securityGroups="${allowInboundTrafficSG}" \
--set ingress.dnsZone="${dnsZone}" \
--set ingress.rootDnsZone="${rootDnsZone}" \
--set ingress.certificateARN="${certificateARNs}" \
--set ingress.wafARN="${wafARN}" \
--set image.tag="${env.GIT_COMMIT_HASH}"
""".trim())
}
}
def runSmokeTestAgainst(environment) {
dir('smoke-test') {
def smoker = docker.build("cota-smoke-test")
//TODO: change this to use terraform output root_dns_zone_name. Currently there is a bug with terraform and the prod dns has a . on the end
def envUrlMap = [
"dev": "dev-smartos.com",
"staging": "staging-smartos.com",
"prod": "smartcolumbusos.com"
]
retry(60) {
sleep(time: 5, unit: 'SECONDS')
smoker.withRun("-e ENDPOINT_URL=cota.${envUrlMap[environment]}") { container ->
sh "docker logs -f ${container.id}"
sh "exit \$(docker inspect ${container.id} --format='{{.State.ExitCode}}')"
}
}
}
}