blob: 96dc0274a65eba8dabe04193770fdb5d1851c2ac [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
Jakub Josefa63f9862018-01-11 17:58:38 +010027timeout(time: 12, unit: 'HOURS') {
28 node() {
29 try {
30 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Sam Stoelingaaab79702018-04-09 18:49:39 -070031 def engine = salt.getPillar(venvPepper, 'I@aptly:server', "aptly:server:source:engine")
32 runningOnDocker = engine.get("return")[0].containsValue("docker")
Richard Felkl4ae811f2017-10-10 18:17:27 +020033
Jakub Josefa63f9862018-01-11 17:58:38 +010034 if(UPDATE_APTLY.toBoolean()){
35 stage('Update Aptly mirrors'){
36 def aptlyMirrorArgs = "-s -v"
Richard Felkl4ae811f2017-10-10 18:17:27 +020037
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010038 if(RECREATE_APTLY_MIRRORS.toBoolean())
39 {
Sam Stoelingaaab79702018-04-09 18:49:39 -070040 if(runningOnDocker){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010041 salt.cmdRun(venvPepper, 'I@aptly:server', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true)
42 }
43 else{
44 salt.cmdRun(venvPepper, 'I@aptly:server', "aptly mirror list --raw | grep -E '*' | xargs -n 1 aptly mirror drop -force", true, null, true, ['runas=aptly'])
45 }
46 }
47
48 salt.enforceState(venvPepper, 'I@aptly:server', ['aptly.server'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +010049 sleep(10)
Richard Felkl4ae811f2017-10-10 18:17:27 +020050
Jakub Josefa63f9862018-01-11 17:58:38 +010051 if(UPDATE_APTLY_MIRRORS != ""){
52 common.infoMsg("Updating List of Aptly mirrors.")
53 UPDATE_APTLY_MIRRORS = UPDATE_APTLY_MIRRORS.replaceAll("\\s","")
54 def mirrors = UPDATE_APTLY_MIRRORS.tokenize(",")
55 for(mirror in mirrors){
Sam Stoelingaaab79702018-04-09 18:49:39 -070056 if(runningOnDocker){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010057 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs} -m ${mirror}\""], null, true)
58 }else{
59 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs} -m ${mirror}\"", 'runas=aptly'], null, true)
60 }
Jakub Josefa63f9862018-01-11 17:58:38 +010061 }
62 }
63 else{
64 common.infoMsg("Updating all Aptly mirrors.")
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010065
Sam Stoelingaaab79702018-04-09 18:49:39 -070066 if(runningOnDocker){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010067 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs}\""], null, true)
68 }
69 else{
70 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs}\"", 'runas=aptly'], null, true)
71 }
Richard Felkl07043e42017-11-28 15:03:42 +010072 }
73 }
Jakub Josefa63f9862018-01-11 17:58:38 +010074 }
75 if(PUBLISH_APTLY.toBoolean()){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010076 def aptlyPublishArgs = "-v"
Jakub Josefa63f9862018-01-11 17:58:38 +010077
78 common.infoMsg("Publishing all Aptly snapshots.")
79
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010080 salt.enforceState(venvPepper, 'I@aptly:server', ['aptly.publisher'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +010081 sleep(10)
82
83 if(CLEANUP_APTLY.toBoolean()){
84 aptlyPublishArgs += "c"
85 }
86 if(RECREATE_APTLY_PUBLISHES.toBoolean()){
87 aptlyPublishArgs += "r"
88 }
89 if(FORCE_OVERWRITE_APTLY_PUBLISHES.toBoolean()){
90 aptlyPublishArgs += "f"
91 }
Sam Stoelingaaab79702018-04-09 18:49:39 -070092 if(runningOnDocker){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +010093 aptlyPublishArgs += " -u http://10.99.0.1:8080"
94 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=\"${aptlyPublishArgs}\""], null, true)
95 }
96 else{
97 aptlyPublishArgs += "a"
98 salt.runSaltProcessStep(venvPepper, 'I@aptly:server', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=\"${aptlyPublishArgs}\"", 'runas=aptly'], null, true)
99 }
100 }
101 if(UPDATE_DEBMIRRORS.toBoolean()){
102 stage('Update Debmirrors'){
103 common.infoMsg("Updating Debmirrors")
104 salt.enforceState(venvPepper, 'I@debmirror:client', 'debmirror')
105 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100106 }
107 if(UPDATE_DOCKER_REGISTRY.toBoolean()){
108 stage('Update Docker images'){
109 common.infoMsg("Updating Docker images.")
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100110 salt.enforceState(venvPepper, 'I@aptly:server', 'docker.client.registry')
Jakub Josefa63f9862018-01-11 17:58:38 +0100111 if(CLEANUP_DOCKER_CACHE.toBoolean()){
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100112 salt.cmdRun(venvPepper, 'I@aptly:server', 'docker system prune --all --force')
Jakub Josefa63f9862018-01-11 17:58:38 +0100113 }
Richard Felkl07043e42017-11-28 15:03:42 +0100114 }
115 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100116 if(UPDATE_GIT.toBoolean()){
117 stage('Update Git repositories'){
118 common.infoMsg("Updating Git repositories.")
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100119 salt.enforceState(venvPepper, 'I@aptly:server', ['git.server'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100120 }
Richard Felkl07043e42017-11-28 15:03:42 +0100121 }
Richard Felkl5f7fdaf2018-02-15 15:38:31 +0100122 if(UPDATE_FILES.toBoolean()){
123 stage('Update static files'){
124 common.infoMsg("Updating static files.")
125 salt.enforceState(venvPepper, 'I@aptly:server', ['linux.system.file'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100126 }
Richard Felkl07043e42017-11-28 15:03:42 +0100127 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100128 } catch (Throwable e) {
129 // If there was an error or exception thrown, the build failed
130 currentBuild.result = "FAILURE"
131 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
132 throw e
Richard Felkl07043e42017-11-28 15:03:42 +0100133 }
Richard Felkl4ae811f2017-10-10 18:17:27 +0200134 }
Jakub Josef2c21c6c2018-02-08 18:51:42 +0100135}