blob: d836afbe65d1d3c17368781d6841f46766fa26c8 [file] [log] [blame]
Tomáš Kukrál7ded3642017-03-27 15:52:51 +02001/**
2 * Generate cookiecutter cluster by individual products
3 *
4 * Expected parameters:
5 * COOKIECUTTER_TEMPLATE_CREDENTIALS Credentials to the Cookiecutter template repo.
6 * COOKIECUTTER_TEMPLATE_URL Cookiecutter template repo address.
7 * COOKIECUTTER_TEMPLATE_BRANCH Branch for the template.
8 * COOKIECUTTER_TEMPLATE_CONTEXT Context parameters for the template generation.
9 * COOKIECUTTER_INSTALL_CICD Whether to install CI/CD stack.
10 * COOKIECUTTER_INSTALL_CONTRAIL Whether to install OpenContrail SDN.
11 * COOKIECUTTER_INSTALL_KUBERNETES Whether to install Kubernetes.
12 * COOKIECUTTER_INSTALL_OPENSTACK Whether to install OpenStack cloud.
13 * COOKIECUTTER_INSTALL_STACKLIGHT Whether to install StackLight monitoring.
14 * RECLASS_MODEL_URL Reclass model repo address
15 * RECLASS_MODEL_CREDENTIALS Credentials to the Reclass model repo.
16 * RECLASS_MODEL_BRANCH Branch for the template to push to model.
Tomáš Kukrál65f8f752017-03-30 17:51:46 +020017 * COMMIT_CHANGES Commit model to repo
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020018 *
19**/
20
21common = new com.mirantis.mk.Common()
22git = new com.mirantis.mk.Git()
23python = new com.mirantis.mk.Python()
24
25timestamps {
26 node() {
Tomáš Kukrál9f6260f2017-03-29 23:58:26 +020027 def templateEnv = "${env.WORKSPACE}/template"
28 def modelEnv = "${env.WORKSPACE}/model"
29
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020030 try {
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020031 def templateContext = python.loadJson(COOKIECUTTER_TEMPLATE_CONTEXT)
32 def templateDir = "${templateEnv}/template/dir"
33 def templateOutputDir = "${env.WORKSPACE}/template"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020034 def cutterEnv = "${env.WORKSPACE}/cutter"
35 def jinjaEnv = "${env.WORKSPACE}/jinja"
36 def clusterName = templateContext.cluster_name
37 def clusterDomain = templateContext.cluster_domain
38 def targetBranch = "feature/${clusterName}"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020039 def outputDestination = "${modelEnv}/classes/cluster/${clusterName}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020040
41 stage ('Download Cookiecutter template') {
42 git.checkoutGitRepository(templateEnv, COOKIECUTTER_TEMPLATE_URL, COOKIECUTTER_TEMPLATE_BRANCH, COOKIECUTTER_TEMPLATE_CREDENTIALS)
43 }
44
45 stage ('Download full Reclass model') {
46 git.checkoutGitRepository(modelEnv, RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, RECLASS_MODEL_CREDENTIALS)
47 }
48
49 stage('Generate base infrastructure') {
50 templateDir = "${templateEnv}/cluster_product/infra"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020051 templateOutputDir = "${env.WORKSPACE}/template/output/infra"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020052 sh "mkdir -p ${templateOutputDir}"
Tomáš Kukrálbdc51812017-03-31 09:55:07 +020053 sh "mkdir -p ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020054 python.setupCookiecutterVirtualenv(cutterEnv)
55 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020056 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020057 }
58
59 stage('Generate product CI/CD') {
60 if (COOKIECUTTER_INSTALL_CICD.toBoolean()) {
61 templateDir = "${templateEnv}/cluster_product/cicd"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020062 templateOutputDir = "${env.WORKSPACE}/template/output/cicd"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020063 sh "mkdir -p ${templateOutputDir}"
64 python.setupCookiecutterVirtualenv(cutterEnv)
65 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020066 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020067 }
68 }
69
70 stage('Generate product OpenContrail') {
71 if (COOKIECUTTER_INSTALL_CONTRAIL.toBoolean()) {
Tomáš Kukrále8042572017-03-30 22:28:06 +020072 templateDir = "${templateEnv}/cluster_product/opencontrail"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020073 templateOutputDir = "${env.WORKSPACE}/template/output/opencontrail"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020074 sh "mkdir -p ${templateOutputDir}"
75 python.setupCookiecutterVirtualenv(cutterEnv)
76 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020077 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020078 }
79 }
80
81 stage('Generate product Kubernetes') {
82 if (COOKIECUTTER_INSTALL_KUBERNETES.toBoolean()) {
83 templateDir = "${templateEnv}/cluster_product/kubernetes"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020084 templateOutputDir = "${env.WORKSPACE}/template/output/kubernetes"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020085 sh "mkdir -p ${templateOutputDir}"
86 python.setupCookiecutterVirtualenv(cutterEnv)
87 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020088 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020089 }
90 }
91
92 stage('Generate product OpenStack') {
93 if (COOKIECUTTER_INSTALL_OPENSTACK.toBoolean()) {
94 templateDir = "${templateEnv}/cluster_product/openstack"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020095 templateOutputDir = "${env.WORKSPACE}/template/output/openstack"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020096 sh "mkdir -p ${templateOutputDir}"
97 python.setupCookiecutterVirtualenv(cutterEnv)
98 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020099 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200100 }
101 }
102
103 stage('Generate product StackLight') {
104 if (COOKIECUTTER_INSTALL_STACKLIGHT.toBoolean()) {
105 templateDir = "${templateEnv}/cluster_product/stacklight"
Tomáš Kukrál931f9972017-03-30 23:44:57 +0200106 templateOutputDir = "${env.WORKSPACE}/template/output/stacklight"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200107 sh "mkdir -p ${templateOutputDir}"
108 python.setupCookiecutterVirtualenv(cutterEnv)
109 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +0200110 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200111 }
112 }
113
114 stage('Generate new SaltMaster node') {
115 def nodeFile = "${modelEnv}/nodes/cfg01.${clusterDomain}.yml"
116 def nodeString = """classes:
117- cluster.${clusterName}.infra.config
118parameters:
119 _param:
120 linux_system_codename: xenial
121 reclass_data_revision: master
122 linux:
123 system:
124 name: cfg01
125 domain: ${clusterDomain}
126"""
127 writeFile(file: nodeFile, text: nodeString)
128 }
129
Tomáš Kukrál6c5957e2017-03-30 18:04:38 +0200130 stage('Inject changes to Reclass model') {
131 git.changeGitBranch(modelEnv, targetBranch)
Tomáš Kukrál931f9972017-03-30 23:44:57 +0200132 def outputSource = "${env.WORKSPACE}/template/output/"
133 sh(returnStdout: true, script: "cp -vr ${outputSource} ${outputDestination}")
Tomáš Kukrál6c5957e2017-03-30 18:04:38 +0200134 }
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200135
Tomáš Kukrál6c5957e2017-03-30 18:04:38 +0200136 stage ('Save changes to Reclass model') {
137 if (COMMIT_CHANGES.toBoolean()) {
138 git.commitGitChanges(modelEnv, "Added new cluster ${clusterName}")
Tomáš Kukrál65f8f752017-03-30 17:51:46 +0200139 git.pushGitChanges(modelEnv, targetBranch, 'origin', RECLASS_MODEL_CREDENTIALS)
140 }
Tomáš Kukrál931f9972017-03-30 23:44:57 +0200141 sh(returnStatus: true, script: "tar -zcvf ${clusterName}.tar.gz -C ${modelEnv} .")
Tomáš Kukrál4c98b582017-03-30 18:49:06 +0200142 archiveArtifacts artifacts: "${clusterName}.tar.gz"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200143 }
144
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200145 } catch (Throwable e) {
146 // If there was an error or exception thrown, the build failed
147 currentBuild.result = "FAILURE"
148 throw e
149 } finally {
Tomáš Kukrál8b91db92017-03-29 08:30:49 +0200150 stage ('Clean workspace directories') {
Tomáš Kukrál2b983c32017-03-30 18:09:02 +0200151 sh(returnStatus: true, script: "rm -rfv ${templateEnv}")
152 sh(returnStatus: true, script: "rm -rfv ${modelEnv}")
Tomáš Kukrál8b91db92017-03-29 08:30:49 +0200153 }
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200154 // common.sendNotification(currentBuild.result,"",["slack"])
155 }
156 }
157}