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