-
Notifications
You must be signed in to change notification settings - Fork 7
/
Jenkinsfile
201 lines (152 loc) · 7.4 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
def OCP_S390X_TOKEN = '<sha256~zdCX5-Lo1dhQyqu5ZsTOwRdc-QQzzyjH-c0Qcdw>'
def OCP_S390X_API_SERVER = '<https://c107.s390x.containers.ihost.local.com:6443>'
// oc login --token=${OCP_S390X_TOKEN} --server=${OCP_S390X_API_SERVER}
def OCP_AMD64_TOKEN = '<sha256~7dylK833xvHzms9VTl1-Ssj8MOqAEZ-HLzFb>'
def OCP_AMD64_API_SERVER = '<https://c107.amd64.containers.cloud.ibm.com:6443>'
//oc login --token=${OCP_AMD64_TOKEN} --server=${OCP_AMD64_API_SERVER}
def DOCKER_REGISTRY= 'docker.io'
def DOCKER_REGISTRY_USER = '<docker-registry-user>'
def DOCKER_REGISTRY_TOKEN = '<hQyqu5ZsTOwRdcLo1d-QQzzyjH-zdCX5>'
// docker login -u=${DOCKER_REGISTRY_USER} -p=${DOCKER_REGISTRY_TOKEN}'
def S390X_LOCAL_IMAGE = 'customer:v0.3-s390x'
def AMD64_LOCAL_IMAGE = 'customer:v0.3-amd64'
def TAG = 'v0.3'
def createOCPNamespaceIfNotExist(String nameSpace) {
echo "passing variable $nameSpace"
try {
sh "oc new-project $nameSpace"
echo 'Succeeded!'
} catch (err) {
echo "The project you are trying to create is already exist: $nameSpace"
//echo "Failed: ${err}"
}
sh "oc project $nameSpace"
}
def deleteOCPDeploymentSVCRouteIfExist() {
def IDENTIFIER_NAME = 'customer'
try {
sh "oc delete deployment ${IDENTIFIER_NAME}-app"
sh "oc delete svc ${IDENTIFIER_NAME}"
sh "oc delete route ${IDENTIFIER_NAME}"
echo 'Succeeded!'
} catch (err) {
echo " the resource you are trying to delete doest not exist: ${IDENTIFIER_NAME}"
//echo "Failed: ${err}"
}
}
node('workers'){
try {
stage('Checkout'){
sh "echo ${OCP_S390X_TOKEN}"
sh "echo ${OCP_AMD64_TOKEN}"
sh "echo ${OCP_S390X_API_SERVER}"
sh "echo ${OCP_AMD64_API_SERVER}"
sh "echo ${DOCKER_REGISTRY_USER}"
sh "echo ${DOCKER_REGISTRY_TOKEN}"
sh "echo ${S390X_LOCAL_IMAGE}"
sh "echo ${AMD64_LOCAL_IMAGE}"
sh "echo ${TAG}"
sh "echo ${DOCKER_REGISTRY}"
checkout scm
}
stage('compile') {
withMaven {
sh 'mvn clean install'
}
dir('target') {
sh "cp bank-customer-1.0-SNAPSHOT.jar ../build"
}
}
stage('Build s390x image'){
dir('build') {
sh "podman build -t ${S390X_LOCAL_IMAGE} --arch=s390x ."
}
// sh "operator-sdk build ${S390X_LOCAL_IMAGE} --image-build-args='--arch=s390x'"
}
stage('Build amd64 image'){
dir('build') {
sh "podman build -t ${AMD64_LOCAL_IMAGE} --arch=amd64 ."
}
// sh "operator-sdk build ${AMD64_LOCAL_IMAGE} --image-build-args='--arch=amd64'"
}
stage('create manifest'){
sh "podman manifest create customer:${TAG}"
}
stage('add manifest list'){
sh "podman manifest add customer:${TAG} containers-storage:localhost/${AMD64_LOCAL_IMAGE}"
sh "podman manifest add customer:${TAG} containers-storage:localhost/${S390X_LOCAL_IMAGE}"
}
stage('Push multi-arch image'){
sh "docker login -u=${DOCKER_REGISTRY_USER} -p=${DOCKER_REGISTRY_TOKEN} "
//sh "skopeo delete docker://${DOCKER_REGISTRY}/${DOCKER_REGISTRY_USER}/customer:${TAG} " //delete the image if it exists.
sh "podman manifest push customer:${TAG} docker://${DOCKER_REGISTRY}/${DOCKER_REGISTRY_USER}/customer:${TAG}"
}
/** Start ---- Pre-integration Tests --------------- */
stage('Pre-integration Tests'){
parallel(
'Quality Tests': {
// sh "docker run --rm customer:v0.3-amd64"
sh "podman run --publish-all --rm --name customer -d customer:v0.3-s390x"
sh 'chmod +x ./build/scripts/test.sh'
sh './build/scripts/test.sh'
},
'Unit Tests': {
sh 'chmod +x ./build/scripts/test.sh'
sh './build/scripts/test.sh'
}
)
}
/** END ---- Pre-integration Tests --------------- */
stage('Deploy Image to OpenShift on x86 and s390x') {
if(env.BRANCH_NAME == 'development' || env.BRANCH_NAME == 'preproduction'){
dir('deploy') {
/** LINUXONE/ONPREM - S390X ENVIRONMENT */
echo 'Deploying to development on S390X environment'
sh "oc login --insecure-skip-tls-verify --token=${OCP_S390X_TOKEN} --server=${OCP_S390X_API_SERVER}"
createOCPNamespaceIfNotExist('staging-deployment')
deleteOCPDeploymentSVCRouteIfExist()
sh "oc create -f bank-customer.yaml" // & deployment config
sh "oc expose service customer" // Push new stream
/** IBM CLOUD - X86 ENVIRONMENT */
echo 'Deploying to development on IBM Cloud on X86 environment'
sh "oc login --insecure-skip-tls-verify --token=${OCP_AMD64_TOKEN} --server=${OCP_AMD64_API_SERVER}"
createOCPNamespaceIfNotExist('staging-deployment')
deleteOCPDeploymentSVCRouteIfExist()
sh "oc create -f bank-customer.yaml" // & deployment config
sh "oc expose service customer" // Push new stream
}
}
if(env.BRANCH_NAME == 'master'){
timeout(time: 2, unit: "HOURS") {
input message: "Approve Deploy?", ok: "Yes"
echo 'Your request to deploy this release to poduction is approved'
dir('deploy') {
/** LINUXONE/ONPREM - S390X ENVIRONMENT */
echo 'Deploying to production on S390X environment'
sh "oc login --token=${OCP_S390X_TOKEN} --server=${OCP_S390X_API_SERVER}"
createOCPNamespaceIfNotExist('production-deployment')
deleteOCPDeploymentSVCRouteIfExist()
sh "oc create -f bank-customer-prod.yaml" // & deployment config
sh "oc expose service customer" // Push new stream
/** IBM CLOUD - X86 ENVIRONMENT */
echo 'Deploying to production on IBM Cloud on X86 environment'
sh "oc login --token=${OCP_AMD64_TOKEN} --server=${OCP_AMD64_API_SERVER}"
createOCPNamespaceIfNotExist('production-deployment')
deleteOCPDeploymentSVCRouteIfExist()
sh "oc create -f bank-customer-prod.yaml" // & deployment config
sh "oc expose service customer" // Push new stream
}
}
}
}
} finally {
stage('cleanup') {
echo 'Clean up workspace'
deleteDir()
echo 'remove all images'
sh 'docker image prune -a -f'
sh "docker stop customer"
// sh 'docker volume rm $(docker volume ls -qf dangling=true)'
}
}
}