Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 1 | #!/bin/bash -x |
| 2 | # |
| 3 | # Copyright 2018 Huawei Technologies Co., Ltd. |
| 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 | |
| 12 | # allow root login |
| 13 | export HOME=/root |
| 14 | mkdir -p ~/.ssh |
| 15 | cp ~ubuntu/.ssh/authorized_keys ~/.ssh |
| 16 | |
| 17 | export DEBIAN_FRONTEND=noninteractive |
| 18 | HOST_IP=$(hostname -I) |
| 19 | echo $HOST_IP `hostname` >> /etc/hosts |
| 20 | printenv |
| 21 | |
| 22 | mkdir -p /opt/config |
Gary Wu | 9bb778b | 2019-06-21 16:16:18 -0700 | [diff] [blame] | 23 | echo "__nfs_volume_id__" > /opt/config/nfs_volume_id.txt |
Gary Wu | d95bf2b | 2019-06-21 15:35:18 -0700 | [diff] [blame] | 24 | echo "__nfs_ip_addr__" > /opt/config/nfs_ip_addr.txt |
Gary Wu | 9bb778b | 2019-06-21 16:16:18 -0700 | [diff] [blame] | 25 | echo "__nfs_private_ip_addr__" > /opt/config/nfs_private_ip_addr.txt |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 26 | echo "__k8s_vm_ips__" > /opt/config/k8s_vm_ips.txt |
| 27 | echo "__k8s_private_ips__" > /opt/config/k8s_private_ips.txt |
| 28 | echo "__public_net_id__" > /opt/config/public_net_id.txt |
| 29 | echo "__oam_network_cidr__" > /opt/config/oam_network_cidr.txt |
| 30 | echo "__oam_network_id__" > /opt/config/oam_network_id.txt |
| 31 | echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt |
| 32 | echo "__sec_group__" > /opt/config/sec_group.txt |
| 33 | echo "__integration_gerrit_branch__" > /opt/config/integration_gerrit_branch.txt |
| 34 | echo "__integration_gerrit_refspec__" > /opt/config/integration_gerrit_refspec.txt |
| 35 | echo "__oom_gerrit_branch__" > /opt/config/oom_gerrit_branch.txt |
| 36 | echo "__oom_gerrit_refspec__" > /opt/config/oom_gerrit_refspec.txt |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 37 | echo "__docker_proxy__" > /opt/config/docker_proxy.txt |
| 38 | echo "__docker_version__" > /opt/config/docker_version.txt |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 39 | echo "__kubectl_version__" > /opt/config/kubectl_version.txt |
| 40 | echo "__helm_version__" > /opt/config/helm_version.txt |
| 41 | echo "__helm_deploy_delay__" > /opt/config/helm_deploy_delay.txt |
| 42 | echo "__mtu__" > /opt/config/mtu.txt |
| 43 | echo "__portal_hostname__" > /opt/config/portal_hostname.txt |
| 44 | |
| 45 | cat <<EOF > /opt/config/integration-override.yaml |
| 46 | __integration_override_yaml__ |
| 47 | EOF |
| 48 | sed -i 's/\_\_portal_hostname__/__portal_hostname__/g' /opt/config/integration-override.yaml |
| 49 | sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml |
| 50 | sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml |
| 51 | sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml |
| 52 | sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml |
| 53 | sed -i 's/\_\_sec_group__/__sec_group__/g' /opt/config/integration-override.yaml |
Gary Wu | d95bf2b | 2019-06-21 15:35:18 -0700 | [diff] [blame] | 54 | sed -i 's/\_\_nfs_ip_addr__/__nfs_ip_addr__/g' /opt/config/integration-override.yaml |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 55 | sed -i 's/\_\_k8s_01_vm_ip__/__k8s_01_vm_ip__/g' /opt/config/integration-override.yaml |
| 56 | sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml |
| 57 | cp /opt/config/integration-override.yaml /root |
| 58 | cat /root/integration-override.yaml |
| 59 | |
| 60 | mkdir -p /etc/docker |
| 61 | if [ ! -z "__docker_proxy__" ]; then |
| 62 | cat > /etc/docker/daemon.json <<EOF |
| 63 | { |
| 64 | "mtu": __mtu__, |
| 65 | "insecure-registries" : ["__docker_proxy__"] |
| 66 | } |
| 67 | EOF |
| 68 | else |
| 69 | cat > /etc/docker/daemon.json <<EOF |
| 70 | { |
| 71 | "mtu": __mtu__ |
| 72 | } |
| 73 | EOF |
| 74 | fi |
| 75 | if [ ! -z "__apt_proxy__" ]; then |
| 76 | cat > /etc/apt/apt.conf.d/30proxy<<EOF |
| 77 | Acquire::http { Proxy "http://__apt_proxy__"; }; |
| 78 | Acquire::https::Proxy "DIRECT"; |
| 79 | EOF |
| 80 | fi |
| 81 | |
| 82 | # workaround for OpenStack intermittent failure to change default apt mirrors |
| 83 | sed -i 's|http://archive.ubuntu.com|http://nova.clouds.archive.ubuntu.com|g' /etc/apt/sources.list |
| 84 | |
| 85 | while ! hash jq &> /dev/null; do |
| 86 | apt-get -y update |
Gary Wu | 9bb778b | 2019-06-21 16:16:18 -0700 | [diff] [blame] | 87 | apt-get -y install curl jq make nfs-kernel-server moreutils zfsutils-linux |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 88 | sleep 10 |
| 89 | done |
| 90 | |
Gary Wu | 06b0812 | 2019-06-21 23:15:55 -0700 | [diff] [blame] | 91 | sed -i 's/RPCNFSDCOUNT=.*/RPCNFSDCOUNT=32/' /etc/default/nfs-kernel-server |
| 92 | service nfs-kernel-server restart |
| 93 | |
Gary Wu | 9bb778b | 2019-06-21 16:16:18 -0700 | [diff] [blame] | 94 | nfs_volume_dev="/dev/disk/by-id/virtio-$(echo "__nfs_volume_id__" | cut -c -20)" |
| 95 | |
Konrad Bańka | a3990d0 | 2019-07-30 09:02:42 +0200 | [diff] [blame] | 96 | until [ -b "$nfs_volume_dev" ]; do |
| 97 | sleep 1m |
| 98 | done |
| 99 | |
Brian Freeman | 1160da4 | 2019-08-14 17:28:09 -0500 | [diff] [blame] | 100 | zpool create -f -m /dockerdata-nfs-z dockerdata-nfs-z $nfs_volume_dev |
| 101 | zfs set compression=lz4 dockerdata-nfs-z |
| 102 | zfs set sharenfs="rw=*" dockerdata-nfs-z |
| 103 | |
| 104 | |
| 105 | mkdir -p /dockerdata-nfs |
| 106 | |
| 107 | |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 108 | |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 109 | # update and initialize git |
Konrad Bańka | a3990d0 | 2019-07-30 09:02:42 +0200 | [diff] [blame] | 110 | git config --system user.email root@nfs |
| 111 | git config --system user.name root@nfs |
| 112 | git config --system log.decorate auto |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 113 | |
| 114 | # version control the persistence volume to see what's happening |
| 115 | chmod 777 /dockerdata-nfs/ |
| 116 | chown nobody:nogroup /dockerdata-nfs/ |
| 117 | cd /dockerdata-nfs/ |
| 118 | git init |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 119 | git add -A |
Konrad Bańka | a3990d0 | 2019-07-30 09:02:42 +0200 | [diff] [blame] | 120 | git commit -m "initial commit" --allow-empty |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 121 | |
Gary Wu | 0bc6983 | 2019-03-27 13:58:46 -0700 | [diff] [blame] | 122 | |
Brian Freeman | 1160da4 | 2019-08-14 17:28:09 -0500 | [diff] [blame] | 123 | # export NFS mount |
| 124 | echo "/dockerdata-nfs *(rw,fsid=1,async,no_root_squash,no_subtree_check)" | tee /etc/exports |
| 125 | exportfs -a |
| 126 | systemctl restart nfs-kernel-server |
Gary Wu | 0bc6983 | 2019-03-27 13:58:46 -0700 | [diff] [blame] | 127 | |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 128 | cd ~ |
| 129 | |
| 130 | # install kubectl __kubectl_version__ |
| 131 | curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v__kubectl_version__/bin/linux/amd64/kubectl |
| 132 | chmod +x ./kubectl |
| 133 | sudo mv ./kubectl /usr/local/bin/kubectl |
Gary Wu | 0bc6983 | 2019-03-27 13:58:46 -0700 | [diff] [blame] | 134 | mkdir -p ~/.kube |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 135 | |
| 136 | # install helm __helm_version__ |
| 137 | mkdir -p helm |
| 138 | pushd helm |
| 139 | wget -q http://storage.googleapis.com/kubernetes-helm/helm-v__helm_version__-linux-amd64.tar.gz |
| 140 | tar -zxvf helm-v__helm_version__-linux-amd64.tar.gz |
| 141 | sudo cp linux-amd64/helm /usr/local/bin/helm |
| 142 | popd |
| 143 | |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 144 | |
| 145 | |
| 146 | |
Gary Wu | 0bc6983 | 2019-03-27 13:58:46 -0700 | [diff] [blame] | 147 | # Clone OOM repo |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 148 | cd ~ |
Gary Wu | abf01f7 | 2019-04-30 08:08:28 -0700 | [diff] [blame] | 149 | git clone --recurse-submodules -b __oom_gerrit_branch__ https://gerrit.onap.org/r/oom |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 150 | cd oom |
| 151 | if [ ! -z "__oom_gerrit_refspec__" ]; then |
| 152 | git fetch https://gerrit.onap.org/r/oom __oom_gerrit_refspec__ |
| 153 | git checkout FETCH_HEAD |
| 154 | fi |
| 155 | git checkout -b workarounds |
| 156 | git log -1 |
| 157 | |
Gary Wu | 0bc6983 | 2019-03-27 13:58:46 -0700 | [diff] [blame] | 158 | # Clone integration repo |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 159 | cd ~ |
| 160 | git clone -b __integration_gerrit_branch__ https://gerrit.onap.org/r/integration |
| 161 | cd integration |
| 162 | if [ ! -z "__integration_gerrit_refspec__" ]; then |
| 163 | git fetch https://gerrit.onap.org/r/integration __integration_gerrit_refspec__ |
| 164 | git checkout FETCH_HEAD |
| 165 | fi |
| 166 | |
| 167 | |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 168 | cd ~/oom |
| 169 | # workaround to change onap portal cookie domain |
Gary Wu | a7f1a94 | 2019-04-15 09:09:20 -0700 | [diff] [blame] | 170 | #sed -i "s/^cookie_domain.*=.*/cookie_domain = __portal_hostname__/g" ./kubernetes/portal/charts/portal-app/resources/config/deliveries/properties/ONAPPORTAL/system.properties |
| 171 | #sed -i "s/^cookie_domain.*=.*/cookie_domain = __portal_hostname__/g" ./kubernetes/portal/charts/portal-sdk/resources/config/deliveries/properties/ONAPPORTALSDK/system.properties |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 172 | git diff |
| 173 | git commit -a -m "set portal cookie domain" |
| 174 | |
| 175 | git tag -a "deploy0" -m "initial deployment" |
| 176 | |
| 177 | |
Gary Wu | 0bc6983 | 2019-03-27 13:58:46 -0700 | [diff] [blame] | 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | # wait for /root/.kube/config to show up; will be placed by deploy script after RKE completes |
| 184 | while [ ! -e /root/.kube/config ]; do |
| 185 | sleep 1m |
| 186 | done |
| 187 | |
| 188 | |
| 189 | NAMESPACE=onap |
| 190 | export KUBECONFIG=/root/.kube/config |
| 191 | kubectl config set-context $(kubectl config current-context) --namespace=$NAMESPACE |
| 192 | kubectl config view |
| 193 | |
| 194 | |
| 195 | # Enable auto-completion for kubectl |
| 196 | echo "source <(kubectl completion bash)" >> ~/.bashrc |
| 197 | |
| 198 | |
| 199 | until [ $(kubectl get cs | tail -n +2 | grep -c Healthy) -ge 5 ]; do |
| 200 | sleep 1m |
| 201 | done |
| 202 | |
| 203 | |
| 204 | # install tiller/helm |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 205 | kubectl -n kube-system create serviceaccount tiller |
| 206 | kubectl create clusterrolebinding tiller --clusterrole=cluster-admin --serviceaccount=kube-system:tiller |
| 207 | helm init --service-account tiller |
| 208 | kubectl -n kube-system rollout status deploy/tiller-deploy |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 209 | helm serve & |
| 210 | sleep 10 |
Gary Wu | 0bc6983 | 2019-03-27 13:58:46 -0700 | [diff] [blame] | 211 | |
| 212 | # Make ONAP helm charts |
| 213 | cd ~/oom/kubernetes/ |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 214 | helm repo add local http://127.0.0.1:8879 |
| 215 | helm repo list |
| 216 | make all |
| 217 | helm search -l | grep local |
| 218 | |
| 219 | # install helm deploy plugin |
| 220 | rsync -avt ~/oom/kubernetes/helm/plugins ~/.helm/ |
| 221 | # temporary workaround to throttle the helm deploy to alleviate startup disk contention issues |
| 222 | if [ ! -z "__helm_deploy_delay__" ]; then |
| 223 | sed -i "/\^enabled:/a\ echo sleep __helm_deploy_delay__\n sleep __helm_deploy_delay__" ~/.helm/plugins/deploy/deploy.sh |
Gary Wu | a56df52 | 2019-06-07 00:34:43 -0700 | [diff] [blame] | 224 | sed -i 's/for subchart in \*/for subchart in aaf cassandra mariadb-galera dmaap */' ~/.helm/plugins/deploy/deploy.sh |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 225 | fi |
| 226 | |
Gary Wu | 0bc6983 | 2019-03-27 13:58:46 -0700 | [diff] [blame] | 227 | # Deploy ONAP |
Brian Freeman | a2b0671 | 2019-10-31 12:28:25 -0500 | [diff] [blame] | 228 | if [ ! -z "__additional_override__" ]; then |
| 229 | helm deploy dev local/onap -f ~/oom/kubernetes/onap/resources/environments/public-cloud.yaml -f ~/integration-override.yaml -f __additional_override__ --namespace $NAMESPACE –verbose |
| 230 | else |
| 231 | helm deploy dev local/onap -f ~/oom/kubernetes/onap/resources/environments/public-cloud.yaml -f ~/integration-override.yaml --namespace $NAMESPACE –verbose |
| 232 | fi |
| 233 | |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 234 | |
| 235 | # re-install original helm deploy plugin |
| 236 | rsync -avt ~/oom/kubernetes/helm/plugins ~/.helm/ |
| 237 | |
| 238 | helm list |
| 239 | |
| 240 | |
| 241 | |
| 242 | # Check ONAP status: |
| 243 | sleep 10 |
| 244 | kubectl get pods --all-namespaces |
| 245 | kubectl get nodes |
| 246 | kubectl top nodes |