blob: 304f97129687eff6608d4a7d3b616cea810a1cf1 [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}"
53 python.setupCookiecutterVirtualenv(cutterEnv)
54 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020055 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020056 }
57
58 stage('Generate product CI/CD') {
59 if (COOKIECUTTER_INSTALL_CICD.toBoolean()) {
60 templateDir = "${templateEnv}/cluster_product/cicd"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020061 templateOutputDir = "${env.WORKSPACE}/template/output/cicd"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020062 sh "mkdir -p ${templateOutputDir}"
63 python.setupCookiecutterVirtualenv(cutterEnv)
64 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020065 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020066 }
67 }
68
69 stage('Generate product OpenContrail') {
70 if (COOKIECUTTER_INSTALL_CONTRAIL.toBoolean()) {
Tomáš Kukrále8042572017-03-30 22:28:06 +020071 templateDir = "${templateEnv}/cluster_product/opencontrail"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020072 templateOutputDir = "${env.WORKSPACE}/template/output/opencontrail"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020073 sh "mkdir -p ${templateOutputDir}"
74 python.setupCookiecutterVirtualenv(cutterEnv)
75 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020076 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020077 }
78 }
79
80 stage('Generate product Kubernetes') {
81 if (COOKIECUTTER_INSTALL_KUBERNETES.toBoolean()) {
82 templateDir = "${templateEnv}/cluster_product/kubernetes"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020083 templateOutputDir = "${env.WORKSPACE}/template/output/kubernetes"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020084 sh "mkdir -p ${templateOutputDir}"
85 python.setupCookiecutterVirtualenv(cutterEnv)
86 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020087 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020088 }
89 }
90
91 stage('Generate product OpenStack') {
92 if (COOKIECUTTER_INSTALL_OPENSTACK.toBoolean()) {
93 templateDir = "${templateEnv}/cluster_product/openstack"
Tomáš Kukrál931f9972017-03-30 23:44:57 +020094 templateOutputDir = "${env.WORKSPACE}/template/output/openstack"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020095 sh "mkdir -p ${templateOutputDir}"
96 python.setupCookiecutterVirtualenv(cutterEnv)
97 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +020098 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020099 }
100 }
101
102 stage('Generate product StackLight') {
103 if (COOKIECUTTER_INSTALL_STACKLIGHT.toBoolean()) {
104 templateDir = "${templateEnv}/cluster_product/stacklight"
Tomáš Kukrál931f9972017-03-30 23:44:57 +0200105 templateOutputDir = "${env.WORKSPACE}/template/output/stacklight"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200106 sh "mkdir -p ${templateOutputDir}"
107 python.setupCookiecutterVirtualenv(cutterEnv)
108 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
Tomáš Kukrál931f9972017-03-30 23:44:57 +0200109 sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200110 }
111 }
112
113 stage('Generate new SaltMaster node') {
114 def nodeFile = "${modelEnv}/nodes/cfg01.${clusterDomain}.yml"
115 def nodeString = """classes:
116- cluster.${clusterName}.infra.config
117parameters:
118 _param:
119 linux_system_codename: xenial
120 reclass_data_revision: master
121 linux:
122 system:
123 name: cfg01
124 domain: ${clusterDomain}
125"""
126 writeFile(file: nodeFile, text: nodeString)
127 }
128
Tomáš Kukrál6c5957e2017-03-30 18:04:38 +0200129 stage('Inject changes to Reclass model') {
130 git.changeGitBranch(modelEnv, targetBranch)
Tomáš Kukrál931f9972017-03-30 23:44:57 +0200131 def outputSource = "${env.WORKSPACE}/template/output/"
132 sh(returnStdout: true, script: "cp -vr ${outputSource} ${outputDestination}")
Tomáš Kukrál6c5957e2017-03-30 18:04:38 +0200133 }
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200134
Tomáš Kukrál6c5957e2017-03-30 18:04:38 +0200135 stage ('Save changes to Reclass model') {
136 if (COMMIT_CHANGES.toBoolean()) {
137 git.commitGitChanges(modelEnv, "Added new cluster ${clusterName}")
Tomáš Kukrál65f8f752017-03-30 17:51:46 +0200138 git.pushGitChanges(modelEnv, targetBranch, 'origin', RECLASS_MODEL_CREDENTIALS)
139 }
Tomáš Kukrál931f9972017-03-30 23:44:57 +0200140 sh(returnStatus: true, script: "tar -zcvf ${clusterName}.tar.gz -C ${modelEnv} .")
Tomáš Kukrál4c98b582017-03-30 18:49:06 +0200141 archiveArtifacts artifacts: "${clusterName}.tar.gz"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200142 }
143
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200144 } catch (Throwable e) {
145 // If there was an error or exception thrown, the build failed
146 currentBuild.result = "FAILURE"
147 throw e
148 } finally {
Tomáš Kukrál8b91db92017-03-29 08:30:49 +0200149 stage ('Clean workspace directories') {
Tomáš Kukrál2b983c32017-03-30 18:09:02 +0200150 sh(returnStatus: true, script: "rm -rfv ${templateEnv}")
151 sh(returnStatus: true, script: "rm -rfv ${modelEnv}")
Tomáš Kukrál8b91db92017-03-29 08:30:49 +0200152 }
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200153 // common.sendNotification(currentBuild.result,"",["slack"])
154 }
155 }
156}