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) { |
| 55 | println(""" |
| 56 | |
| 57 | ** ----------------------------------------------------------------------- |
| 58 | ** ${message} |
| 59 | ** ----------------------------------------------------------------------- |
| 60 | """) |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | // ----------------------------------------------------------------------- |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 65 | // Intent: Perform volthaDeploy stuff |
| 66 | // ----------------------------------------------------------------------- |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame^] | 67 | void process(Map config) |
| 68 | { |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 69 | // 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] | 70 | // [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] | 71 | def defaultConfig = [ |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 72 | onosReplica: 1, |
| 73 | atomixReplica: 1, |
| 74 | kafkaReplica: 1, |
| 75 | etcdReplica: 1, |
| 76 | bbsimReplica: 1, |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame^] | 77 | infraNamespace : 'infra', |
| 78 | volthaNamespace : 'voltha', |
| 79 | stackName : 'voltha', |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 80 | stackId: 1, |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame^] | 81 | workflow : 'att', |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 82 | withMacLearning: false, |
| 83 | withFttb: false, |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame^] | 84 | extraHelmFlags : '', |
| 85 | localCharts: false, // Local or upstream (?) (for local we assume they are stored in $WORKSPACE/voltha-helm-charts) |
| 86 | dockerRegistry : '', // Different registry for images eg: "mirror.registry.opennetworking.org" |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 87 | kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable |
| 88 | withVolthaInfra: true, |
| 89 | withVolthaStack: true, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 90 | ] |
| 91 | |
| 92 | if (!config) { |
| 93 | config = [:] |
| 94 | } |
| 95 | |
| 96 | def cfg = defaultConfig + config |
| 97 | |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame^] | 98 | if (cfg.dockerRegistry != '') { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 99 | def registryFlags = " --set global.image_registry=${cfg.dockerRegistry}/ " |
| 100 | registryFlags += " --set etcd.image.registry=${cfg.dockerRegistry} " |
| 101 | registryFlags += " --set kafka.image.registry=${cfg.dockerRegistry} " |
| 102 | registryFlags += " --set kafka.zookeper.image.registry=${cfg.dockerRegistry} " |
| 103 | registryFlags += " --set onos-classic.image.repository=${cfg.dockerRegistry}/voltha/voltha-onos " |
| 104 | registryFlags += " --set onos-classic.atomix.image.repository=${cfg.dockerRegistry}/atomix/atomix " |
| 105 | registryFlags += " --set freeradius.images.radius.registry=${cfg.dockerRegistry}/ " |
Matteo Scandolo | 5244aaa | 2021-04-28 09:28:58 -0700 | [diff] [blame] | 106 | |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 107 | // we want to always leave the user provided flags at the end, to override changes |
| 108 | cfg.extraHelmFlags = registryFlags + " " + cfg.extraHelmFlags |
Matteo Scandolo | 37f168b | 2021-04-15 16:20:46 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame^] | 111 | // --------------------- |
| 112 | banner("Updating helm repos") |
Andrea Campanella | b29ca1e | 2021-05-06 17:45:27 +0200 | [diff] [blame] | 113 | |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 114 | sh(label : 'Configure helm repo', |
| 115 | script : """ |
| 116 | helm repo add onf https://charts.opencord.org |
| 117 | helm repo update |
| 118 | """) |
Andrea Campanella | b29ca1e | 2021-05-06 17:45:27 +0200 | [diff] [blame] | 119 | |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame^] | 120 | // --------------------- |
| 121 | banner("Deploying VOLTHA with the following parameters: ${cfg}") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 122 | |
Hardik Windlass | 230fca6 | 2022-05-04 08:50:35 +0530 | [diff] [blame] | 123 | if (cfg.withVolthaInfra) { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 124 | volthaInfraDeploy(cfg) |
Hardik Windlass | 230fca6 | 2022-05-04 08:50:35 +0530 | [diff] [blame] | 125 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 126 | |
Hardik Windlass | 230fca6 | 2022-05-04 08:50:35 +0530 | [diff] [blame] | 127 | if (cfg.withVolthaStack) { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 128 | volthaStackDeploy(cfg) |
Hardik Windlass | 230fca6 | 2022-05-04 08:50:35 +0530 | [diff] [blame] | 129 | } |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 130 | |
Joey Armstrong | 7f6c2c0 | 2024-02-11 14:15:24 -0500 | [diff] [blame^] | 131 | return |
| 132 | } |
| 133 | |
| 134 | // ----------------------------------------------------------------------- |
| 135 | // ----------------------------------------------------------------------- |
| 136 | def call(Map config=[:]) { // Function return type(?) |
| 137 | String iam = getIam('main') |
| 138 | Boolean ans = true |
| 139 | |
| 140 | try { |
| 141 | enter('main') |
| 142 | process(config) |
| 143 | } |
| 144 | catch (Exception err) { // groovylint-disable-line CatchException |
| 145 | ans = false |
| 146 | println("** ${iam}: EXCEPTION ${err}") |
| 147 | throw err |
| 148 | } |
| 149 | finally { |
| 150 | leave('main') |
| 151 | } |
| 152 | |
| 153 | return(ans) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 154 | } |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 155 | |
| 156 | // [EOF] |