blob: 70256b71287cca043af1d8f6fd187dfd45353885 [file] [log] [blame]
Richard Felkl26cae4d2017-12-19 00:19:16 +01001/**
2 *
3 * Update Salt environment pipeline
4 *
5 * Expected parameters:
6 * SALT_MASTER_URL Salt API server location
7 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
8 * MCP_VERSION Version of MCP to upgrade to
9 * UPDATE_LOCAL_REPOS Update local repositories
10 */
11
12// Load shared libs
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010013salt = new com.mirantis.mk.Salt()
14common = new com.mirantis.mk.Common()
15python = new com.mirantis.mk.Python()
16venvPepper = "venvPepper"
17
18@NonCPS
19def Boolean dockerExists() {
20 def engine = salt.getPillar(venvPepper, 'I@aptly:server', "aptly:server:source:engine")
21 def matches = (engine =~ /:docker/)
22 try{
23 def test = matches[position]
24 return false
25 }catch(Exception ex){
26 return true
27 }
28}
29
Jakub Josefa63f9862018-01-11 17:58:38 +010030timeout(time: 12, unit: 'HOURS') {
31 node("python") {
32 try {
33 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010034 def dockerExists = dockerExists()
Richard Felkl26cae4d2017-12-19 00:19:16 +010035
Jakub Josefa63f9862018-01-11 17:58:38 +010036 stage("Update Reclass"){
37 common.infoMsg("Updating reclass model")
38 salt.cmdRun(venvPepper, "I@salt:master", 'cd /srv/salt/reclass && git pull -r && git submodule update', false)
Jakub Josef2c21c6c2018-02-08 18:51:42 +010039 salt.cmdRun(venvPepper, 'I@salt:master', 'reclass-salt --top')
Jakub Josefa63f9862018-01-11 17:58:38 +010040 salt.enforceState(venvPepper, "I@salt:master", 'reclass', true)
41 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010042
Jakub Josefa63f9862018-01-11 17:58:38 +010043 if(UPDATE_LOCAL_REPOS.toBoolean()){
44 stage("Update local repos"){
45 common.infoMsg("Updating local repositories")
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010046 if(dockerExists){
47 salt.cmdRun(venvPepper, 'I@aptly:server', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true)
48 }
49 else{
50 salt.cmdRun(venvPepper, 'I@aptly:server', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true, ['runas=aptly'])
51 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010052
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010053 salt.enforceState(venvPepper, 'I@aptly:server', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010054
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010055 if(dockerExists){
56 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
57 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-frv -u http://10.99.0.1:8080"], null, true)
58 }
59 else{
60 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
61 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-afrv", 'runas=aptly'], null, true)
62 }
Richard Felkl79d7df12018-01-05 16:40:11 +010063
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010064 salt.enforceState(venvPepper, 'I@aptly:server', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010065
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010066 salt.enforceState(venvPepper, 'I@aptly:server', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010067
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010068 salt.enforceState(venvPepper, 'I@aptly:server', 'git.server', true)
69
70 salt.enforceState(venvPepper, 'I@aptly:server', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +010071 }
72 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010073
Jakub Josefa63f9862018-01-11 17:58:38 +010074 stage("Update APT repos"){
75 common.infoMsg("Updating APT repositories")
76 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true)
77 }
78
79 stage("Update formulas"){
80 common.infoMsg("Updating salt formulas")
81 salt.cmdRun(venvPepper, "I@salt:master", 'apt-get clean && apt-get update && apt-get install -y salt-formula-*')
82
83 common.infoMsg("Running salt sync-all")
84 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.sync_all', [], null, true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010085 }
86 }
Jakub Josefa63f9862018-01-11 17:58:38 +010087 catch (Throwable e) {
88 // If there was an error or exception thrown, the build failed
89 currentBuild.result = "FAILURE"
90 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +010091 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010092 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +010093}