Richard Felkl | 4ae811f | 2017-10-10 18:17:27 +0200 | [diff] [blame] | 1 | /** |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 2 | * Update local mirror |
Richard Felkl | 4ae811f | 2017-10-10 18:17:27 +0200 | [diff] [blame] | 3 | * |
| 4 | * Expected parameters: |
Richard Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 5 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 6 | * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:6969]. |
Richard Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 7 | * UPDATE_APTLY Option to update Aptly |
| 8 | * UPDATE_APTLY_MIRRORS List of mirrors |
| 9 | * PUBLISH_APTLY Publish aptly snapshots |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 10 | * RECREATE_APTLY_MIRRORS Recreate Aptly mirrors |
Richard Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 11 | * 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 Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 14 | * UPDATE_DEBMIRRORS Option to update Debmirrors |
Richard Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 15 | * UPDATE_DOCKER_REGISTRY Option to update Docker Registry |
| 16 | * CLEANUP_DOCKER_CACHE Option to cleanup locally cached Docker images |
Richard Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 17 | * UPDATE_GIT Option to update Git repositories |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 18 | * UPDATE_FILES Option to update static files |
Richard Felkl | 4ae811f | 2017-10-10 18:17:27 +0200 | [diff] [blame] | 19 | * |
| 20 | **/ |
| 21 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 22 | common = new com.mirantis.mk.Common() |
| 23 | salt = new com.mirantis.mk.Salt() |
| 24 | python = new com.mirantis.mk.Python() |
| 25 | venvPepper = "venvPepper" |
| 26 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 27 | timeout(time: 12, unit: 'HOURS') { |
| 28 | node() { |
| 29 | try { |
| 30 | python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 31 | def engine = salt.getPillar(venvPepper, 'I@aptly:server', "aptly:server:source:engine") |
| 32 | runningOnDocker = engine.get("return")[0].containsValue("docker") |
Richard Felkl | 4ae811f | 2017-10-10 18:17:27 +0200 | [diff] [blame] | 33 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 34 | if(UPDATE_APTLY.toBoolean()){ |
| 35 | stage('Update Aptly mirrors'){ |
| 36 | def aptlyMirrorArgs = "-s -v" |
Richard Felkl | 4ae811f | 2017-10-10 18:17:27 +0200 | [diff] [blame] | 37 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 38 | if(RECREATE_APTLY_MIRRORS.toBoolean()) |
| 39 | { |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 40 | if(runningOnDocker){ |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 41 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 49 | sleep(10) |
Richard Felkl | 4ae811f | 2017-10-10 18:17:27 +0200 | [diff] [blame] | 50 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 51 | 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 Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 56 | if(runningOnDocker){ |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 57 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | else{ |
| 64 | common.infoMsg("Updating all Aptly mirrors.") |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 65 | |
Sam Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 66 | if(runningOnDocker){ |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 67 | 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 Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 72 | } |
| 73 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 74 | } |
| 75 | if(PUBLISH_APTLY.toBoolean()){ |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 76 | def aptlyPublishArgs = "-v" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 77 | |
| 78 | common.infoMsg("Publishing all Aptly snapshots.") |
| 79 | |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 80 | salt.enforceState(venvPepper, 'I@aptly:server', ['aptly.publisher'], true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 81 | 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 Stoelinga | aab7970 | 2018-04-09 18:49:39 -0700 | [diff] [blame] | 92 | if(runningOnDocker){ |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 93 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 106 | } |
| 107 | if(UPDATE_DOCKER_REGISTRY.toBoolean()){ |
| 108 | stage('Update Docker images'){ |
| 109 | common.infoMsg("Updating Docker images.") |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 110 | salt.enforceState(venvPepper, 'I@aptly:server', 'docker.client.registry') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 111 | if(CLEANUP_DOCKER_CACHE.toBoolean()){ |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 112 | salt.cmdRun(venvPepper, 'I@aptly:server', 'docker system prune --all --force') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 113 | } |
Richard Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 114 | } |
| 115 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 116 | if(UPDATE_GIT.toBoolean()){ |
| 117 | stage('Update Git repositories'){ |
| 118 | common.infoMsg("Updating Git repositories.") |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 119 | salt.enforceState(venvPepper, 'I@aptly:server', ['git.server'], true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 120 | } |
Richard Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 121 | } |
Richard Felkl | 5f7fdaf | 2018-02-15 15:38:31 +0100 | [diff] [blame] | 122 | 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 126 | } |
Richard Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 127 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 128 | } 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 Felkl | 07043e4 | 2017-11-28 15:03:42 +0100 | [diff] [blame] | 133 | } |
Richard Felkl | 4ae811f | 2017-10-10 18:17:27 +0200 | [diff] [blame] | 134 | } |
Jakub Josef | 2c21c6c | 2018-02-08 18:51:42 +0100 | [diff] [blame] | 135 | } |