-
Notifications
You must be signed in to change notification settings - Fork 2
/
KubernetesApplication.groovy
247 lines (197 loc) · 7.15 KB
/
KubernetesApplication.groovy
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
CloudBees Flow DSL: Application Model illustrating Kubernetes deployments
Creates
- Environment models with attached kubectl context names
- Resources pointing to the same machine as 'local'
- Application models with a single image to be deployed
Actions supported
- Kubernetes deploy
- Kubernetes undeploy
- Flow environment inventory updated with image version
Dependencies
- kubectl installed
- kubectl config context with the same name as the Flow environments
- Github configuration
- Yaml file stored in github
Notes on running the Model
- Artifact staging must be unselected for Deployment
*/
def proj = 'Kubernetes Example'
def app = 'Kubernetes App'
def image_name = 'nginx'
def image_version = '1.7.9'
def yaml_file = 'demoNginx.yaml'
def yaml_repo = 'https://github.com/gmaxey/KubeDemoApp.git'
def github_config = "Greg's RO github"
def kubectl_path = "/opt/google-cloud-sdk/bin/kubectl"
def envs = ["dev","qa","preprod"]
def tier = 'App Tier'
def hostName = getResource(resourceName: "local").hostName
/*
The above may return 127.0.0.1 which might fail because localhost is already set to REGISTERED use
hostName = "localhost"
as a workaround
*/
def Zone = "zone2"
zone Zone
/*
There's a problem with zones on the Thunder demo instance. The above is a workaround
*/
project proj,{
envs.each { env ->
environment env, {
environmentTier tier, {
resource "${app}_${env}_${tier}", hostName: hostName,
zoneName: Zone // Workaround
}
// Custom properties
property "context", value: env
}
}
application app, {
applicationTier tier, {
component image_name, pluginName: null, {
pluginKey = 'EC-Artifact'
process 'Install', {
applicationName = null
processType = 'DEPLOY'
processStep 'Create Artifact Placeholder', {
actualParameter = [
'commandToRun': 'artifact artifactKey: "$[/myComponent/ec_content_details/artifactName]", groupId: "group"',
'shellToUse': 'ectool evalDsl --dslFile',
]
applicationTierName = null
processStepType = 'command'
subprocedure = 'RunCommand'
subproject = '/plugins/EC-Core/project'
}
processStep 'Get yaml deploy file(s)', {
actualParameter = [
'clone': '1',
'config': github_config,
dest: '$[/myComponent/image_name]',
'GitRepo': '$[/myComponent/yaml_repo]',
'overwrite': '0',
'tag': '',
]
processStepType = 'plugin'
subprocedure = 'CheckoutCode'
subproject = '/plugins/ECSCM-Git/project'
}
processStep 'Undeploy any existing', {
actualParameter = [
commandToRun: """\
$kubectl_path config use-context \$[/myEnvironment/context]
sed 's/image: .*/image: \$[/myComponent/image_name]/' \$[/myComponent/image_name]/\$[/myComponent/yaml_file] | $kubectl_path delete -f - || echo ok
""".stripIndent(),
]
applicationTierName = null
processStepType = 'command'
subprocedure = 'RunCommand'
subproject = '/plugins/EC-Core/project'
}
processStep 'Deploy', {
actualParameter = [
commandToRun: """\
$kubectl_path config use-context \$[/myEnvironment/context]
sed 's/image: .*/image: \$[/myComponent/image_name]:\$[\$[/myComponent/componentName]_version]/' \$[/myComponent/image_name]/\$[/myComponent/yaml_file] | $kubectl_path create -f -
""".stripIndent(),
]
applicationTierName = null
processStepType = 'command'
subprocedure = 'RunCommand'
subproject = '/plugins/EC-Core/project'
}
processDependency 'Create Artifact Placeholder', targetProcessStepName: 'Get yaml deploy file(s)'
processDependency 'Undeploy any existing', targetProcessStepName: 'Deploy'
processDependency 'Get yaml deploy file(s)', targetProcessStepName: 'Undeploy any existing'
}
process 'Uninstall', {
applicationName = null
processType = 'UNDEPLOY'
processStep 'Get yaml deploy file(s)', {
actualParameter = [
'clone': '1',
'config': github_config,
dest: '$[/myComponent/image_name]',
'GitRepo': '$[/myComponent/yaml_repo]',
'overwrite': '0',
'tag': '',
]
processStepType = 'plugin'
subprocedure = 'CheckoutCode'
subproject = '/plugins/ECSCM-Git/project'
}
processStep 'Uninstall', {
actualParameter = [
commandToRun: """\
$kubectl_path config use-context \$[/myEnvironment/context]
sed 's/image: .*/image: \$[/myComponent/image_name]/' \$[/myComponent/image_name]/\$[/myComponent/yaml_file] | $kubectl_path delete -f - || echo ok
""".stripIndent(),
]
applicationTierName = null
processStepType = 'command'
subprocedure = 'RunCommand'
subproject = '/plugins/EC-Core/project'
}
processDependency 'Get yaml deploy file(s)', targetProcessStepName: 'Uninstall'
}
// Custom properties
property 'ec_content_details', {
property 'artifactName', value: image_name, {
}
artifactVersionLocationProperty = '/myJob/retrievedArtifactVersions/$[assignedResourceName]'
property 'overwrite', value: 'update'
pluginProcedure = 'Retrieve'
property 'pluginProjectName', value: 'EC-Artifact'
retrieveToDirectory = ''
property 'versionRange', value: "\$[${image_name}_version]"
}
property "image_name", value: image_name
property "yaml_file", value: yaml_file
property "yaml_repo", value: yaml_repo
}
}
process 'Deploy', {
processType = "OTHER"
formalParameter "ec_enforceDependencies", defaultValue: '0'
formalParameter "ec_${image_name}-run", defaultValue: '1'
formalParameter "ec_${image_name}-version", defaultValue: "\$[/projects/${projectName}/applications/${applicationName}/components/${image_name}/ec_content_details/versionRange]", expansionDeferred: '1'
formalParameter 'ec_smartDeployOption', defaultValue: '0'
formalParameter 'ec_stageArtifacts', defaultValue: '0'
formalParameter "${image_name}_version", defaultValue: image_version
processStep image_name, {
applicationTierName = tier
processStepType = 'process'
subcomponent = image_name
subcomponentApplicationName = applicationName
subcomponentProcess = 'Install'
}
}
process 'Undeploy', {
processType = 'OTHER'
formalParameter "ec_enforceDependencies", defaultValue: '0'
formalParameter "ec_${image_name}-run", defaultValue: '1'
formalParameter "ec_${image_name}-version", defaultValue: "\$[/projects/${projectName}/applications/${applicationName}/components/${image_name}/ec_content_details/versionRange]", expansionDeferred: '1'
formalParameter 'ec_smartDeployOption', defaultValue: '1'
formalParameter 'ec_stageArtifacts', defaultValue: '0'
processStep image_name, {
applicationTierName = tier
processStepType = 'process'
subcomponent = image_name
subcomponentApplicationName = applicationName
subcomponentProcess = 'Uninstall'
}
}
envs.each { env ->
tierMap env, {
environmentName = env
environmentProjectName = projectName
tierMapping "${tier}_${env}", {
applicationTierName = tier
environmentTierName = tier
}
}
}
}
}