Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 1 | /** |
| 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 Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 13 | salt = new com.mirantis.mk.Salt() |
| 14 | common = new com.mirantis.mk.Common() |
| 15 | python = new com.mirantis.mk.Python() |
| 16 | venvPepper = "venvPepper" |
| 17 | |
| 18 | @NonCPS |
| 19 | def 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 30 | timeout(time: 12, unit: 'HOURS') { |
| 31 | node("python") { |
| 32 | try { |
| 33 | python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 34 | def dockerExists = dockerExists() |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 35 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 36 | 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 Josef | 2c21c6c | 2018-02-08 18:51:42 +0100 | [diff] [blame] | 39 | salt.cmdRun(venvPepper, 'I@salt:master', 'reclass-salt --top') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 40 | salt.enforceState(venvPepper, "I@salt:master", 'reclass', true) |
| 41 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 42 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 43 | if(UPDATE_LOCAL_REPOS.toBoolean()){ |
| 44 | stage("Update local repos"){ |
| 45 | common.infoMsg("Updating local repositories") |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 46 | 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 Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 52 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 53 | salt.enforceState(venvPepper, 'I@aptly:server', 'aptly', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 54 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 55 | 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 Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 63 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 64 | salt.enforceState(venvPepper, 'I@aptly:server', 'docker.client.registry', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 65 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 66 | salt.enforceState(venvPepper, 'I@aptly:server', 'debmirror', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 67 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 68 | salt.enforceState(venvPepper, 'I@aptly:server', 'git.server', true) |
| 69 | |
| 70 | salt.enforceState(venvPepper, 'I@aptly:server', 'linux.system.file', true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 71 | } |
| 72 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 73 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 74 | 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 Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 85 | } |
| 86 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 87 | catch (Throwable e) { |
| 88 | // If there was an error or exception thrown, the build failed |
| 89 | currentBuild.result = "FAILURE" |
| 90 | throw e |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 91 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 92 | } |
Jakub Josef | 2c21c6c | 2018-02-08 18:51:42 +0100 | [diff] [blame] | 93 | } |