blob: ffc4fd5f6f73cd477f5c0744e96a1c262b8e845f [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 Wu978171e2018-07-24 11:56:01 -070017echo "__public_net_id__" > /opt/config/public_net_id.txt
18echo "__oam_network_cidr__" > /opt/config/oam_network_cidr.txt
Gary Wu11c98742018-05-02 16:19:04 -070019echo "__oam_network_id__" > /opt/config/oam_network_id.txt
20echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt
Gary Wu81836d22018-06-22 13:48:50 -070021echo "__gerrit_branch__" > /opt/config/gerrit_branch.txt
22echo "__gerrit_refspec__" > /opt/config/gerrit_refspec.txt
23echo "__docker_manifest__" > /opt/config/docker_manifest.txt
Gary Wu978171e2018-07-24 11:56:01 -070024echo "__docker_proxy__" > /opt/config/docker_proxy.txt
Gary Wu11c98742018-05-02 16:19:04 -070025
26cat <<EOF > /opt/config/integration-override.yaml
27__integration_override_yaml__
28EOF
Gary Wu978171e2018-07-24 11:56:01 -070029sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml
30sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070031sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml
32sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml
Gary Wu0a671622018-05-14 12:59:03 -070033sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml
Gary Wu978171e2018-07-24 11:56:01 -070034sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070035cp /opt/config/integration-override.yaml /root
Gary Wu978171e2018-07-24 11:56:01 -070036cat /root/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -070037
Gary Wu1ff56672018-01-17 20:51:45 -080038echo `hostname -I` `hostname` >> /etc/hosts
39mkdir -p /etc/docker
Gary Wu3ad596f2018-02-08 07:16:37 -080040if [ ! -z "__docker_proxy__" ]; then
41 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080042{
43 "insecure-registries" : ["__docker_proxy__"]
44}
45EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080046fi
47if [ ! -z "__apt_proxy__" ]; then
48 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080049Acquire::http { Proxy "http://__apt_proxy__"; };
50Acquire::https::Proxy "DIRECT";
51EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080052fi
Gary Wu1ff56672018-01-17 20:51:45 -080053apt-get -y update
Gary Wubc764502018-06-28 16:13:41 -070054apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server moreutils
Gary Wu14a6b302018-05-01 15:59:28 -070055
56
Gary Wuc4749702018-06-26 14:27:41 -070057# use RAM disk for /dockerdata-nfs for testing
Gary Wubc764502018-06-28 16:13:41 -070058echo "tmpfs /dockerdata-nfs tmpfs noatime 1 2" >> /etc/fstab
Gary Wuc4749702018-06-26 14:27:41 -070059mkdir -pv /dockerdata-nfs
60mount /dockerdata-nfs
61
Gary Wu14a6b302018-05-01 15:59:28 -070062# version control the persistence volume to see what's happening
Gary Wu14a6b302018-05-01 15:59:28 -070063chmod 777 /dockerdata-nfs/
64chown nobody:nogroup /dockerdata-nfs/
65cd /dockerdata-nfs/
66git init
Gary Wu11c98742018-05-02 16:19:04 -070067git config user.email "root@onap"
Gary Wu14a6b302018-05-01 15:59:28 -070068git config user.name "root"
69git add -A
70git commit -m "initial commit"
71
72# export NFS mount
73NFS_EXP=""
74for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_vm_ips.txt); do
Gary Wubc764502018-06-28 16:13:41 -070075 NFS_EXP+="$K8S_VM_IP(rw,fsid=1,sync,no_root_squash,no_subtree_check) "
Gary Wu14a6b302018-05-01 15:59:28 -070076done
77echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports
78
79
80exportfs -a
81systemctl restart nfs-kernel-server
82
83cd ~
84
85# install docker 17.03
86curl -s https://releases.rancher.com/install-docker/17.03.sh | sh
Gary Wu1ff56672018-01-17 20:51:45 -080087usermod -aG docker ubuntu
Gary Wu14a6b302018-05-01 15:59:28 -070088
89docker run --restart unless-stopped -d -p 8080:8080 -e CATTLE_BOOTSTRAP_REQUIRED_IMAGE=__docker_proxy__/rancher/agent:v1.2.9 __docker_proxy__/rancher/server:v1.6.14
90
Gary Wua0fe61c2018-06-08 08:06:47 -070091# install kubernetes 1.8.10
Gary Wu14a6b302018-05-01 15:59:28 -070092curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.10/bin/linux/amd64/kubectl
93chmod +x ./kubectl
94sudo mv ./kubectl /usr/local/bin/kubectl
95mkdir ~/.kube
96
97# install helm
98wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz
99tar -zxvf helm-v2.8.2-linux-amd64.tar.gz
100sudo mv linux-amd64/helm /usr/local/bin/helm
101
102echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc
103source api-keys-rc
104
105sleep 50
106until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
107 sleep 10
108done
109OLD_PID=$(jq -r '.data[0].id' projects.json)
110
111curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
112echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
113echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
114source api-keys-rc
115
116
117curl -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
118
119curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
120
121until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
122 sleep 5
123 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
124 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
125done
126
127curl -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
128PID=`jq -r '.id' project.json`
129echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
130source api-keys-rc
131
132until [ $(jq -r '.state' project.json) == "active" ]; do
133 sleep 5
134 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
135done
136
137
138curl -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
139RID=$(jq -r '.id' registry.json)
140
141
142curl -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"
143
144
145
146TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
147touch token.json
148while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
149 sleep 5
150 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
151done
152jq -r .command token.json > rancher_agent_cmd.sh
153chmod +x rancher_agent_cmd.sh
154cp rancher_agent_cmd.sh /dockerdata-nfs
Gary Wu11c98742018-05-02 16:19:04 -0700155cd /dockerdata-nfs
156git add -A
157git commit -a -m "Add rancher agent command file"
158cd ~
Gary Wu14a6b302018-05-01 15:59:28 -0700159
160
161KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
162
163# create .kube/config
164cat > ~/.kube/config <<EOF
165apiVersion: v1
166kind: Config
167clusters:
168- cluster:
169 api-version: v1
170 insecure-skip-tls-verify: true
171 server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443"
172 name: "oom"
173contexts:
174- context:
175 cluster: "oom"
176 user: "oom"
177 name: "oom"
178current-context: "oom"
179users:
180- name: "oom"
181 user:
182 token: "$KUBETOKEN"
183EOF
184
185export KUBECONFIG=/root/.kube/config
186kubectl config view
187
188# wait for kubernetes to initialze
189sleep 100
190until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
191 sleep 10
192done
193
194
195# Install using OOM
196export HOME=/root
Gary Wu978171e2018-07-24 11:56:01 -0700197mkdir -p ~/.ssh
198cp ~ubuntu/.ssh/authorized_keys ~/.ssh
199
Gary Wu14a6b302018-05-01 15:59:28 -0700200
Gary Wu0dfbea32018-05-12 09:27:44 -0700201# update and initialize git
202apt-get -y install git
203git config --global user.email root@rancher
204git config --global user.name root@rancher
205git config --global log.decorate auto
206
Gary Wu14a6b302018-05-01 15:59:28 -0700207# Clone OOM:
208cd ~
Gary Wu81836d22018-06-22 13:48:50 -0700209git clone -b master https://gerrit.onap.org/r/oom
Gary Wu14a6b302018-05-01 15:59:28 -0700210cd oom
211git log -1
Gary Wu0dfbea32018-05-12 09:27:44 -0700212git tag -a "deploy0" -m "initial deployment"
213git checkout -b workarounds
Gary Wu14a6b302018-05-01 15:59:28 -0700214
Gary Wu81836d22018-06-22 13:48:50 -0700215# Clone integration
216cd ~
217git clone -b __gerrit_branch__ https://gerrit.onap.org/r/integration
218cd integration
219git fetch https://gerrit.onap.org/r/integration __gerrit_refspec__
220git checkout FETCH_HEAD
221
222cd version-manifest/src/main/scripts
223./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/
224
225cd ~/oom
226git diff
227
228
Gary Wu14a6b302018-05-01 15:59:28 -0700229# Run ONAP:
230cd ~/oom/kubernetes/
Gary Wu14a6b302018-05-01 15:59:28 -0700231helm init --client-only
232helm init --upgrade
233helm serve &
234sleep 3
235helm repo add local http://127.0.0.1:8879
236helm repo list
237make all
238helm search -l | grep local
Gary Wu11c98742018-05-02 16:19:04 -0700239helm install local/onap -n dev --namespace onap -f ~/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -0700240
hector56bc0dd2018-06-01 20:00:43 -0400241# Enable auto-completion for kubectl
242echo "source <(kubectl completion bash)" >> ~/.bashrc
Gary Wu14a6b302018-05-01 15:59:28 -0700243
244# Check ONAP status:
245sleep 3
246kubectl get pods --all-namespaces