blob: 2fd65bc72b11fe0afee41cb54ef908a5115d4039 [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.
17 *
18**/
19
20common = new com.mirantis.mk.Common()
21git = new com.mirantis.mk.Git()
22python = new com.mirantis.mk.Python()
23
24timestamps {
25 node() {
Tomáš Kukrál9f6260f2017-03-29 23:58:26 +020026 def templateEnv = "${env.WORKSPACE}/template"
27 def modelEnv = "${env.WORKSPACE}/model"
28
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020029 try {
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020030 def templateContext = python.loadJson(COOKIECUTTER_TEMPLATE_CONTEXT)
31 def templateDir = "${templateEnv}/template/dir"
32 def templateOutputDir = "${env.WORKSPACE}/template"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +020033 def cutterEnv = "${env.WORKSPACE}/cutter"
34 def jinjaEnv = "${env.WORKSPACE}/jinja"
35 def clusterName = templateContext.cluster_name
36 def clusterDomain = templateContext.cluster_domain
37 def targetBranch = "feature/${clusterName}"
38
39 stage ('Download Cookiecutter template') {
40 git.checkoutGitRepository(templateEnv, COOKIECUTTER_TEMPLATE_URL, COOKIECUTTER_TEMPLATE_BRANCH, COOKIECUTTER_TEMPLATE_CREDENTIALS)
41 }
42
43 stage ('Download full Reclass model') {
44 git.checkoutGitRepository(modelEnv, RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, RECLASS_MODEL_CREDENTIALS)
45 }
46
47 stage('Generate base infrastructure') {
48 templateDir = "${templateEnv}/cluster_product/infra"
49 templateOutputDir = "${env.WORKSPACE}/template/output_infra"
50 sh "mkdir -p ${templateOutputDir}"
51 python.setupCookiecutterVirtualenv(cutterEnv)
52 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
53 }
54
55 stage('Generate product CI/CD') {
56 if (COOKIECUTTER_INSTALL_CICD.toBoolean()) {
57 templateDir = "${templateEnv}/cluster_product/cicd"
58 templateOutputDir = "${env.WORKSPACE}/template/output_cicd"
59 sh "mkdir -p ${templateOutputDir}"
60 python.setupCookiecutterVirtualenv(cutterEnv)
61 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
62 }
63 }
64
65 stage('Generate product OpenContrail') {
66 if (COOKIECUTTER_INSTALL_CONTRAIL.toBoolean()) {
67 templateDir = "${templateEnv}/cluster_product/contrail"
68 templateOutputDir = "${env.WORKSPACE}/template/output_contrail"
69 sh "mkdir -p ${templateOutputDir}"
70 python.setupCookiecutterVirtualenv(cutterEnv)
71 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
72 }
73 }
74
75 stage('Generate product Kubernetes') {
76 if (COOKIECUTTER_INSTALL_KUBERNETES.toBoolean()) {
77 templateDir = "${templateEnv}/cluster_product/kubernetes"
78 templateOutputDir = "${env.WORKSPACE}/template/output_kubernetes"
79 sh "mkdir -p ${templateOutputDir}"
80 python.setupCookiecutterVirtualenv(cutterEnv)
81 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
82 }
83 }
84
85 stage('Generate product OpenStack') {
86 if (COOKIECUTTER_INSTALL_OPENSTACK.toBoolean()) {
87 templateDir = "${templateEnv}/cluster_product/openstack"
88 templateOutputDir = "${env.WORKSPACE}/template/output_openstack"
89 sh "mkdir -p ${templateOutputDir}"
90 python.setupCookiecutterVirtualenv(cutterEnv)
91 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
92 }
93 }
94
95 stage('Generate product StackLight') {
96 if (COOKIECUTTER_INSTALL_STACKLIGHT.toBoolean()) {
97 templateDir = "${templateEnv}/cluster_product/stacklight"
98 templateOutputDir = "${env.WORKSPACE}/template/output_stacklight"
99 sh "mkdir -p ${templateOutputDir}"
100 python.setupCookiecutterVirtualenv(cutterEnv)
101 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
102 }
103 }
104
105 stage('Generate new SaltMaster node') {
106 def nodeFile = "${modelEnv}/nodes/cfg01.${clusterDomain}.yml"
107 def nodeString = """classes:
108- cluster.${clusterName}.infra.config
109parameters:
110 _param:
111 linux_system_codename: xenial
112 reclass_data_revision: master
113 linux:
114 system:
115 name: cfg01
116 domain: ${clusterDomain}
117"""
118 writeFile(file: nodeFile, text: nodeString)
119 }
120
121 stage('Inject changes to Reclass model') {
122 git.changeGitBranch(modelEnv, targetBranch)
123 def outputSource = "${templateOutputDir}/${clusterName}"
124 def outputDestination = "${modelEnv}/classes/cluster/${clusterName}"
125 sh(returnStdout: true, script: "cp ${outputSource} ${outputDestination} -r")
126 git.commitGitChanges(modelEnv, "Added new cluster ${clusterName}")
Tomáš Kukrál3b2f9932017-03-28 22:57:31 +0200127 archiveArtifacts artifacts: modelEnv
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200128 }
129
130 stage ('Push changes to Reclass model') {
131 git.pushGitChanges(modelEnv, targetBranch, 'origin', RECLASS_MODEL_CREDENTIALS)
132 }
133
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200134 } catch (Throwable e) {
135 // If there was an error or exception thrown, the build failed
136 currentBuild.result = "FAILURE"
137 throw e
138 } finally {
Tomáš Kukrál8b91db92017-03-29 08:30:49 +0200139 stage ('Clean workspace directories') {
140 sh(returnStdout: true, script: "rm ${templateEnv} -rf")
141 sh(returnStdout: true, script: "rm ${modelEnv} -rf")
142 }
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200143 // common.sendNotification(currentBuild.result,"",["slack"])
144 }
145 }
146}