blob: fb8b0e6ed1c1b790bb9b13e6fa49f5d409a58591 [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
Jakub Josefa63f9862018-01-11 17:58:38 +010018timeout(time: 12, unit: 'HOURS') {
19 node("python") {
20 try {
21 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Richard Felkl26cae4d2017-12-19 00:19:16 +010022
Jakub Josefa63f9862018-01-11 17:58:38 +010023 stage("Update Reclass"){
24 common.infoMsg("Updating reclass model")
25 salt.cmdRun(venvPepper, "I@salt:master", 'cd /srv/salt/reclass && git pull -r && git submodule update', false)
Jakub Josef2c21c6c2018-02-08 18:51:42 +010026 salt.cmdRun(venvPepper, 'I@salt:master', 'reclass-salt --top')
Jakub Josefa63f9862018-01-11 17:58:38 +010027 salt.enforceState(venvPepper, "I@salt:master", 'reclass', true)
28 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010029
Jakub Josefa63f9862018-01-11 17:58:38 +010030 if(UPDATE_LOCAL_REPOS.toBoolean()){
31 stage("Update local repos"){
32 common.infoMsg("Updating local repositories")
Sam Stoelingaaab79702018-04-09 18:49:39 -070033
34 def engine = salt.getPillar(venvPepper, 'I@aptly:server', "aptly:server:source:engine")
35 runningOnDocker = engine.get("return")[0].containsValue("docker")
36
37 if (runningOnDocker) {
38 common.infoMsg("Aptly is running as Docker container")
39 }
40 else {
41 common.infoMsg("Aptly isn't running as Docker container. Going to use aptly user for executing aptly commands")
42 }
43
44 if(runningOnDocker){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010045 salt.cmdRun(venvPepper, 'I@aptly:server', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true)
46 }
47 else{
48 salt.cmdRun(venvPepper, 'I@aptly:server', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true, ['runas=aptly'])
49 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010050
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010051 salt.enforceState(venvPepper, 'I@aptly:server', 'aptly', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010052
Sam Stoelingaaab79702018-04-09 18:49:39 -070053 if(runningOnDocker){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010054 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv"], null, true)
55 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)
56 }
57 else{
58 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true)
59 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-afrv", 'runas=aptly'], null, true)
60 }
Richard Felkl79d7df12018-01-05 16:40:11 +010061
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010062 salt.enforceState(venvPepper, 'I@aptly:server', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010063
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010064 salt.enforceState(venvPepper, 'I@aptly:server', 'debmirror', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010065
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010066 salt.enforceState(venvPepper, 'I@aptly:server', 'git.server', true)
67
68 salt.enforceState(venvPepper, 'I@aptly:server', 'linux.system.file', true)
Jakub Josefa63f9862018-01-11 17:58:38 +010069 }
70 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010071
Jakub Josefa63f9862018-01-11 17:58:38 +010072 stage("Update APT repos"){
73 common.infoMsg("Updating APT repositories")
74 salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true)
75 }
76
77 stage("Update formulas"){
78 common.infoMsg("Updating salt formulas")
79 salt.cmdRun(venvPepper, "I@salt:master", 'apt-get clean && apt-get update && apt-get install -y salt-formula-*')
80
81 common.infoMsg("Running salt sync-all")
82 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.sync_all', [], null, true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010083 }
84 }
Jakub Josefa63f9862018-01-11 17:58:38 +010085 catch (Throwable e) {
86 // If there was an error or exception thrown, the build failed
87 currentBuild.result = "FAILURE"
88 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +010089 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010090 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +010091}