blob: 238dbb25c0c337a2c7a543d9797912aae1c062df [file] [log] [blame]
Richard Felkl4ae811f2017-10-10 18:17:27 +02001/**
2 * Update mirror image
3 *
4 * Expected parameters:
Richard Felkl07043e42017-11-28 15:03:42 +01005 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000].
7 * UPDATE_APTLY Option to update Aptly
8 * UPDATE_APTLY_MIRRORS List of mirrors
9 * PUBLISH_APTLY Publish aptly snapshots
10 * RECREATE_APTLY_PUBLISHES Option to recreate Aptly publishes separated by comma
11 * FORCE_OVERWRITE_APTLY_PUBLISHES Option to force overwrite existing packages while publishing
12 * CLEANUP_APTLY Option to cleanup old Aptly snapshots
13 * UPDATE_DOCKER_REGISTRY Option to update Docker Registry
14 * CLEANUP_DOCKER_CACHE Option to cleanup locally cached Docker images
15 * UPDATE_PYPI Option to update Python Packages
16 * UPDATE_GIT Option to update Git repositories
17 * UPDATE_IMAGES Option to update VM images
Richard Felkl4ae811f2017-10-10 18:17:27 +020018 *
19**/
20
21def common = new com.mirantis.mk.Common()
22def salt = new com.mirantis.mk.Salt()
23def python = new com.mirantis.mk.Python()
24def venvPepper = "venvPepper"
25
26node() {
27 try {
Richard Felkl4ae811f2017-10-10 18:17:27 +020028 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
29
Richard Felkl07043e42017-11-28 15:03:42 +010030 if(UPDATE_APTLY.toBoolean()){
31 stage('Update Aptly mirrors'){
32 def aptlyMirrorArgs = "-s -v"
Richard Felkl4ae811f2017-10-10 18:17:27 +020033
Richard Felkl07043e42017-11-28 15:03:42 +010034 salt.enforceState(venvPepper, '*apt*', ['aptly.server'], true)
35 sleep(10)
Richard Felkl4ae811f2017-10-10 18:17:27 +020036
Richard Felkl07043e42017-11-28 15:03:42 +010037 if(UPDATE_APTLY_MIRRORS != ""){
38 common.infoMsg("Updating List of Aptly mirrors.")
39 UPDATE_APTLY_MIRRORS = UPDATE_APTLY_MIRRORS.replaceAll("\\s","")
40 def mirrors = UPDATE_APTLY_MIRRORS.tokenize(",")
41 for(mirror in mirrors){
42 salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs} -m ${mirror}\"", 'runas=aptly'], null, true)
43 }
44 }
45 else{
46 common.infoMsg("Updating all Aptly mirrors.")
47 salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs}\"", 'runas=aptly'], null, true)
48 }
49 }
Richard Felkl4ae811f2017-10-10 18:17:27 +020050 }
Richard Felkl07043e42017-11-28 15:03:42 +010051 if(PUBLISH_APTLY.toBoolean()){
52 def aptlyPublishArgs = "-av"
Richard Felkl4ae811f2017-10-10 18:17:27 +020053
Richard Felkl07043e42017-11-28 15:03:42 +010054 common.infoMsg("Publishing all Aptly snapshots.")
55
56 salt.enforceState(venvPepper, '*apt*', ['aptly.publisher'], true)
57 sleep(10)
58
59 if(CLEANUP_APTLY.toBoolean()){
60 aptlyPublishArgs += "c"
61 }
62 if(RECREATE_APTLY_PUBLISHES.toBoolean()){
63 aptlyPublishArgs += "r"
64 }
65 if(FORCE_OVERWRITE_APTLY_PUBLISHES.toBoolean()){
66 aptlyPublishArgs += "f"
67 }
68 salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=\"${aptlyPublishArgs}\"", 'runas=aptly'], null, true)
Richard Felkl4ae811f2017-10-10 18:17:27 +020069 }
Richard Felkl07043e42017-11-28 15:03:42 +010070 if(UPDATE_DOCKER_REGISTRY.toBoolean()){
71 stage('Update Docker images'){
72 common.infoMsg("Updating Docker images.")
73 salt.enforceState(venvPepper, '*apt*', ['docker.client.registry'], true)
74 if(CLEANUP_DOCKER_CACHE.toBoolean()){
75 salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.run', ['docker system prune --all --force'], null, true)
76 }
77 }
Richard Felkl4ae811f2017-10-10 18:17:27 +020078 }
Richard Felkl07043e42017-11-28 15:03:42 +010079 if(UPDATE_PYPI.toBoolean()){
80 stage('Update PyPi packages'){
81 common.infoMsg("Updating PyPi packages.")
82 salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.run', ['pip2pi /srv/pypi_mirror/packages/ -r /srv/pypi_mirror/requirements.txt'], null, true)
83 }
84 }
85 if(UPDATE_GIT.toBoolean()){
86 stage('Update Git repositories'){
87 common.infoMsg("Updating Git repositories.")
88 salt.enforceState(venvPepper, '*apt*', ['git.server'], true)
89 }
90 }
91 if(UPDATE_IMAGES.toBoolean()){
92 stage('Update VM images'){
93 common.infoMsg("Updating VM images.")
94 salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.run', ['/srv/scripts/update-images.sh'], null, true)
95 }
96 }
Richard Felkl4ae811f2017-10-10 18:17:27 +020097 } catch (Throwable e) {
98 // If there was an error or exception thrown, the build failed
99 currentBuild.result = "FAILURE"
100 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
101 throw e
102 }
103}