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 | // ----------------------------------------------------------------------- |
| 22 | def getIam(String func) |
| 23 | { |
| 24 | // Cannot rely on a stack trace due to jenkins manipulation |
| 25 | String src = 'vars/installVoltctl.groovy' |
| 26 | String iam = [src, func].join('::') |
| 27 | return iam |
| 28 | } |
| 29 | |
| 30 | // ----------------------------------------------------------------------- |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 31 | // Intent: Assign perms to fix access problems |
| 32 | // . /bin/sh: 1: /home/jenkins/.volt/config: Permission denied |
| 33 | // ----------------------------------------------------------------------- |
| 34 | def fixPerms() { |
| 35 | |
| 36 | String iam = 'vars/installVoltctl.groovy' |
| 37 | println("** ${iam}: ENTER") |
| 38 | |
| 39 | sh( |
| 40 | label: 'fixperms', |
| 41 | script : """ |
| 42 | |
| 43 | umask 022 |
| 44 | |
| 45 | volt_dir='~/.volt' |
| 46 | volt_cfg='~/.volt/config' |
| 47 | |
| 48 | echo |
| 49 | echo "** Fixing perms: $volt_cfg" |
| 50 | mkdir -p "$volt_dir" |
| 51 | chmod -R u+w,go-rwx "$volt_dir" |
| 52 | chmod u=rwx "$volt_dir" |
| 53 | touch "$volt_conf" |
| 54 | /bin/ls -l "$volt_dir" |
| 55 | """) |
| 56 | return |
| 57 | } |
| 58 | |
| 59 | // ----------------------------------------------------------------------- |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 60 | // ----------------------------------------------------------------------- |
| 61 | def process(String branch) { |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 62 | |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 63 | String iam = 'vars/installVoltctl.groovy' |
Joey Armstrong | 299f1f3 | 2022-11-24 08:45:25 -0500 | [diff] [blame] | 64 | println("** ${iam}: ENTER") |
| 65 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 66 | // This logic seems odd given we branch & tag repositories |
| 67 | // for release so hilight non-frozen until we know for sure. |
| 68 | def released=[ |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 69 | // v1.9.1 - https://github.com/opencord/voltctl/releases/tag/untagged-cd611c39178f25b95a87 |
| 70 | 'voltha-2.12' : '1.8.45', |
| 71 | 'voltha-2.11' : '1.8.45', |
| 72 | // https://github.com/opencord/voltctl/releases/tag/v1.7.6 |
| 73 | 'voltha-2.10' : '1.7.6', |
| 74 | 'voltha-2.9' : '1.7.4', |
| 75 | 'voltha-2.8' : '1.6.11', |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 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 | boolean have_released = released.containsKey(branch) |
| 79 | boolean is_release = false |
| 80 | // TODO: Enable with parameter: RELEASE_VOLTHA= |
| 81 | boolean has_binding = binding.hasVariable('WORKSPACE') |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 82 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 83 | // WIP: Probe to find out what is available |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 84 | print(""" |
| 85 | ** have_released: ${have_released} |
| 86 | ** has_binding: ${has_binding} |
| 87 | """) |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 88 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 89 | // --------------------------------------------- |
| 90 | // Sanity check: released version must be frozen |
| 91 | // --------------------------------------------- |
| 92 | if (is_release && ! released.containsKey(branch)) { |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 93 | // Fingers crossed: jenkins may rewrite the callstack. |
| 94 | def myname = this.class.getName() |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 95 | |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 96 | String url = [ |
| 97 | 'https://docs.voltha.org/master', |
| 98 | 'howto/release/installVoltctl.html', |
| 99 | ].join('/') |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 100 | |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 101 | String error = [ |
| 102 | myname, "ERROR:", |
| 103 | "Detected release version=[$branch]", |
| 104 | "but voltctl is not frozen.", |
| 105 | '', |
| 106 | "See Also:", url, |
| 107 | ].join(' ') |
| 108 | throw new Exception(error) |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | // -------------------------------- |
| 112 | // General answer: latest available |
| 113 | // -------------------------------- |
| 114 | if (! have_released) { |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 115 | url = 'https://api.github.com/repos/opencord/voltctl/releases/latest' |
| 116 | get_version = [ |
| 117 | "curl -sSL ${url}", |
| 118 | "jq -r .tag_name", |
| 119 | "sed -e 's/^v//g'", |
| 120 | ].join(' | ') |
| 121 | |
| 122 | print(" ** RUNNING: ${get_version}") |
| 123 | released[branch] = sh ( |
| 124 | script: get_version, |
| 125 | returnStdout: true |
| 126 | ).trim() |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | voltctlVersion = released[branch] |
| 130 | println "Installing voltctl version ${voltctlVersion} on branch ${branch}" |
| 131 | |
| 132 | // ----------------------------------------------------------------------- |
| 133 | // groovy expansion: ${var} |
| 134 | // shell expansion: \${var} |
| 135 | // ----------------------------------------------------------------------- |
| 136 | sh returnStdout: false, script: """#!/bin/bash |
| 137 | |
Joey Armstrong | b65ada3 | 2023-08-03 12:50:20 -0400 | [diff] [blame] | 138 | # set -eu -o pipefail |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 139 | |
| 140 | bin_voltctl="$WORKSPACE/bin/voltctl" |
| 141 | |
| 142 | mkdir -p "$WORKSPACE/bin" |
| 143 | cd "$WORKSPACE" || { echo "ERROR: cd $WORKSPACE failed"; exit 1; } |
| 144 | |
| 145 | HOSTOS="\$(uname -s | tr '[:upper:]' '[:lower:]')" |
| 146 | HOSTARCH="\$(uname -m | tr '[:upper:]' '[:lower:]')" |
| 147 | if [ "\$HOSTARCH" == "x86_64" ]; then |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 148 | HOSTARCH="amd64" |
| 149 | fi |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 150 | |
| 151 | # Retrieve versioned voltctl binary |
| 152 | download_url="https://github.com/opencord/voltctl/releases/download" |
| 153 | vol_ver="v${voltctlVersion}" |
| 154 | vol_name="voltctl-${voltctlVersion}-\${HOSTOS}-\${HOSTARCH}" |
Joey Armstrong | b2f8981 | 2022-11-24 08:09:40 -0500 | [diff] [blame] | 155 | curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}" |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 156 | |
Joey Armstrong | a935e71 | 2022-11-24 08:03:15 -0500 | [diff] [blame] | 157 | chmod u=rwx,go=rx "\$bin_voltctl" |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 158 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 159 | # --------------------------------------------------------- |
| 160 | # /usr/local/bin/voltctl --version != bin/voltctl --version |
| 161 | # Problem when default searchpath has not been modified. |
| 162 | # --------------------------------------------------------- |
Joey Armstrong | a935e71 | 2022-11-24 08:03:15 -0500 | [diff] [blame] | 163 | "\${bin_voltctl}" version --clientonly |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 164 | voltctl version --clientonly |
| 165 | """ |
Joey Armstrong | 299f1f3 | 2022-11-24 08:45:25 -0500 | [diff] [blame] | 166 | |
| 167 | println("** ${iam}: LEAVE") |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 168 | return |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 169 | } |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 170 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 171 | // ----------------------------------------------------------------------- |
| 172 | // ----------------------------------------------------------------------- |
| 173 | def call(String branch) |
| 174 | { |
| 175 | String iam = getIam('main') |
| 176 | println("** ${iam}: ENTER") |
| 177 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 178 | try |
| 179 | { |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 180 | fixPerms() |
| 181 | process(branch) |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 182 | } |
| 183 | catch (Exception err) |
| 184 | { |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 185 | println("** ${iam}: EXCEPTION ${err}") |
| 186 | throw err |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 187 | } |
| 188 | finally |
| 189 | { |
Joey Armstrong | 9d35c0f | 2023-08-25 21:35:54 -0400 | [diff] [blame^] | 190 | println("** ${iam}: LEAVE") |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 191 | } |
| 192 | return |
| 193 | } |
| 194 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 195 | // [EOF] |