blob: 0efc83d388e69bbe3c51ea9a3e78ff321c9534b8 [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
13def salt = new com.mirantis.mk.Salt()
14def common = new com.mirantis.mk.Common()
15def python = new com.mirantis.mk.Python()
16def venvPepper = "venvPepper"
Jakub Josefa63f9862018-01-11 17:58:38 +010017timeout(time: 12, unit: 'HOURS') {
18 node("python") {
19 try {
20 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Richard Felkl26cae4d2017-12-19 00:19:16 +010021
Jakub Josefa63f9862018-01-11 17:58:38 +010022 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 Felkl26cae4d2017-12-19 00:19:16 +010028
Jakub Josefa63f9862018-01-11 17:58:38 +010029 if(UPDATE_LOCAL_REPOS.toBoolean()){
30 stage("Update local repos"){
31 common.infoMsg("Updating local repositories")
Richard Felkl79d7df12018-01-05 16:40:11 +010032 salt.cmdRun(venvPepper, '*apt*', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true, ['runas=aptly'])
Jakub Josefa63f9862018-01-11 17:58:38 +010033 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 Felkl79d7df12018-01-05 16:40:11 +010035 salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-afrv", 'runas=aptly'], null, true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010036
Jakub Josefa63f9862018-01-11 17:58:38 +010037 salt.enforceState(venvPepper, '*apt*', 'docker.client.registry', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010038
Richard Felkl79d7df12018-01-05 16:40:11 +010039 salt.cmdRun(venvPepper, '*apt*', "export HOME='/root';export MCP_VERSION='${MCP_VERSION}';/srv/scripts/debmirror.sh")
40
Jakub Josefa63f9862018-01-11 17:58:38 +010041 salt.enforceState(venvPepper, '*apt*', 'git server', true)
Richard Felkl26cae4d2017-12-19 00:19:16 +010042
Richard Felkl79d7df12018-01-05 16:40:11 +010043 salt.cmdRun(venvPepper, '*apt*', 'pip2pi /srv/pypi_mirror/packages/ -r /srv/pypi_mirror/requirements.txt')
Richard Felkl26cae4d2017-12-19 00:19:16 +010044
Richard Felkl79d7df12018-01-05 16:40:11 +010045 salt.cmdRun(venvPepper, '*apt*', '/srv/scripts/update-images.sh')
Jakub Josefa63f9862018-01-11 17:58:38 +010046 }
47 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010048
Jakub Josefa63f9862018-01-11 17:58:38 +010049 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 Felkl26cae4d2017-12-19 00:19:16 +010060 }
61 }
Jakub Josefa63f9862018-01-11 17:58:38 +010062 catch (Throwable e) {
63 // If there was an error or exception thrown, the build failed
64 currentBuild.result = "FAILURE"
65 throw e
Richard Felkl26cae4d2017-12-19 00:19:16 +010066 }
Richard Felkl26cae4d2017-12-19 00:19:16 +010067 }
68}