blob: df9dec836b0a49fd2ac613cd8384d886d58af2fb [file] [log] [blame]
Filip Pytloun0a07f702017-02-24 18:26:18 +01001/**
2 *
3 * Launch heat stack with CI/CD lab infrastructure
4 *
5 * Expected parameters:
6 * HEAT_TEMPLATE_URL URL to git repo with Heat templates
7 * HEAT_TEMPLATE_CREDENTIALS Credentials to the Heat templates repo
8 * HEAT_TEMPLATE_BRANCH Heat templates repo branch
9 * HEAT_STACK_NAME Heat stack name
10 * HEAT_STACK_TEMPLATE Heat stack HOT template
11 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
12 * HEAT_STACK_ZONE Heat stack availability zone
13 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
14 * HEAT_STACK_DELETE Delete Heat stack when finished (bool)
15 * HEAT_STACK_CLEANUP_JOB Name of job for deleting Heat stack
16 * HEAT_STACK_REUSE Reuse Heat stack (don't create one)
17 *
18 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Filip Pytloune32fda82017-02-24 18:26:18 +010019 * SALT_MASTER_PORT Port of salt-api, defaults to 8000
Filip Pytloun0a07f702017-02-24 18:26:18 +010020 *
21 * OPENSTACK_API_URL OpenStack API address
22 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
23 * OPENSTACK_API_PROJECT OpenStack project to connect to
24 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
25 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
26 *
27 */
28
29git = new com.mirantis.mk.Git()
30openstack = new com.mirantis.mk.Openstack()
31salt = new com.mirantis.mk.Salt()
32orchestrate = new com.mirantis.mk.Orchestrate()
33
34node {
35
36 // connection objects
37 def openstackCloud
38 def saltMaster
39
40 // value defaults
41 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
42 def openstackEnv = "${env.WORKSPACE}/venv"
43
44 if (HEAT_STACK_NAME == '') {
45 HEAT_STACK_NAME = BUILD_TAG
46 }
47
48 //
49 // Bootstrap
50 //
51
52 stage ('Download Heat templates') {
53 git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS)
54 }
55
56 stage('Install OpenStack CLI') {
57 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
58 }
59
60 stage('Connect to OpenStack cloud') {
61 openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
62 openstack.getKeystoneToken(openstackCloud, openstackEnv)
63 }
64
65 if (HEAT_STACK_REUSE == 'false') {
66 stage('Launch new Heat stack') {
67 envParams = [
68 'instance_zone': HEAT_STACK_ZONE,
69 'public_net': HEAT_STACK_PUBLIC_NET
70 ]
71 openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv)
72 }
73 }
74
75 stage('Connect to Salt master') {
Filip Pytloune32fda82017-02-24 18:26:18 +010076 def saltMasterPort
77 try {
78 saltMasterPort = SALT_MASTER_PORT
79 } catch (MissingPropertyException e) {
80 saltMasterPort = 8000
81 }
Filip Pytloun0a07f702017-02-24 18:26:18 +010082 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv)
Filip Pytloune32fda82017-02-24 18:26:18 +010083 saltMasterUrl = "http://${saltMasterHost}:${saltMasterPort}"
Filip Pytloun0a07f702017-02-24 18:26:18 +010084 saltMaster = salt.connection(saltMasterUrl, SALT_MASTER_CREDENTIALS)
85 }
86
87 //
88 // Install
89 //
90
91 stage('Install core infra') {
92 // salt.master, reclass
93 // refresh_pillar
94 // sync_all
95 // linux,openssh,salt.minion.ntp
96
97 orchestrate.installFoundationInfra(saltMaster)
98 orchestrate.validateFoundationInfra(saltMaster)
99 }
100
101 stage("Deploy GlusterFS") {
Filip Pytloun67fc9a22017-02-27 16:49:04 +0100102 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
103 salt.runSaltProcessStep(saltMaster, 'ci01*', 'state.sls', ['glusterfs.server.setup'])
104 salt.runSaltProcessStep(saltMaster, 'I@glusterfs:client', 'state.sls', ['glusterfs.client'])
Filip Pytloun0a07f702017-02-24 18:26:18 +0100105 }
106
107 stage("Deploy GlusterFS") {
Filip Pytloun67fc9a22017-02-27 16:49:04 +0100108 salt.runSaltProcessStep(saltMaster, 'I@haproxy:proxy', 'state.sls', ['haproxy,keepalived'])
Filip Pytloun0a07f702017-02-24 18:26:18 +0100109 }
110
111 stage("Setup Docker Swarm") {
Filip Pytloun67fc9a22017-02-27 16:49:04 +0100112 salt.runSaltProcessStep(saltMaster, 'I@docker:host', 'state.sls', ['docker.host'])
113 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'state.sls', ['docker.swarm'])
Filip Pytloun23741982017-02-27 17:43:00 +0100114 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'state.sls', ['salt'])
Filip Pytloun67fc9a22017-02-27 16:49:04 +0100115 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'mine.flush')
116 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'mine.update')
117 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm', 'state.sls', ['docker.swarm'])
118 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'cmd.run', ['docker node ls'])
Filip Pytloun0a07f702017-02-24 18:26:18 +0100119 }
120
121 stage("Deploy Docker services") {
Filip Pytloun67fc9a22017-02-27 16:49:04 +0100122 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'state.sls', ['docker.client'])
Filip Pytloun23741982017-02-27 17:43:00 +0100123
124 // XXX: Hack to fix dependency of gerrit on mysql
125 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'cmd.run', ["docker service rm gerrit; rm -rf /srv/volumes/gerrit/*"])
126 sleep(5)
127 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'state.sls', ['docker.client'])
Filip Pytloun0a07f702017-02-24 18:26:18 +0100128
129 retry(30) {
Filip Pytloun67fc9a22017-02-27 16:49:04 +0100130 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'cmd.run', ["""/bin/bash -c '! docker service ls | grep -E "0/[0-9]+"'"""])
Filip Pytloun0a07f702017-02-24 18:26:18 +0100131 sleep(10)
132 }
133 }
134
135 stage("Configure CI/CD services") {
Filip Pytloun67fc9a22017-02-27 16:49:04 +0100136 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'state.sls', ['aptly'])
Filip Pytloun0a07f702017-02-24 18:26:18 +0100137 retry(2) {
138 // Needs to run twice to pass __virtual__ method of gerrit module
139 // after installation of dependencies
Filip Pytloun67fc9a22017-02-27 16:49:04 +0100140 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'state.sls', ['gerrit'])
Filip Pytloun0a07f702017-02-24 18:26:18 +0100141 }
Filip Pytloun23741982017-02-27 17:43:00 +0100142 retry(2) {
143 // Same for jenkins
144 salt.runSaltProcessStep(saltMaster, 'I@docker:swarm:role:master', 'state.sls', ['jenkins'])
145 }
Filip Pytloun0a07f702017-02-24 18:26:18 +0100146 }
147
148 //
149 // Cleanup
150 //
151
152 if (HEAT_STACK_DELETE == 'true') {
153 stage('Trigger cleanup job') {
154 build job: 'deploy_heat_cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
155 }
156 }
157}