blob: 55b56c25eed28fbb798408865fbd9d6419667148 [file] [log] [blame]
Joey Armstrong97643b32022-11-14 17:33:27 -05001#!/usr/bin/env groovy
Joey Armstrong379660e2022-12-14 19:21:00 -05002// -----------------------------------------------------------------------
Joey Armstrongaf679da2023-01-31 14:22:41 -05003// 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 Armstrong379660e2022-12-14 19:21:00 -050017// Install the voltctl command by branch name "voltha-xx"
18// -----------------------------------------------------------------------
Joey Armstrong97643b32022-11-14 17:33:27 -050019
Joey Armstrong379660e2022-12-14 19:21:00 -050020// -----------------------------------------------------------------------
21// -----------------------------------------------------------------------
22def 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 Armstrong9d35c0f2023-08-25 21:35:54 -040031// Intent: Assign perms to fix access problems
32// . /bin/sh: 1: /home/jenkins/.volt/config: Permission denied
33// -----------------------------------------------------------------------
34def 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 Armstrong379660e2022-12-14 19:21:00 -050060// -----------------------------------------------------------------------
61def process(String branch) {
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070062
Joey Armstrong96158a92022-11-25 10:36:06 -050063 String iam = 'vars/installVoltctl.groovy'
Joey Armstrong299f1f32022-11-24 08:45:25 -050064 println("** ${iam}: ENTER")
65
Joey Armstrong97643b32022-11-14 17:33:27 -050066 // 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 Armstrong9d35c0f2023-08-25 21:35:54 -040069 // 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 Armstrong97643b32022-11-14 17:33:27 -050076 ]
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070077
Joey Armstrong97643b32022-11-14 17:33:27 -050078 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 Scandolob47a6fd2021-10-27 17:02:49 -070082
Joey Armstrong97643b32022-11-14 17:33:27 -050083 // WIP: Probe to find out what is available
Joey Armstrong96158a92022-11-25 10:36:06 -050084 print("""
85** have_released: ${have_released}
86** has_binding: ${has_binding}
87""")
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070088
Joey Armstrong97643b32022-11-14 17:33:27 -050089 // ---------------------------------------------
90 // Sanity check: released version must be frozen
91 // ---------------------------------------------
92 if (is_release && ! released.containsKey(branch)) {
Joey Armstrong9d35c0f2023-08-25 21:35:54 -040093 // Fingers crossed: jenkins may rewrite the callstack.
94 def myname = this.class.getName()
Joey Armstrong97643b32022-11-14 17:33:27 -050095
Joey Armstrong9d35c0f2023-08-25 21:35:54 -040096 String url = [
97 'https://docs.voltha.org/master',
98 'howto/release/installVoltctl.html',
99 ].join('/')
Joey Armstrong97643b32022-11-14 17:33:27 -0500100
Joey Armstrong9d35c0f2023-08-25 21:35:54 -0400101 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 Armstrong97643b32022-11-14 17:33:27 -0500109 }
110
111 // --------------------------------
112 // General answer: latest available
113 // --------------------------------
114 if (! have_released) {
Joey Armstrong9d35c0f2023-08-25 21:35:54 -0400115 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 Armstrong97643b32022-11-14 17:33:27 -0500127 }
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 Armstrongb65ada32023-08-03 12:50:20 -0400138# set -eu -o pipefail
Joey Armstrong97643b32022-11-14 17:33:27 -0500139
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 Windlass9658cd22021-10-25 11:13:25 +0000148 HOSTARCH="amd64"
149 fi
Joey Armstrong97643b32022-11-14 17:33:27 -0500150
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 Armstrongb2f89812022-11-24 08:09:40 -0500155 curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}"
Joey Armstrong97643b32022-11-14 17:33:27 -0500156
Joey Armstronga935e712022-11-24 08:03:15 -0500157 chmod u=rwx,go=rx "\$bin_voltctl"
Joey Armstrong97643b32022-11-14 17:33:27 -0500158
Joey Armstrong379660e2022-12-14 19:21:00 -0500159 # ---------------------------------------------------------
160 # /usr/local/bin/voltctl --version != bin/voltctl --version
161 # Problem when default searchpath has not been modified.
162 # ---------------------------------------------------------
Joey Armstronga935e712022-11-24 08:03:15 -0500163 "\${bin_voltctl}" version --clientonly
Hardik Windlass9658cd22021-10-25 11:13:25 +0000164 voltctl version --clientonly
165 """
Joey Armstrong299f1f32022-11-24 08:45:25 -0500166
167 println("** ${iam}: LEAVE")
Joey Armstrong9d35c0f2023-08-25 21:35:54 -0400168 return
Hardik Windlass9658cd22021-10-25 11:13:25 +0000169}
Joey Armstrong97643b32022-11-14 17:33:27 -0500170
Joey Armstrong379660e2022-12-14 19:21:00 -0500171// -----------------------------------------------------------------------
172// -----------------------------------------------------------------------
173def call(String branch)
174{
175 String iam = getIam('main')
176 println("** ${iam}: ENTER")
177
Joey Armstrong379660e2022-12-14 19:21:00 -0500178 try
179 {
Joey Armstrong9d35c0f2023-08-25 21:35:54 -0400180 fixPerms()
181 process(branch)
Joey Armstrong379660e2022-12-14 19:21:00 -0500182 }
183 catch (Exception err)
184 {
Joey Armstrong9d35c0f2023-08-25 21:35:54 -0400185 println("** ${iam}: EXCEPTION ${err}")
186 throw err
Joey Armstrong379660e2022-12-14 19:21:00 -0500187 }
188 finally
189 {
Joey Armstrong9d35c0f2023-08-25 21:35:54 -0400190 println("** ${iam}: LEAVE")
Joey Armstrong379660e2022-12-14 19:21:00 -0500191 }
192 return
193}
194
Joey Armstrong97643b32022-11-14 17:33:27 -0500195// [EOF]