forked from rackerlabs/poppy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
267 lines (265 loc) · 11.1 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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
pipeline {
agent any
environment {
OS_TEST_PATH = "$WORKSPACE/tests/functional"
OS_LOG_PATH = "$WORKSPACE/.logs"
}
options {
disableConcurrentBuilds()
}
stages {
stage('poppy_venv') {
steps {
slackSend (color: '#ffe100', message: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
echo "Setup poppy_venv and install deps"
sh 'if [ -d poppy_venv/ ]; then rm -rf poppy_venv; fi'
sh 'if [ -d ~/base_poppy_venv ]; then virtualenv-clone ~/base_poppy_venv poppy_venv; else virtualenv poppy_venv; fi'
sh '''. poppy_venv/bin/activate && if [ $(pip -V | awk '{print $2}') != "19.0.3" ]; then curl -s https://bootstrap.pypa.io/get-pip.py | python - "pip==19.0.3"; fi'''
sh '. poppy_venv/bin/activate && pip install --find-links=~/wheels -U wheel setuptools testrepository'
sh '. poppy_venv/bin/activate && pip install --find-links=~/wheels -r requirements/requirements.txt'
sh '#if [ ! -d ~/base_poppy_venv ]; then virtualenv-clone poppy_venv ~/base_poppy_venv; fi'
}
}
stage('poppy_tests_venv') {
steps {
echo "Setup poppy_tests_venv and install deps"
sh 'if [ -d poppy_tests_venv/ ]; then rm -rf poppy_tests_venv; fi'
sh 'if [ -d ~/base_poppy_tests_venv ]; then virtualenv-clone ~/base_poppy_tests_venv poppy_tests_venv; else virtualenv-clone poppy_venv poppy_tests_venv; fi'
sh '. poppy_tests_venv/bin/activate && pip install --find-links=~/wheels -r tests/test-requirements.txt'
sh '#if [ ! -d ~/base_poppy_tests_venv ]; then virtualenv-clone poppy_tests_venv ~/base_poppy_tests_venv; fi'
sh '. poppy_tests_venv/bin/activate && python setup.py install'
}
}
stage('Run Tests') {
parallel {
stage('PyLint') {
steps {
sh '''
echo "Pylint tests are temporarily disabled"
#. poppy_tests_venv/bin/activate
# pycodestyle --max-line-length=119 --statistics --first
'''
}
}
stage('Unit') {
steps {
sh '''
echo "Unit tests are temporarily disabled"
#. poppy_tests_venv/bin/activate
#nosetests --with-coverage --cover-package=poppy --with-xunit --xunit-file=unit-tests.xml tests/unit
'''
}
post {
always {
echo "junit 'unit-tests.xml' is currently disabled"
}
}
}
stage('Functional') {
steps {
sh '''
echo "Functional tests are temporarily disabled"
#. poppy_tests_venv/bin/activate
#nosetests --with-coverage --cover-package=poppy --with-xunit --xunit-file=functional-tests.xml tests/functional
'''
}
post {
always {
echo "junit 'functional-tests.xml' is currently disabled"
}
}
}
}
}
stage('PyPI Preview') {
when { anyOf { branch 'pre-release'; branch 'release' } }
steps {
sh '''
echo "Build and Upload PREVIEW Wheel for $BRANCH_NAME"
. poppy_venv/bin/activate
rm -rf dist
PBR_VERSION=2019.4.101 python setup.py bdist_wheel upload -v -r prev
'''
}
}
stage('PyPI Production') {
when { branch 'release' }
steps {
echo "Build and Upload PROD Wheel for $BRANCH_NAME"
sh '''
. poppy_venv/bin/activate
rm -rf dist
PBR_VERSION=2019.3.${BUILD_NUMBER} python setup.py bdist_wheel upload -v -r prod
'''
}
}
stage('Deploy Prev IAD') {
when { anyOf { branch 'pre-release'; branch 'release' } }
steps {
echo "Create backup of poppy installation and config"
sh '''
ssh [email protected] 'sudo salt -v pwkr?a-ccv-iad cmd.run "bash backup_poppy.sh"'
ssh [email protected] 'sudo salt -v cdn?a-ccv-iad cmd.run "bash backup_poppy.sh"'
'''
echo "start deploy poppy workers"
sh 'ssh [email protected] "bash preview-deploy-pwkr.sh"'
echo "start deploy poppy servers"
sh 'ssh [email protected] "bash preview-deploy-cdn.sh"'
}
}
stage('Prev API Check') {
when { anyOf { branch 'pre-release'; branch 'release' } }
steps {
sh 'sleep 5'
sh 'nc -zv preview.cdn.api.rackspacecloud.com 443'
}
}
stage('Deploy Prod HKG') {
when {
beforeInput true
branch 'release'
}
input {
message "Should we deploy to Prod HKG?"
ok "Register HKG Choice"
parameters {
string(name: 'DEPLOY_HKG', defaultValue: 'FALSE', description: 'Enter TRUE to deploy, leave FALSE to skip.')
}
}
steps {
echo "Create backup of poppy installation and config"
sh '''
if [ $DEPLOY_HKG = "TRUE" ]; then
ssh [email protected] 'sudo salt -v pwkr?a-ccp-hkg cmd.run "bash backup_poppy.sh"'
ssh [email protected] 'sudo salt -v cdn?a-ccp-hkg cmd.run "bash backup_poppy.sh"'
fi
'''
echo "start deploy poppy workers"
sh '''
if [ $DEPLOY_HKG = "TRUE" ]; then
ssh [email protected] 'sudo salt -v pwkr?a-ccp-hkg state.sls poppy_worker cdn-prod-hkg'
fi
'''
echo "start deploy poppy servers"
sh '''
if [ $DEPLOY_HKG = "TRUE" ]; then
ssh [email protected] 'sudo salt -v cdn?a-ccp-hkg state.sls poppy_server cdn-prod-hkg'
fi
'''
}
}
stage('Deploy Prod LON') {
when {
beforeInput true
branch 'release'
}
input {
message "Should we deploy to Prod LON?"
ok "Register LON Choice"
parameters {
string(name: 'DEPLOY_LON', defaultValue: 'FALSE', description: 'Enter TRUE to deploy, leave FALSE to skip.')
}
}
steps {
echo "Create backup of poppy installation and config"
sh '''
if [ $DEPLOY_LON = "TRUE" ]; then
ssh [email protected] 'sudo salt -v pwkr?a-ccp-lon cmd.run "bash backup_poppy.sh"'
ssh [email protected] 'sudo salt -v cdn?a-ccp-lon cmd.run "bash backup_poppy.sh"'
fi
'''
echo "start deploy poppy workers"
sh '''
if [ $DEPLOY_LON = "TRUE" ]; then
ssh [email protected] 'sudo salt -v pwkr?a-ccp-lon state.sls poppy_worker cdn-prod-lon'
fi
'''
echo "start deploy poppy servers"
sh '''
if [ $DEPLOY_LON = "TRUE" ]; then
ssh [email protected] 'sudo salt -v cdn?a-ccp-lon state.sls poppy_server cdn-prod-lon'
fi
'''
}
}
stage('Deploy Prod IAD') {
when {
beforeInput true
branch 'release'
}
input {
message "Should we deploy to Prod IAD?"
ok "Register IAD Choice"
parameters {
string(name: 'DEPLOY_IAD', defaultValue: 'FALSE', description: 'Enter TRUE to deploy, leave FALSE to skip.')
}
}
steps {
echo "Create backup of poppy installation and config"
sh '''
if [ $DEPLOY_IAD = "TRUE" ]; then
ssh [email protected] 'sudo salt -v pwkr?a-ccp-iad cmd.run "bash backup_poppy.sh"'
ssh [email protected] 'sudo salt -v cdn?a-ccp-iad cmd.run "bash backup_poppy.sh"'
fi
'''
echo "start deploy poppy workers"
sh '''
if [ $DEPLOY_IAD = "TRUE" ]; then
ssh [email protected] 'sudo salt -v pwkr?a-ccp-iad state.sls poppy_worker cdn-prod-iad'
fi
'''
echo "start deploy poppy servers"
sh '''
if [ $DEPLOY_IAD = "TRUE" ]; then
ssh [email protected] 'sudo salt -v cdn?a-ccp-iad state.sls poppy_server cdn-prod-iad'
fi
'''
}
}
stage('Prod API Check') {
parallel {
stage('Prod Global') {
when { branch 'release' }
steps {
sh 'sleep 5'
sh 'nc -zv global.cdn.api.rackspacecloud.com 443'
}
}
stage('Prod HKG LB') {
when { branch 'release' }
steps {
sh 'sleep 5'
sh 'nc -zv 119.9.70.202 443'
}
}
stage('Prod LON LB') {
when { branch 'release' }
steps {
sh 'sleep 5'
sh 'nc -zv 134.213.79.89 443'
}
}
stage('Prod IAD LB') {
when { branch 'release' }
steps {
sh 'sleep 5'
sh 'nc -zv 23.253.146.253 443'
}
}
}
}
stage('Finish') {
steps {
echo "End of pipeline reached."
}
}
}
post {
success {
slackSend (color: '#008902', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
failure {
slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
}
}