blob: 8bde843ce9facafd409c4d8b557e70313d959450 [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"
Jakub Josefa63f9862018-01-11 17:58:38 +010025timeout(time: 12, unit: 'HOURS') {
26 node() {
27 try {
28 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Richard Felkl4ae811f2017-10-10 18:17:27 +020029
Jakub Josefa63f9862018-01-11 17:58:38 +010030 if(UPDATE_APTLY.toBoolean()){
31 stage('Update Aptly mirrors'){
32 def aptlyMirrorArgs = "-s -v"
Richard Felkl4ae811f2017-10-10 18:17:27 +020033
Jakub Josefa63f9862018-01-11 17:58:38 +010034 salt.enforceState(venvPepper, '*apt*', ['aptly.server'], true)
35 sleep(10)
Richard Felkl4ae811f2017-10-10 18:17:27 +020036
Jakub Josefa63f9862018-01-11 17:58:38 +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)
Richard Felkl07043e42017-11-28 15:03:42 +010048 }
49 }
Jakub Josefa63f9862018-01-11 17:58:38 +010050 }
51 if(PUBLISH_APTLY.toBoolean()){
52 def aptlyPublishArgs = "-av"
53
54 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)
69 }
70 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 }
Richard Felkl07043e42017-11-28 15:03:42 +010077 }
78 }
Jakub Josefa63f9862018-01-11 17:58:38 +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)
Richard Felkl07043e42017-11-28 15:03:42 +010083 }
84 }
Jakub Josefa63f9862018-01-11 17:58:38 +010085 if(UPDATE_GIT.toBoolean()){
86 stage('Update Git repositories'){
87 common.infoMsg("Updating Git repositories.")
88 salt.enforceState(venvPepper, '*apt*', ['git.server'], true)
89 }
Richard Felkl07043e42017-11-28 15:03:42 +010090 }
Jakub Josefa63f9862018-01-11 17:58:38 +010091 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 }
Richard Felkl07043e42017-11-28 15:03:42 +010096 }
Jakub Josefa63f9862018-01-11 17:58:38 +010097 } 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
Richard Felkl07043e42017-11-28 15:03:42 +0100102 }
Richard Felkl4ae811f2017-10-10 18:17:27 +0200103 }
104}