forked from gunjeetgulatigit/nameko-devex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
213 lines (184 loc) · 8.16 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
pipeline {
agent {
docker {
image 'devcontainer:dev'
}
}
options {
buildDiscarder(logRotator(daysToKeepStr: '60'))
timeout(time: 4, unit: 'HOURS')
//skipDefaultCheckout()
}
parameters {
string(name: 'CF_URL', defaultValue: 'https://api.dev.kubecf.speedyorbit.com',
description: '''
Using KubeCF
''')
string(name: 'CF_ORG', defaultValue: 'good',
description: '''
Using PCF Cloudfoundry
''')
string(name: 'CF_SPACE', defaultValue: 'morning', description: 'CF space. eg: jenkins ?')
string(name: 'PREFIX', defaultValue: '', description: 'usually same as CF_SPACE. Empty = Dynamic generation')
string(name: 'CF_CRED_ID', defaultValue: 'ddb7804d-3dbf-48fc-8b14-7ddaa6fc2ea2', description: 'get it from jenkins credentials')
string(name: 'NUM_USERS', defaultValue: '20', description: 'Total number of concurrent users')
string(name: 'HOLD_HOURS', defaultValue: '0.5', description: 'Total amount of time to execute the tests')
}
environment {
CF_HOME = "${env.WORKSPACE}"
}
stages {
stage('Prepare Dev Env') {
parallel {
stage('Create Dev Conda Env'){
steps {
script {
if (currentBuild.number == 1) {
build(job: currentBuild.fullProjectName, propagate: false, wait: false)
currentBuild.result = "ABORTED"
error("Job #1: aborting and re-build for initialize parameters")
}
if (!params.PREFIX?.trim()) {
env.PREFIX = sh(returnStdout: true, script: 'echo ${BUILD_TAG} | md5sum | cut -c -10').trim()
}
}
sh '''#!/bin/bash
conda env create -f environment_dev.yml > conda_create.log
'''
}
}
stage('Start Local BackServices') {
steps {
sh '''#!/bin/bash
echo "Starting RabbitMQ Service"
source activate rabbitmq
rabbitmq-server -detached
sleep 30
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl add_user "rabbit" "rabbit"
rabbitmqctl set_user_tags rabbit administrator
rabbitmqctl set_permissions --vhost '/' 'rabbit' '.' '.' '.'
echo "Starting Redis Service"
source activate redis
# get config file for version 5
curl -s https://raw.githubusercontent.com/antirez/redis/5.0/redis.conf > ./redis.conf
redis-server ./redis.conf --daemonize yes
sleep 5
echo 'CONFIG Set "requirePass" ""' | redis-cli
echo "Starting Postgres Service"
echo "Starting Postgres Service"
# source activate ${HOME}/.conda/envs/postgres
source activate postgres
DB_DIR=$(mktemp -d -t postgres.XXX)
echo ${DB_DIR}
INIT_DB_PATH=${HOME}/.conda/envs/postgres/share
echo ${INIT_DB_PATH}
initdb -L ${INIT_DB_PATH} -D ${DB_DIR}/postgres
# Configure pg_hdb.conf file
echo "host all all 0.0.0.0/0 trust" >> ${DB_DIR}/postgres/pg_hba.conf
echo "host replication all 0.0.0.0/0 trust" >> ${DB_DIR}/postgres/pg_hba.conf
echo "port = 5432" >> ${DB_DIR}/postgres/my_custom.conf
echo "listen_addresses = '0.0.0.0'" >> ${DB_DIR}/postgres/my_custom.conf
echo "include = 'my_custom.conf'" >> ${DB_DIR}/postgres/postgresql.conf
postgres -i -N 200 -D ${DB_DIR}/postgres &
sleep 5
createuser --no-password --superuser postgres
# createdb --owner=postgres postgres
echo "GRANT CONNECT ON DATABASE postgres TO postgres;" | psql postgres
echo "Users and local db is created..."
'''
}
}
}
}
stage('Unit Test') {
steps {
sh '''#!/bin/bash
source activate nameko-devex
./dev_pytest.sh
'''
}
}
stage('Smoke Test') {
steps {
sh '''#!/bin/bash
source activate nameko-devex
echo "Start app service ..."
FASTAPI=X ./dev_run.sh orders.service products.service > app.log &
sleep 5
echo "Start smoketest ..."
./test/nex-smoketest.sh local
'''
}
}
stage('Deploy + Test') {
when {
anyOf {
expression{ env.BRANCH_NAME =~ 'PR-' }
branch 'performance'
branch 'master'
}
}
stages {
stage('Deploy') {
steps {
// cf login and undeploy
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: "${params.CF_CRED_ID}",
usernameVariable: 'CF_USR', passwordVariable: 'CF_PWD']]){
sh '''#!/bin/bash
echo "Deploy: CF Login into org:${CF_ORG}, space:${CF_SPACE}"
cf login -u ${CF_USR} -p ${CF_PWD} -a ${CF_URL} -o ${CF_ORG} -s ${CF_SPACE}
source activate nameko-devex
set -e
echo "Deploy: CF_APP=${PREFIX} make deployCF"
CF_APP=${PREFIX} make deployCF > deploy.log
'''
}
}
}
stage('Smoke Test on CF') {
steps {
sh '''#!/bin/bash
source activate nameko-devex
echo "Start smoketest ..."
./test/nex-smoketest.sh https://${PREFIX}.dev.kubecf.speedyorbit.com
'''
}
}
stage('Perf Test') {
when {
anyOf {
branch 'performance'
branch 'master'
}
}
steps {
sh '''#!/bin/bash
source activate nameko-devex
echo "Start perftest ..."
./test/nex-bzt.sh https://${PREFIX}.dev.kubecf.speedyorbit.com
'''
}
}
}
}
}
post {
always {
script {
// undeploy first if deployed
if (fileExists('deploy.log')) {
sh '''
echo "post: Undeploy landscape: ${PREFIX}"
CF_APP=${PREFIX} make undeployCF
'''
}
}
}
cleanup {
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log, *.xng', fingerprint: true
deleteDir()
}
}
}