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 |
| 13 | def salt = new com.mirantis.mk.Salt() |
| 14 | def common = new com.mirantis.mk.Common() |
| 15 | def python = new com.mirantis.mk.Python() |
| 16 | def venvPepper = "venvPepper" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 17 | timeout(time: 12, unit: 'HOURS') { |
| 18 | node("python") { |
| 19 | try { |
| 20 | python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 21 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 22 | stage("Update Reclass"){ |
| 23 | common.infoMsg("Updating reclass model") |
| 24 | salt.cmdRun(venvPepper, "I@salt:master", 'cd /srv/salt/reclass && git pull -r && git submodule update', false) |
| 25 | salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'cmd.run', ['reclass-salt --top'], null, true) |
| 26 | salt.enforceState(venvPepper, "I@salt:master", 'reclass', true) |
| 27 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 28 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 29 | if(UPDATE_LOCAL_REPOS.toBoolean()){ |
| 30 | stage("Update local repos"){ |
| 31 | common.infoMsg("Updating local repositories") |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 32 | salt.cmdRun(venvPepper, '*apt*', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true, ['runas=aptly']) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 33 | salt.enforceState(venvPepper, '*apt*', 'aptly', true) |
| 34 | salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", 'runas=aptly'], null, true) |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 35 | salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-afrv", 'runas=aptly'], null, true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 36 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 37 | salt.enforceState(venvPepper, '*apt*', 'docker.client.registry', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 38 | |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 39 | salt.cmdRun(venvPepper, '*apt*', "export HOME='/root';export MCP_VERSION='${MCP_VERSION}';/srv/scripts/debmirror.sh") |
| 40 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 41 | salt.enforceState(venvPepper, '*apt*', 'git server', true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 42 | |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 43 | salt.cmdRun(venvPepper, '*apt*', 'pip2pi /srv/pypi_mirror/packages/ -r /srv/pypi_mirror/requirements.txt') |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 44 | |
Richard Felkl | 79d7df1 | 2018-01-05 16:40:11 +0100 | [diff] [blame] | 45 | salt.cmdRun(venvPepper, '*apt*', '/srv/scripts/update-images.sh') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 46 | } |
| 47 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 48 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 49 | stage("Update APT repos"){ |
| 50 | common.infoMsg("Updating APT repositories") |
| 51 | salt.enforceState(venvPepper, "I@linux:system", 'linux.system.repo', true) |
| 52 | } |
| 53 | |
| 54 | stage("Update formulas"){ |
| 55 | common.infoMsg("Updating salt formulas") |
| 56 | salt.cmdRun(venvPepper, "I@salt:master", 'apt-get clean && apt-get update && apt-get install -y salt-formula-*') |
| 57 | |
| 58 | common.infoMsg("Running salt sync-all") |
| 59 | salt.runSaltProcessStep(venvPepper, '*', 'saltutil.sync_all', [], null, true) |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 60 | } |
| 61 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 62 | catch (Throwable e) { |
| 63 | // If there was an error or exception thrown, the build failed |
| 64 | currentBuild.result = "FAILURE" |
| 65 | throw e |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 66 | } |
Richard Felkl | 26cae4d | 2017-12-19 00:19:16 +0100 | [diff] [blame] | 67 | } |
| 68 | } |