blob: 641689eafe8f4f13c7fc45c557531e00cb9eea41 [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}"
39
40 stage ('Download Cookiecutter template') {
41 git.checkoutGitRepository(templateEnv, COOKIECUTTER_TEMPLATE_URL, COOKIECUTTER_TEMPLATE_BRANCH, COOKIECUTTER_TEMPLATE_CREDENTIALS)
42 }
43
44 stage ('Download full Reclass model') {
45 git.checkoutGitRepository(modelEnv, RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, RECLASS_MODEL_CREDENTIALS)
46 }
47
48 stage('Generate base infrastructure') {
49 templateDir = "${templateEnv}/cluster_product/infra"
50 templateOutputDir = "${env.WORKSPACE}/template/output_infra"
51 sh "mkdir -p ${templateOutputDir}"
52 python.setupCookiecutterVirtualenv(cutterEnv)
53 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
54 }
55
56 stage('Generate product CI/CD') {
57 if (COOKIECUTTER_INSTALL_CICD.toBoolean()) {
58 templateDir = "${templateEnv}/cluster_product/cicd"
59 templateOutputDir = "${env.WORKSPACE}/template/output_cicd"
60 sh "mkdir -p ${templateOutputDir}"
61 python.setupCookiecutterVirtualenv(cutterEnv)
62 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
63 }
64 }
65
66 stage('Generate product OpenContrail') {
67 if (COOKIECUTTER_INSTALL_CONTRAIL.toBoolean()) {
68 templateDir = "${templateEnv}/cluster_product/contrail"
69 templateOutputDir = "${env.WORKSPACE}/template/output_contrail"
70 sh "mkdir -p ${templateOutputDir}"
71 python.setupCookiecutterVirtualenv(cutterEnv)
72 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
73 }
74 }
75
76 stage('Generate product Kubernetes') {
77 if (COOKIECUTTER_INSTALL_KUBERNETES.toBoolean()) {
78 templateDir = "${templateEnv}/cluster_product/kubernetes"
79 templateOutputDir = "${env.WORKSPACE}/template/output_kubernetes"
80 sh "mkdir -p ${templateOutputDir}"
81 python.setupCookiecutterVirtualenv(cutterEnv)
82 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
83 }
84 }
85
86 stage('Generate product OpenStack') {
87 if (COOKIECUTTER_INSTALL_OPENSTACK.toBoolean()) {
88 templateDir = "${templateEnv}/cluster_product/openstack"
89 templateOutputDir = "${env.WORKSPACE}/template/output_openstack"
90 sh "mkdir -p ${templateOutputDir}"
91 python.setupCookiecutterVirtualenv(cutterEnv)
92 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
93 }
94 }
95
96 stage('Generate product StackLight') {
97 if (COOKIECUTTER_INSTALL_STACKLIGHT.toBoolean()) {
98 templateDir = "${templateEnv}/cluster_product/stacklight"
99 templateOutputDir = "${env.WORKSPACE}/template/output_stacklight"
100 sh "mkdir -p ${templateOutputDir}"
101 python.setupCookiecutterVirtualenv(cutterEnv)
102 python.buildCookiecutterTemplate(templateDir, templateContext, templateOutputDir, cutterEnv)
103 }
104 }
105
106 stage('Generate new SaltMaster node') {
107 def nodeFile = "${modelEnv}/nodes/cfg01.${clusterDomain}.yml"
108 def nodeString = """classes:
109- cluster.${clusterName}.infra.config
110parameters:
111 _param:
112 linux_system_codename: xenial
113 reclass_data_revision: master
114 linux:
115 system:
116 name: cfg01
117 domain: ${clusterDomain}
118"""
119 writeFile(file: nodeFile, text: nodeString)
120 }
121
Tomáš Kukrál6c5957e2017-03-30 18:04:38 +0200122 stage('Inject changes to Reclass model') {
123 git.changeGitBranch(modelEnv, targetBranch)
124 def outputSource = "${templateOutputDir}/${clusterName}"
125 def outputDestination = "${modelEnv}/classes/cluster/${clusterName}"
126 sh(returnStdout: true, script: "cp ${outputSource} ${outputDestination} -r")
127 }
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200128
Tomáš Kukrál6c5957e2017-03-30 18:04:38 +0200129 stage ('Save changes to Reclass model') {
130 if (COMMIT_CHANGES.toBoolean()) {
131 git.commitGitChanges(modelEnv, "Added new cluster ${clusterName}")
Tomáš Kukrál65f8f752017-03-30 17:51:46 +0200132 git.pushGitChanges(modelEnv, targetBranch, 'origin', RECLASS_MODEL_CREDENTIALS)
133 }
Tomáš Kukrál4c98b582017-03-30 18:49:06 +0200134 sh(returnStatus: true, script: "tar zcvf ${clusterName}.tar.gz ${modelEnv}")
135 archiveArtifacts artifacts: "${clusterName}.tar.gz"
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200136 }
137
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200138 } catch (Throwable e) {
139 // If there was an error or exception thrown, the build failed
140 currentBuild.result = "FAILURE"
141 throw e
142 } finally {
Tomáš Kukrál8b91db92017-03-29 08:30:49 +0200143 stage ('Clean workspace directories') {
Tomáš Kukrál2b983c32017-03-30 18:09:02 +0200144 sh(returnStatus: true, script: "rm -rfv ${templateEnv}")
145 sh(returnStatus: true, script: "rm -rfv ${modelEnv}")
Tomáš Kukrál8b91db92017-03-29 08:30:49 +0200146 }
Tomáš Kukrál7ded3642017-03-27 15:52:51 +0200147 // common.sendNotification(currentBuild.result,"",["slack"])
148 }
149 }
150}