Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | 518f357 | 2024-02-11 07:56:25 -0500 | [diff] [blame] | 3 | // Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 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 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 17 | // this keyword is dedicated to deploy a single VOLTHA stack with infra |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 18 | // If you need to deploy different configurations you can use the |
| 19 | // volthaInfraDeploy and volthaStackDeploy DSL keywords |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 20 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 21 | |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 22 | // ----------------------------------------------------------------------- |
| 23 | // ----------------------------------------------------------------------- |
| 24 | String getIam(String func) { |
| 25 | // Cannot rely on a stack trace due to jenkins manipulation |
| 26 | String src = 'vars/volthaDeploy.groovy' |
| 27 | String iam = [src, func].join('::') |
| 28 | return iam |
| 29 | } |
| 30 | |
| 31 | // ----------------------------------------------------------------------- |
| 32 | // Intent: Log progress message |
| 33 | // ----------------------------------------------------------------------- |
| 34 | void enter(String name) { |
| 35 | // Announce ourselves for log usability |
| 36 | String iam = getIam(name) |
| 37 | println("${iam}: ENTER") |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | // ----------------------------------------------------------------------- |
| 42 | // Intent: Log progress message |
| 43 | // ----------------------------------------------------------------------- |
| 44 | void leave(String name) { |
| 45 | // Announce ourselves for log usability |
| 46 | String iam = getIam(name) |
| 47 | println("${iam}: LEAVE") |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | // ----------------------------------------------------------------------- |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 52 | // Intent: Display a message with visibility for logging |
| 53 | // ----------------------------------------------------------------------- |
| 54 | String banner(String message) { |
Joey Armstrong | f023276 | 2024-02-11 17:23:04 -0500 | [diff] [blame] | 55 | String iam = getIam('banner') |
| 56 | |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 57 | println(""" |
| 58 | |
| 59 | ** ----------------------------------------------------------------------- |
Joey Armstrong | f023276 | 2024-02-11 17:23:04 -0500 | [diff] [blame] | 60 | ** IAM: $iam |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 61 | ** ${message} |
| 62 | ** ----------------------------------------------------------------------- |
| 63 | """) |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | // ----------------------------------------------------------------------- |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 68 | // Intent: Perform volthaDeploy stuff |
| 69 | // ----------------------------------------------------------------------- |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 70 | void process(Map config) |
| 71 | { |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 72 | // note that I can't define this outside the function as there's no global scope in Groovy |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 73 | // [joey] A class method or library call can be used in place of globals, fqdn needed. |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 74 | def defaultConfig = [ |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 75 | onosReplica: 1, |
| 76 | atomixReplica: 1, |
| 77 | kafkaReplica: 1, |
| 78 | etcdReplica: 1, |
| 79 | bbsimReplica: 1, |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 80 | infraNamespace : 'infra', |
| 81 | volthaNamespace : 'voltha', |
| 82 | stackName : 'voltha', |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 83 | stackId: 1, |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 84 | workflow : 'att', |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 85 | withMacLearning: false, |
| 86 | withFttb: false, |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 87 | extraHelmFlags : '', |
| 88 | localCharts: false, // Local or upstream (?) (for local we assume they are stored in $WORKSPACE/voltha-helm-charts) |
| 89 | dockerRegistry : '', // Different registry for images eg: "mirror.registry.opennetworking.org" |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 90 | kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable |
| 91 | withVolthaInfra: true, |
| 92 | withVolthaStack: true, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 93 | ] |
| 94 | |
| 95 | if (!config) { |
| 96 | config = [:] |
| 97 | } |
| 98 | |
| 99 | def cfg = defaultConfig + config |
| 100 | |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 101 | if (cfg.dockerRegistry != '') { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 102 | def registryFlags = " --set global.image_registry=${cfg.dockerRegistry}/ " |
| 103 | registryFlags += " --set etcd.image.registry=${cfg.dockerRegistry} " |
| 104 | registryFlags += " --set kafka.image.registry=${cfg.dockerRegistry} " |
| 105 | registryFlags += " --set kafka.zookeper.image.registry=${cfg.dockerRegistry} " |
| 106 | registryFlags += " --set onos-classic.image.repository=${cfg.dockerRegistry}/voltha/voltha-onos " |
| 107 | registryFlags += " --set onos-classic.atomix.image.repository=${cfg.dockerRegistry}/atomix/atomix " |
| 108 | registryFlags += " --set freeradius.images.radius.registry=${cfg.dockerRegistry}/ " |
Matteo Scandolo | 5244aaa | 2021-04-28 09:28:58 -0700 | [diff] [blame] | 109 | |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 110 | // we want to always leave the user provided flags at the end, to override changes |
| 111 | cfg.extraHelmFlags = registryFlags + " " + cfg.extraHelmFlags |
Matteo Scandolo | 37f168b | 2021-04-15 16:20:46 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 114 | // --------------------- |
| 115 | banner("Updating helm repos") |
Andrea Campanella | b29ca1e | 2021-05-06 17:45:27 +0200 | [diff] [blame] | 116 | |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 117 | sh(label : 'Configure helm repo', |
| 118 | script : """ |
| 119 | helm repo add onf https://charts.opencord.org |
| 120 | helm repo update |
| 121 | """) |
Andrea Campanella | b29ca1e | 2021-05-06 17:45:27 +0200 | [diff] [blame] | 122 | |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 123 | // --------------------- |
| 124 | banner("Deploying VOLTHA with the following parameters: ${cfg}") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 125 | |
Hardik Windlass | 230fca6 | 2022-05-04 08:50:35 +0530 | [diff] [blame] | 126 | if (cfg.withVolthaInfra) { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 127 | volthaInfraDeploy(cfg) |
Hardik Windlass | 230fca6 | 2022-05-04 08:50:35 +0530 | [diff] [blame] | 128 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 129 | |
Hardik Windlass | 230fca6 | 2022-05-04 08:50:35 +0530 | [diff] [blame] | 130 | if (cfg.withVolthaStack) { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 131 | volthaStackDeploy(cfg) |
Hardik Windlass | 230fca6 | 2022-05-04 08:50:35 +0530 | [diff] [blame] | 132 | } |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 133 | |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame] | 134 | return |
| 135 | } |
| 136 | |
| 137 | // ----------------------------------------------------------------------- |
| 138 | // ----------------------------------------------------------------------- |
| 139 | def call(Map config=[:]) { // Function return type(?) |
| 140 | String iam = getIam('main') |
| 141 | Boolean ans = true |
| 142 | |
| 143 | try { |
| 144 | enter('main') |
| 145 | process(config) |
| 146 | } |
| 147 | catch (Exception err) { // groovylint-disable-line CatchException |
| 148 | ans = false |
| 149 | println("** ${iam}: EXCEPTION ${err}") |
| 150 | throw err |
| 151 | } |
| 152 | finally { |
| 153 | leave('main') |
| 154 | } |
| 155 | |
| 156 | return(ans) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 157 | } |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 158 | |
| 159 | // [EOF] |