blob: 2f71d2a67a7935d25ca7578dd4f254dcd95e3796 [file] [log] [blame]
Richard Felkl4ae811f2017-10-10 18:17:27 +02001/**
Richard Felkl5f7fdaf2018-02-15 15:38:31 +01002 * Update local mirror
Richard Felkl4ae811f2017-10-10 18:17:27 +02003 *
4 * Expected parameters:
Richard Felkl07043e42017-11-28 15:03:42 +01005 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
Richard Felkl5f7fdaf2018-02-15 15:38:31 +01006 * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:6969].
Richard Felkl07043e42017-11-28 15:03:42 +01007 * UPDATE_APTLY Option to update Aptly
8 * UPDATE_APTLY_MIRRORS List of mirrors
9 * PUBLISH_APTLY Publish aptly snapshots
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010010 * RECREATE_APTLY_MIRRORS Recreate Aptly mirrors
Richard Felkl07043e42017-11-28 15:03:42 +010011 * RECREATE_APTLY_PUBLISHES Option to recreate Aptly publishes separated by comma
12 * FORCE_OVERWRITE_APTLY_PUBLISHES Option to force overwrite existing packages while publishing
13 * CLEANUP_APTLY Option to cleanup old Aptly snapshots
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010014 * UPDATE_DEBMIRRORS Option to update Debmirrors
Richard Felkl07043e42017-11-28 15:03:42 +010015 * UPDATE_DOCKER_REGISTRY Option to update Docker Registry
16 * CLEANUP_DOCKER_CACHE Option to cleanup locally cached Docker images
Richard Felkl07043e42017-11-28 15:03:42 +010017 * UPDATE_GIT Option to update Git repositories
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010018 * UPDATE_FILES Option to update static files
Richard Felkl4ae811f2017-10-10 18:17:27 +020019 *
20**/
21
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010022common = new com.mirantis.mk.Common()
23salt = new com.mirantis.mk.Salt()
24python = new com.mirantis.mk.Python()
25venvPepper = "venvPepper"
26
27@NonCPS
28def Boolean dockerExists() {
29 def engine = salt.getPillar(venvPepper, 'I@aptly:server', "aptly:server:source:engine")
30 def matches = (engine =~ /:docker/)
31 try{
32 def test = matches[position]
33 return false
34 }catch(Exception ex){
35 return true
36 }
37}
38
Jakub Josefa63f9862018-01-11 17:58:38 +010039timeout(time: 12, unit: 'HOURS') {
40 node() {
41 try {
42 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010043 def dockerExists = dockerExists()
Richard Felkl4ae811f2017-10-10 18:17:27 +020044
Jakub Josefa63f9862018-01-11 17:58:38 +010045 if(UPDATE_APTLY.toBoolean()){
46 stage('Update Aptly mirrors'){
47 def aptlyMirrorArgs = "-s -v"
Richard Felkl4ae811f2017-10-10 18:17:27 +020048
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010049 if(RECREATE_APTLY_MIRRORS.toBoolean())
50 {
51 if(dockerExists){
52 salt.cmdRun(venvPepper, 'I@aptly:server', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true)
53 }
54 else{
55 salt.cmdRun(venvPepper, 'I@aptly:server', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true, ['runas=aptly'])
56 }
57 }
58
59 salt.enforceState(venvPepper, 'I@aptly:server', ['aptly.server'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +010060 sleep(10)
Richard Felkl4ae811f2017-10-10 18:17:27 +020061
Jakub Josefa63f9862018-01-11 17:58:38 +010062 if(UPDATE_APTLY_MIRRORS != ""){
63 common.infoMsg("Updating List of Aptly mirrors.")
64 UPDATE_APTLY_MIRRORS = UPDATE_APTLY_MIRRORS.replaceAll("\\s","")
65 def mirrors = UPDATE_APTLY_MIRRORS.tokenize(",")
66 for(mirror in mirrors){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010067 if(dockerExists){
68 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs} -m ${mirror}\""], null, true)
69 }else{
70 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs} -m ${mirror}\"", 'runas=aptly'], null, true)
71 }
Jakub Josefa63f9862018-01-11 17:58:38 +010072 }
73 }
74 else{
75 common.infoMsg("Updating all Aptly mirrors.")
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010076
77 if(dockerExists){
78 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs}\""], null, true)
79 }
80 else{
81 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs}\"", 'runas=aptly'], null, true)
82 }
Richard Felkl07043e42017-11-28 15:03:42 +010083 }
84 }
Jakub Josefa63f9862018-01-11 17:58:38 +010085 }
86 if(PUBLISH_APTLY.toBoolean()){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010087 def aptlyPublishArgs = "-v"
Jakub Josefa63f9862018-01-11 17:58:38 +010088
89 common.infoMsg("Publishing all Aptly snapshots.")
90
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010091 salt.enforceState(venvPepper, 'I@aptly:server', ['aptly.publisher'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +010092 sleep(10)
93
94 if(CLEANUP_APTLY.toBoolean()){
95 aptlyPublishArgs += "c"
96 }
97 if(RECREATE_APTLY_PUBLISHES.toBoolean()){
98 aptlyPublishArgs += "r"
99 }
100 if(FORCE_OVERWRITE_APTLY_PUBLISHES.toBoolean()){
101 aptlyPublishArgs += "f"
102 }
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100103 if(dockerExists){
104 aptlyPublishArgs += " -u http://10.99.0.1:8080"
105 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=\"${aptlyPublishArgs}\""], null, true)
106 }
107 else{
108 aptlyPublishArgs += "a"
109 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=\"${aptlyPublishArgs}\"", 'runas=aptly'], null, true)
110 }
111 }
112 if(UPDATE_DEBMIRRORS.toBoolean()){
113 stage('Update Debmirrors'){
114 common.infoMsg("Updating Debmirrors")
115 salt.enforceState(venvPepper, 'I@debmirror:client', 'debmirror')
116 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100117 }
118 if(UPDATE_DOCKER_REGISTRY.toBoolean()){
119 stage('Update Docker images'){
120 common.infoMsg("Updating Docker images.")
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100121 salt.enforceState(venvPepper, 'I@aptly:server', 'docker.client.registry')
Jakub Josefa63f9862018-01-11 17:58:38 +0100122 if(CLEANUP_DOCKER_CACHE.toBoolean()){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100123 salt.cmdRun(venvPepper, 'I@aptly:server', 'docker system prune --all --force')
Jakub Josefa63f9862018-01-11 17:58:38 +0100124 }
Richard Felkl07043e42017-11-28 15:03:42 +0100125 }
126 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100127 if(UPDATE_GIT.toBoolean()){
128 stage('Update Git repositories'){
129 common.infoMsg("Updating Git repositories.")
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100130 salt.enforceState(venvPepper, 'I@aptly:server', ['git.server'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100131 }
Richard Felkl07043e42017-11-28 15:03:42 +0100132 }
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100133 if(UPDATE_FILES.toBoolean()){
134 stage('Update static files'){
135 common.infoMsg("Updating static files.")
136 salt.enforceState(venvPepper, 'I@aptly:server', ['linux.system.file'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100137 }
Richard Felkl07043e42017-11-28 15:03:42 +0100138 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100139 } catch (Throwable e) {
140 // If there was an error or exception thrown, the build failed
141 currentBuild.result = "FAILURE"
142 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
143 throw e
Richard Felkl07043e42017-11-28 15:03:42 +0100144 }
Richard Felkl4ae811f2017-10-10 18:17:27 +0200145 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100146}