forked from apache/openwhisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
117 lines (105 loc) · 5.51 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
#!groovy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
timeout(time: 12, unit: 'HOURS') {
def port = "444"
def cert = "domain.crt"
def key = "domain.key"
node("openwhisk") {
def hostName = sh(returnStdout: true, script: 'hostname').trim()
def domainName = hostName+".apache.org"
lock("${hostName}") {
try {
deleteDir()
stage('Checkout') {
checkout scm
}
stage('Build') {
// Set up a private docker registry service, accessed by all the OpenWhisk VMs.
try {
sh "docker container stop registry && docker container rm -v registry"
} catch (exp) {
println("Unable to stop and remove the container registry.")
}
sh "docker run -d --restart=always --name registry -v \"$HOME\"/certs:/certs \
-e REGISTRY_HTTP_ADDR=0.0.0.0:${port} -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/${cert} \
-e REGISTRY_HTTP_TLS_KEY=/certs/${key} -p ${port}:${port} registry:2"
// Build the controller and invoker images.
sh "./gradlew distDocker -PdockerRegistry=${domainName}:${port}"
}
stage('Deploy') {
dir("ansible") {
// Copy the jenkins ansible configuration under the directory ansible. This can make sure the SSH is used to
// access the VMs of invokers by the VM of the controller.
sh '[ -f "environments/jenkins/ansible_jenkins.cfg" ] && cp environments/jenkins/ansible_jenkins.cfg ansible.cfg'
}
dir("ansible/environments/jenkins") {
sh "cp ${hostName}.j2.ini hosts.j2.ini"
}
dir("ansible/environments/jenkins/group_vars") {
sh "cp ${hostName} all"
}
dir("ansible") {
sh 'ansible-playbook -i environments/jenkins setup.yml'
sh 'ansible-playbook -i environments/jenkins openwhisk.yml -e mode=clean'
sh 'ansible-playbook -i environments/jenkins apigateway.yml -e mode=clean'
sh 'ansible-playbook -i environments/jenkins couchdb.yml -e mode=clean'
sh 'ansible-playbook -i environments/jenkins couchdb.yml'
sh 'ansible-playbook -i environments/jenkins initdb.yml'
sh 'ansible-playbook -i environments/jenkins wipe.yml'
sh 'ansible-playbook -i environments/jenkins apigateway.yml'
sh 'ansible-playbook -i environments/jenkins openwhisk.yml'
sh 'ansible-playbook -i environments/jenkins properties.yml'
sh 'ansible-playbook -i environments/jenkins routemgmt.yml'
sh 'ansible-playbook -i environments/jenkins postdeploy.yml'
}
}
try {
stage('Test') {
sh './gradlew :tests:test'
}
} catch (exp) {
println("Exception:" + exp)
}
try {
stage('Shoot one invoker test') {
def folder = "ansible/environments/jenkins/group_vars"
def invoker1_node = sh(returnStdout: true,
script: "grep invoker1_machine ${folder}/${hostName} | cut -d: -f2").trim()
sh "ssh -i ${home}/secret/openwhisk_key openwhisk@${invoker1_node} 'docker stop invoker1'"
sleep time: 1, unit: 'MINUTES'
sh './gradlew :tests:test -Dtest.single=*WskActionTests*'
sh "ssh -i ${home}/secret/openwhisk_key openwhisk@${invoker1_node} 'docker start invoker1'"
}
} catch (exp) {
println("Exception:" + exp)
}
stage('Clean up') {
dir("ansible") {
sh 'ansible-playbook -i environments/jenkins openwhisk.yml -e mode=clean'
sh 'ansible-playbook -i environments/jenkins apigateway.yml -e mode=clean'
sh 'ansible-playbook -i environments/jenkins couchdb.yml -e mode=clean'
}
}
} catch (exp) {
println("Exception:" + exp)
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/test-results/**/TEST-*.xml'])
}
}
}
}