blob: 2eabf4e3e110340c2adbb0f39622117200059f60 [file] [log] [blame]
Gary Wu1ff56672018-01-17 20:51:45 -08001#!/bin/bash -x
Gary Wua3fb86f2018-06-04 16:23:54 -07002#
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
Gary Wu1ff56672018-01-17 20:51:45 -080012printenv
13
Gary Wu14a6b302018-05-01 15:59:28 -070014mkdir -p /opt/config
15echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt
16echo "__k8s_vm_ips__" > /opt/config/k8s_vm_ips.txt
Gary Wuad513722018-07-26 13:08:47 -070017echo "__k8s_private_ips__" > /opt/config/k8s_private_ips.txt
Gary Wu978171e2018-07-24 11:56:01 -070018echo "__public_net_id__" > /opt/config/public_net_id.txt
19echo "__oam_network_cidr__" > /opt/config/oam_network_cidr.txt
Gary Wu11c98742018-05-02 16:19:04 -070020echo "__oam_network_id__" > /opt/config/oam_network_id.txt
21echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt
Gary Wu87aa8b52018-08-09 08:10:24 -070022echo "__integration_gerrit_branch__" > /opt/config/integration_gerrit_branch.txt
23echo "__integration_gerrit_refspec__" > /opt/config/integration_gerrit_refspec.txt
24echo "__oom_gerrit_branch__" > /opt/config/oom_gerrit_branch.txt
25echo "__oom_gerrit_refspec__" > /opt/config/oom_gerrit_refspec.txt
Gary Wu81836d22018-06-22 13:48:50 -070026echo "__docker_manifest__" > /opt/config/docker_manifest.txt
Gary Wu978171e2018-07-24 11:56:01 -070027echo "__docker_proxy__" > /opt/config/docker_proxy.txt
Gary Wu7a04b3d2018-08-15 12:31:46 -070028echo "__docker_version__" > /opt/config/docker_version.txt
29echo "__rancher_version__" > /opt/config/rancher_version.txt
30echo "__rancher_agent_version__" > /opt/config/rancher_agent_version.txt
31echo "__kubectl_version__" > /opt/config/kubectl_version.txt
32echo "__helm_version__" > /opt/config/helm_version.txt
Gary Wu11c98742018-05-02 16:19:04 -070033
34cat <<EOF > /opt/config/integration-override.yaml
35__integration_override_yaml__
36EOF
Gary Wu978171e2018-07-24 11:56:01 -070037sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml
38sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070039sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml
40sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml
Gary Wued95ca72018-07-26 10:24:51 -070041sed -i 's/\_\_rancher_ip_addr__/__rancher_ip_addr__/g' /opt/config/integration-override.yaml
Gary Wu0a671622018-05-14 12:59:03 -070042sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml
Gary Wu978171e2018-07-24 11:56:01 -070043sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070044cp /opt/config/integration-override.yaml /root
Gary Wu978171e2018-07-24 11:56:01 -070045cat /root/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -070046
Gary Wu1ff56672018-01-17 20:51:45 -080047echo `hostname -I` `hostname` >> /etc/hosts
48mkdir -p /etc/docker
Gary Wu3ad596f2018-02-08 07:16:37 -080049if [ ! -z "__docker_proxy__" ]; then
50 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080051{
52 "insecure-registries" : ["__docker_proxy__"]
53}
54EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080055fi
56if [ ! -z "__apt_proxy__" ]; then
57 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080058Acquire::http { Proxy "http://__apt_proxy__"; };
59Acquire::https::Proxy "DIRECT";
60EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080061fi
Gary Wu14a6b302018-05-01 15:59:28 -070062
Gary Wub0e36502018-10-16 11:01:07 -070063while ! hash jq &> /dev/null; do
64 apt-get -y update
65 apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server moreutils
66 sleep 10
67done
Gary Wu14a6b302018-05-01 15:59:28 -070068
Gary Wuc4749702018-06-26 14:27:41 -070069# use RAM disk for /dockerdata-nfs for testing
Gary Wu1ac48832018-10-18 16:08:19 -070070echo "tmpfs /dockerdata-nfs tmpfs noatime,size=75% 1 2" >> /etc/fstab
Gary Wuece58582018-10-01 15:15:17 -070071mkdir -pv /dockerdata-nfs
Gary Wu1ac48832018-10-18 16:08:19 -070072mount /dockerdata-nfs
Gary Wuc4749702018-06-26 14:27:41 -070073
Gary Wu14a6b302018-05-01 15:59:28 -070074# version control the persistence volume to see what's happening
Gary Wu14a6b302018-05-01 15:59:28 -070075chmod 777 /dockerdata-nfs/
76chown nobody:nogroup /dockerdata-nfs/
77cd /dockerdata-nfs/
78git init
Gary Wu11c98742018-05-02 16:19:04 -070079git config user.email "root@onap"
Gary Wu14a6b302018-05-01 15:59:28 -070080git config user.name "root"
81git add -A
82git commit -m "initial commit"
83
84# export NFS mount
85NFS_EXP=""
Gary Wuad513722018-07-26 13:08:47 -070086for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_private_ips.txt); do
Gary Wu1ac48832018-10-18 16:08:19 -070087 NFS_EXP+="$K8S_VM_IP(rw,fsid=1,async,no_root_squash,no_subtree_check) "
Gary Wu14a6b302018-05-01 15:59:28 -070088done
89echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports
90
91
92exportfs -a
93systemctl restart nfs-kernel-server
94
95cd ~
96
Gary Wu7a04b3d2018-08-15 12:31:46 -070097# install docker __docker_version__
Gary Wub0e36502018-10-16 11:01:07 -070098while ! hash docker &> /dev/null; do
99 curl -s https://releases.rancher.com/install-docker/__docker_version__.sh | sh
100 usermod -aG docker ubuntu
101 sleep 10
102done
Gary Wu14a6b302018-05-01 15:59:28 -0700103
Gary Wu7a04b3d2018-08-15 12:31:46 -0700104# install rancher __rancher_version__
105docker run --restart unless-stopped -d -p 8080:8080 -e CATTLE_BOOTSTRAP_REQUIRED_IMAGE=__docker_proxy__/rancher/agent:v__rancher_agent_version__ __docker_proxy__/rancher/server:v__rancher_version__
Gary Wu14a6b302018-05-01 15:59:28 -0700106
Gary Wu7a04b3d2018-08-15 12:31:46 -0700107# install kubectl __kubectl_version__
108curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v__kubectl_version__/bin/linux/amd64/kubectl
Gary Wu14a6b302018-05-01 15:59:28 -0700109chmod +x ./kubectl
110sudo mv ./kubectl /usr/local/bin/kubectl
111mkdir ~/.kube
112
Gary Wu7a04b3d2018-08-15 12:31:46 -0700113# install helm __helm_version__
114wget -q http://storage.googleapis.com/kubernetes-helm/helm-v__helm_version__-linux-amd64.tar.gz
115tar -zxvf helm-v__helm_version__-linux-amd64.tar.gz
Gary Wu14a6b302018-05-01 15:59:28 -0700116sudo mv linux-amd64/helm /usr/local/bin/helm
117
Gary Wuad513722018-07-26 13:08:47 -0700118echo export RANCHER_IP=__rancher_private_ip_addr__ > api-keys-rc
Gary Wu14a6b302018-05-01 15:59:28 -0700119source api-keys-rc
120
Gary Wu14a6b302018-05-01 15:59:28 -0700121until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
Gary Wub0e36502018-10-16 11:01:07 -0700122 sleep 30
Gary Wu14a6b302018-05-01 15:59:28 -0700123done
124OLD_PID=$(jq -r '.data[0].id' projects.json)
125
126curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
127echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
128echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
129source api-keys-rc
130
131
132curl -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"id":"registry.default","type":"activeSetting","baseType":"setting","name":"registry.default","activeValue":"__docker_proxy__","inDb":true,"source":"Database","value":"__docker_proxy__"}' http://$RANCHER_IP:8080/v2-beta/settings/registry.default
133
134curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
135
136until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
137 sleep 5
138 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
139 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
140done
141
142curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X POST -H 'Content-Type: application/json' -d '{ "name":"oom", "projectTemplateId":"'$TEMPLATE_ID'" }' "http://$RANCHER_IP:8080/v2-beta/projects" > project.json
143PID=`jq -r '.id' project.json`
144echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
145source api-keys-rc
146
147until [ $(jq -r '.state' project.json) == "active" ]; do
148 sleep 5
149 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
150done
151
152
153curl -s -u $RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"name":"docker-proxy", "serverAddress":"__docker_proxy__"}' $RANCHER_URL/registries > registry.json
154RID=$(jq -r '.id' registry.json)
155
156
157curl -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"publicValue":"docker", "registryId":"'$RID'", "secretValue":"docker", "type":"registryCredential"}' "http://$RANCHER_IP:8080/v2-beta/projects/$PID/registrycredential"
158
159
160
161TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
162touch token.json
163while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
164 sleep 5
165 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
166done
167jq -r .command token.json > rancher_agent_cmd.sh
168chmod +x rancher_agent_cmd.sh
169cp rancher_agent_cmd.sh /dockerdata-nfs
Gary Wu11c98742018-05-02 16:19:04 -0700170cd /dockerdata-nfs
171git add -A
172git commit -a -m "Add rancher agent command file"
173cd ~
Gary Wu14a6b302018-05-01 15:59:28 -0700174
175
176KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
177
178# create .kube/config
179cat > ~/.kube/config <<EOF
180apiVersion: v1
181kind: Config
182clusters:
183- cluster:
184 api-version: v1
185 insecure-skip-tls-verify: true
Gary Wuad513722018-07-26 13:08:47 -0700186 server: "https://__rancher_ip_addr__:8080/r/projects/$PID/kubernetes:6443"
Gary Wu14a6b302018-05-01 15:59:28 -0700187 name: "oom"
188contexts:
189- context:
190 cluster: "oom"
191 user: "oom"
192 name: "oom"
193current-context: "oom"
194users:
195- name: "oom"
196 user:
197 token: "$KUBETOKEN"
198EOF
199
200export KUBECONFIG=/root/.kube/config
201kubectl config view
202
Gary Wub0e36502018-10-16 11:01:07 -0700203# Enable auto-completion for kubectl
204echo "source <(kubectl completion bash)" >> ~/.bashrc
205
206
Gary Wu14a6b302018-05-01 15:59:28 -0700207# wait for kubernetes to initialze
Gary Wub0e36502018-10-16 11:01:07 -0700208sleep 3m
Gary Wu14a6b302018-05-01 15:59:28 -0700209until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
Gary Wub0e36502018-10-16 11:01:07 -0700210 sleep 1m
Gary Wu14a6b302018-05-01 15:59:28 -0700211done
212
213
214# Install using OOM
215export HOME=/root
Gary Wu978171e2018-07-24 11:56:01 -0700216mkdir -p ~/.ssh
217cp ~ubuntu/.ssh/authorized_keys ~/.ssh
218
Gary Wu14a6b302018-05-01 15:59:28 -0700219
Gary Wu0dfbea32018-05-12 09:27:44 -0700220# update and initialize git
221apt-get -y install git
222git config --global user.email root@rancher
223git config --global user.name root@rancher
224git config --global log.decorate auto
225
Gary Wu14a6b302018-05-01 15:59:28 -0700226# Clone OOM:
227cd ~
Gary Wu87aa8b52018-08-09 08:10:24 -0700228git clone -b __oom_gerrit_branch__ https://gerrit.onap.org/r/oom
Gary Wu14a6b302018-05-01 15:59:28 -0700229cd oom
Gary Wu87aa8b52018-08-09 08:10:24 -0700230git fetch https://gerrit.onap.org/r/oom __oom_gerrit_refspec__
231git checkout FETCH_HEAD
Gary Wu0dfbea32018-05-12 09:27:44 -0700232git checkout -b workarounds
Gary Wu87aa8b52018-08-09 08:10:24 -0700233git log -1
Gary Wu14a6b302018-05-01 15:59:28 -0700234
Gary Wu81836d22018-06-22 13:48:50 -0700235# Clone integration
236cd ~
Gary Wu87aa8b52018-08-09 08:10:24 -0700237git clone -b __integration_gerrit_branch__ https://gerrit.onap.org/r/integration
Gary Wu81836d22018-06-22 13:48:50 -0700238cd integration
Gary Wu87aa8b52018-08-09 08:10:24 -0700239git fetch https://gerrit.onap.org/r/integration __integration_gerrit_refspec__
Gary Wu81836d22018-06-22 13:48:50 -0700240git checkout FETCH_HEAD
241
Gary Wu87aa8b52018-08-09 08:10:24 -0700242if [ ! -z "__docker_manifest__" ]; then
243 cd version-manifest/src/main/scripts
244 ./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/
245fi
Gary Wu81836d22018-06-22 13:48:50 -0700246
247cd ~/oom
248git diff
Gary Wu87aa8b52018-08-09 08:10:24 -0700249git commit -a -m "apply manifest versions"
250git tag -a "deploy0" -m "initial deployment"
Gary Wu81836d22018-06-22 13:48:50 -0700251
252
Gary Wu14a6b302018-05-01 15:59:28 -0700253# Run ONAP:
254cd ~/oom/kubernetes/
Gary Wu14a6b302018-05-01 15:59:28 -0700255helm init --client-only
256helm init --upgrade
257helm serve &
Gary Wub0e36502018-10-16 11:01:07 -0700258sleep 10
Gary Wu14a6b302018-05-01 15:59:28 -0700259helm repo add local http://127.0.0.1:8879
260helm repo list
261make all
Gary Wu389aa902018-09-17 13:53:54 -0700262rsync -avt ~/oom/kubernetes/helm/plugins ~/.helm/
Gary Wu14a6b302018-05-01 15:59:28 -0700263helm search -l | grep local
Gary Wua8d6b122018-10-17 11:33:24 -0700264helm deploy dev local/onap -f ~/oom/kubernetes/onap/resources/environments/public-cloud.yaml -f ~/integration-override.yaml --namespace onap | tee ~/helm-deploy.log
Gary Wu389aa902018-09-17 13:53:54 -0700265helm list
Gary Wu14a6b302018-05-01 15:59:28 -0700266
267
268# Check ONAP status:
Gary Wub0e36502018-10-16 11:01:07 -0700269sleep 10
Gary Wu14a6b302018-05-01 15:59:28 -0700270kubectl get pods --all-namespaces
Gary Wub0e36502018-10-16 11:01:07 -0700271kubectl get nodes
272kubectl top nodes