Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 3 | // Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | // ----------------------------------------------------------------------- |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 17 | // Install the voltctl command by branch name "voltha-xx" |
| 18 | // ----------------------------------------------------------------------- |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 19 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 20 | // ----------------------------------------------------------------------- |
| 21 | // ----------------------------------------------------------------------- |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 22 | String getIam(String func) { |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 23 | // Cannot rely on a stack trace due to jenkins manipulation |
| 24 | String src = 'vars/installVoltctl.groovy' |
| 25 | String iam = [src, func].join('::') |
| 26 | return iam |
| 27 | } |
| 28 | |
| 29 | // ----------------------------------------------------------------------- |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 30 | // Intent: Log progress message |
| 31 | // ----------------------------------------------------------------------- |
| 32 | void enter(String name) { |
| 33 | // Announce ourselves for log usability |
| 34 | String iam = getIam(name) |
| 35 | println("${iam}: ENTER") |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | // ----------------------------------------------------------------------- |
| 40 | // Intent: Log progress message |
| 41 | // ----------------------------------------------------------------------- |
| 42 | void leave(String name) { |
| 43 | // Announce ourselves for log usability |
| 44 | String iam = getIam(name) |
| 45 | println("${iam}: LEAVE") |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | // ----------------------------------------------------------------------- |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 50 | // ----------------------------------------------------------------------- |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 51 | Boolean process(String branch) { |
| 52 | Boolean ans = true |
| 53 | enter('process') |
Joey Armstrong | 299f1f3 | 2022-11-24 08:45:25 -0500 | [diff] [blame] | 54 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 55 | // This logic seems odd given we branch & tag repositories |
| 56 | // for release so hilight non-frozen until we know for sure. |
Joey Armstrong | e0ed035 | 2023-09-05 19:00:50 -0400 | [diff] [blame] | 57 | def released = [ |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 58 | // v1.9.1 - https://github.com/opencord/voltctl/releases/tag/untagged-cd611c39178f25b95a87 |
| 59 | 'voltha-2.12' : '1.8.45', |
| 60 | 'voltha-2.11' : '1.8.45', |
| 61 | // https://github.com/opencord/voltctl/releases/tag/v1.7.6 |
| 62 | 'voltha-2.10' : '1.7.6', |
| 63 | 'voltha-2.9' : '1.7.4', |
| 64 | 'voltha-2.8' : '1.6.11', |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 65 | ] |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 66 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 67 | boolean have_released = released.containsKey(branch) |
| 68 | boolean is_release = false |
| 69 | // TODO: Enable with parameter: RELEASE_VOLTHA= |
| 70 | boolean has_binding = binding.hasVariable('WORKSPACE') |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 71 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 72 | // WIP: Probe to find out what is available |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 73 | print(""" |
| 74 | ** have_released: ${have_released} |
| 75 | ** has_binding: ${has_binding} |
| 76 | """) |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 77 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 78 | // --------------------------------------------- |
| 79 | // Sanity check: released version must be frozen |
| 80 | // --------------------------------------------- |
| 81 | if (is_release && ! released.containsKey(branch)) { |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 82 | // Fingers crossed: jenkins may rewrite the callstack. |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 83 | String myname = this.class.getName() |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 84 | |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 85 | String url = [ |
| 86 | 'https://docs.voltha.org/master', |
| 87 | 'howto/release/installVoltctl.html', |
| 88 | ].join('/') |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 89 | |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 90 | String error = [ |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 91 | myname, 'ERROR:', |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 92 | "Detected release version=[$branch]", |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 93 | 'but voltctl is not frozen.', |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 94 | '', |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 95 | 'See Also:', url, |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 96 | ].join(' ') |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 97 | throw new Exception(error) // groovylint-disable-line ThrowException |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | // -------------------------------- |
| 101 | // General answer: latest available |
| 102 | // -------------------------------- |
| 103 | if (! have_released) { |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 104 | url = 'https://api.github.com/repos/opencord/voltctl/releases/latest' |
| 105 | get_version = [ |
| 106 | "curl -sSL ${url}", |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 107 | 'jq -r .tag_name', |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 108 | "sed -e 's/^v//g'", |
| 109 | ].join(' | ') |
| 110 | |
| 111 | print(" ** RUNNING: ${get_version}") |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 112 | released[branch] = sh( |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 113 | script: get_version, |
| 114 | returnStdout: true |
| 115 | ).trim() |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | voltctlVersion = released[branch] |
| 119 | println "Installing voltctl version ${voltctlVersion} on branch ${branch}" |
| 120 | |
| 121 | // ----------------------------------------------------------------------- |
| 122 | // groovy expansion: ${var} |
| 123 | // shell expansion: \${var} |
| 124 | // ----------------------------------------------------------------------- |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 125 | sh( |
| 126 | label : 'Install Voltctl', |
| 127 | returnStdout: false, |
| 128 | script: """#!/bin/bash |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 129 | |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 130 | # set -eu -o pipefail |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 131 | |
| 132 | bin_voltctl="$WORKSPACE/bin/voltctl" |
| 133 | |
| 134 | mkdir -p "$WORKSPACE/bin" |
| 135 | cd "$WORKSPACE" || { echo "ERROR: cd $WORKSPACE failed"; exit 1; } |
| 136 | |
| 137 | HOSTOS="\$(uname -s | tr '[:upper:]' '[:lower:]')" |
| 138 | HOSTARCH="\$(uname -m | tr '[:upper:]' '[:lower:]')" |
| 139 | if [ "\$HOSTARCH" == "x86_64" ]; then |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 140 | HOSTARCH="amd64" |
| 141 | fi |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 142 | |
| 143 | # Retrieve versioned voltctl binary |
| 144 | download_url="https://github.com/opencord/voltctl/releases/download" |
| 145 | vol_ver="v${voltctlVersion}" |
| 146 | vol_name="voltctl-${voltctlVersion}-\${HOSTOS}-\${HOSTARCH}" |
Joey Armstrong | b2f8981 | 2022-11-24 08:09:40 -0500 | [diff] [blame] | 147 | curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}" |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 148 | |
Joey Armstrong | a935e71 | 2022-11-24 08:03:15 -0500 | [diff] [blame] | 149 | chmod u=rwx,go=rx "\$bin_voltctl" |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 150 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 151 | # --------------------------------------------------------- |
| 152 | # /usr/local/bin/voltctl --version != bin/voltctl --version |
| 153 | # Problem when default searchpath has not been modified. |
| 154 | # --------------------------------------------------------- |
Joey Armstrong | a935e71 | 2022-11-24 08:03:15 -0500 | [diff] [blame] | 155 | "\${bin_voltctl}" version --clientonly |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 156 | voltctl version --clientonly |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 157 | """) |
Joey Armstrong | 299f1f3 | 2022-11-24 08:45:25 -0500 | [diff] [blame] | 158 | |
Roger Luethi | 218b853 | 2023-09-28 14:19:50 +0200 | [diff] [blame] | 159 | sh( |
| 160 | label : 'Write /home/jenkins/.volt/config', |
| 161 | returnStdout: false, |
| 162 | script: """#!/bin/bash |
| 163 | |
| 164 | bin_voltctl="$WORKSPACE/bin/voltctl" |
| 165 | |
| 166 | mkdir -p "/home/jenkins/.volt" |
| 167 | rm -f "/home/jenkins/.volt/config" |
| 168 | "\${bin_voltctl}" config > "/home/jenkins/.volt/config" |
| 169 | """) |
| 170 | |
Roger Luethi | ff337d8 | 2023-09-20 12:09:44 +0200 | [diff] [blame] | 171 | leave('process') |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 172 | return(ans) |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 173 | } |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 174 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 175 | // ----------------------------------------------------------------------- |
| 176 | // ----------------------------------------------------------------------- |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 177 | def call(String branch) { |
| 178 | try { |
| 179 | enter('main') |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 180 | process(branch) |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 181 | } |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 182 | catch (Exception err) { // groovylint-disable-line CatchException |
| 183 | String iam = getIam('main') |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame] | 184 | println("** ${iam}: EXCEPTION ${err}") |
| 185 | throw err |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 186 | } |
Joey Armstrong | 97af219 | 2023-09-05 17:06:41 -0400 | [diff] [blame] | 187 | finally { |
| 188 | leave('main') |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 189 | } |
| 190 | return |
| 191 | } |
| 192 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 193 | // [EOF] |