blob: d77572f54ba6e8f66cda78f3472aea20337792cf [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
19 *
20 * OPENSTACK_API_URL OpenStack API address
21 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
22 * OPENSTACK_API_PROJECT OpenStack project to connect to
23 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
24 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
25 *
26 */
27
28git = new com.mirantis.mk.Git()
29openstack = new com.mirantis.mk.Openstack()
30salt = new com.mirantis.mk.Salt()
31orchestrate = new com.mirantis.mk.Orchestrate()
32
33node {
34
35 // connection objects
36 def openstackCloud
37 def saltMaster
38
39 // value defaults
40 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
41 def openstackEnv = "${env.WORKSPACE}/venv"
42
43 if (HEAT_STACK_NAME == '') {
44 HEAT_STACK_NAME = BUILD_TAG
45 }
46
47 //
48 // Bootstrap
49 //
50
51 stage ('Download Heat templates') {
52 git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS)
53 }
54
55 stage('Install OpenStack CLI') {
56 openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
57 }
58
59 stage('Connect to OpenStack cloud') {
60 openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
61 openstack.getKeystoneToken(openstackCloud, openstackEnv)
62 }
63
64 if (HEAT_STACK_REUSE == 'false') {
65 stage('Launch new Heat stack') {
66 envParams = [
67 'instance_zone': HEAT_STACK_ZONE,
68 'public_net': HEAT_STACK_PUBLIC_NET
69 ]
70 openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv)
71 }
72 }
73
74 stage('Connect to Salt master') {
75 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv)
76 saltMasterUrl = "http://${saltMasterHost}:8088"
77 saltMaster = salt.connection(saltMasterUrl, SALT_MASTER_CREDENTIALS)
78 }
79
80 //
81 // Install
82 //
83
84 stage('Install core infra') {
85 // salt.master, reclass
86 // refresh_pillar
87 // sync_all
88 // linux,openssh,salt.minion.ntp
89
90 orchestrate.installFoundationInfra(saltMaster)
91 orchestrate.validateFoundationInfra(saltMaster)
92 }
93
94 stage("Deploy GlusterFS") {
95 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
96 salt.runSaltProcessStep(master, 'ci01*', 'state.sls', ['glusterfs.server.setup'])
97 salt.runSaltProcessStep(master, 'I@glusterfs:client', 'state.sls', ['glusterfs.client'])
98 }
99
100 stage("Deploy GlusterFS") {
101 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'state.sls', ['haproxy,keepalived'])
102 }
103
104 stage("Setup Docker Swarm") {
105 salt.runSaltProcessStep(master, 'I@docker:host', 'state.sls', ['docker.host'])
106 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'state.sls', ['docker.swarm'])
107 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'mine.flush')
108 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'mine.update')
109 salt.runSaltProcessStep(master, 'I@docker:swarm', 'state.sls', ['docker.swarm'])
110 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'cmd.run', ['docker node ls'])
111 }
112
113 stage("Deploy Docker services") {
114 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'state.sls', ['docker.client'])
115 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'cmd.run', ['docker service ls'])
116
117 retry(30) {
118 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'cmd.run', ["""/bin/bash -c '! docker service ls | grep -E "0/[0-9]+"'"""])
119 sleep(10)
120 }
121 }
122
123 stage("Configure CI/CD services") {
124 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'state.sls', ['aptly'])
125 retry(2) {
126 // Needs to run twice to pass __virtual__ method of gerrit module
127 // after installation of dependencies
128 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'state.sls', ['gerrit'])
129 }
130 salt.runSaltProcessStep(master, 'I@docker:swarm:role:master', 'state.sls', ['jenkins'])
131 }
132
133 //
134 // Cleanup
135 //
136
137 if (HEAT_STACK_DELETE == 'true') {
138 stage('Trigger cleanup job') {
139 build job: 'deploy_heat_cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
140 }
141 }
142}