blob: 0490b6ab4a887ce989942830079a7ac5f40829a0 [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 Wu11c98742018-05-02 16:19:04 -070017echo "__oam_network_id__" > /opt/config/oam_network_id.txt
18echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt
19
20cat <<EOF > /opt/config/integration-override.yaml
21__integration_override_yaml__
22EOF
23sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml
24sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml
Gary Wu0a671622018-05-14 12:59:03 -070025sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070026cp /opt/config/integration-override.yaml /root
Gary Wu14a6b302018-05-01 15:59:28 -070027
Gary Wu1ff56672018-01-17 20:51:45 -080028echo `hostname -I` `hostname` >> /etc/hosts
29mkdir -p /etc/docker
Gary Wu3ad596f2018-02-08 07:16:37 -080030if [ ! -z "__docker_proxy__" ]; then
31 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080032{
33 "insecure-registries" : ["__docker_proxy__"]
34}
35EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080036fi
37if [ ! -z "__apt_proxy__" ]; then
38 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080039Acquire::http { Proxy "http://__apt_proxy__"; };
40Acquire::https::Proxy "DIRECT";
41EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080042fi
Gary Wu1ff56672018-01-17 20:51:45 -080043apt-get -y update
Gary Wu14a6b302018-05-01 15:59:28 -070044apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server
45
46
47# version control the persistence volume to see what's happening
48mkdir -p /dockerdata-nfs/
49chmod 777 /dockerdata-nfs/
50chown nobody:nogroup /dockerdata-nfs/
51cd /dockerdata-nfs/
52git init
Gary Wu11c98742018-05-02 16:19:04 -070053git config user.email "root@onap"
Gary Wu14a6b302018-05-01 15:59:28 -070054git config user.name "root"
55git add -A
56git commit -m "initial commit"
57
58# export NFS mount
59NFS_EXP=""
60for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_vm_ips.txt); do
61 NFS_EXP+="$K8S_VM_IP(rw,sync,no_root_squash,no_subtree_check) "
62done
63echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports
64
65
66exportfs -a
67systemctl restart nfs-kernel-server
68
69cd ~
70
71# install docker 17.03
72curl -s https://releases.rancher.com/install-docker/17.03.sh | sh
Gary Wu1ff56672018-01-17 20:51:45 -080073usermod -aG docker ubuntu
Gary Wu14a6b302018-05-01 15:59:28 -070074
75docker 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
76
Gary Wua0fe61c2018-06-08 08:06:47 -070077# install kubernetes 1.8.10
Gary Wu14a6b302018-05-01 15:59:28 -070078curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.10/bin/linux/amd64/kubectl
79chmod +x ./kubectl
80sudo mv ./kubectl /usr/local/bin/kubectl
81mkdir ~/.kube
82
83# install helm
84wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz
85tar -zxvf helm-v2.8.2-linux-amd64.tar.gz
86sudo mv linux-amd64/helm /usr/local/bin/helm
87
88echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc
89source api-keys-rc
90
91sleep 50
92until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
93 sleep 10
94done
95OLD_PID=$(jq -r '.data[0].id' projects.json)
96
97curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
98echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
99echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
100source api-keys-rc
101
102
103curl -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
104
105curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
106
107until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
108 sleep 5
109 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
110 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
111done
112
113curl -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
114PID=`jq -r '.id' project.json`
115echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
116source api-keys-rc
117
118until [ $(jq -r '.state' project.json) == "active" ]; do
119 sleep 5
120 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
121done
122
123
124curl -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
125RID=$(jq -r '.id' registry.json)
126
127
128curl -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"
129
130
131
132TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
133touch token.json
134while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
135 sleep 5
136 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
137done
138jq -r .command token.json > rancher_agent_cmd.sh
139chmod +x rancher_agent_cmd.sh
140cp rancher_agent_cmd.sh /dockerdata-nfs
Gary Wu11c98742018-05-02 16:19:04 -0700141cd /dockerdata-nfs
142git add -A
143git commit -a -m "Add rancher agent command file"
144cd ~
Gary Wu14a6b302018-05-01 15:59:28 -0700145
146
147KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
148
149# create .kube/config
150cat > ~/.kube/config <<EOF
151apiVersion: v1
152kind: Config
153clusters:
154- cluster:
155 api-version: v1
156 insecure-skip-tls-verify: true
157 server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443"
158 name: "oom"
159contexts:
160- context:
161 cluster: "oom"
162 user: "oom"
163 name: "oom"
164current-context: "oom"
165users:
166- name: "oom"
167 user:
168 token: "$KUBETOKEN"
169EOF
170
171export KUBECONFIG=/root/.kube/config
172kubectl config view
173
174# wait for kubernetes to initialze
175sleep 100
176until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
177 sleep 10
178done
179
180
181# Install using OOM
182export HOME=/root
183
Gary Wu0dfbea32018-05-12 09:27:44 -0700184# update and initialize git
185apt-get -y install git
186git config --global user.email root@rancher
187git config --global user.name root@rancher
188git config --global log.decorate auto
189
Gary Wu14a6b302018-05-01 15:59:28 -0700190# Clone OOM:
191cd ~
Gary Wuc076ada2018-06-07 16:38:25 -0700192git clone -b master http://gerrit.onap.org/r/oom
Gary Wu14a6b302018-05-01 15:59:28 -0700193cd oom
194git log -1
Gary Wu0dfbea32018-05-12 09:27:44 -0700195git tag -a "deploy0" -m "initial deployment"
196git checkout -b workarounds
Gary Wu14a6b302018-05-01 15:59:28 -0700197
Gary Wu14a6b302018-05-01 15:59:28 -0700198# Run ONAP:
199cd ~/oom/kubernetes/
Gary Wu14a6b302018-05-01 15:59:28 -0700200helm init --client-only
201helm init --upgrade
202helm serve &
203sleep 3
204helm repo add local http://127.0.0.1:8879
205helm repo list
206make all
207helm search -l | grep local
Gary Wu11c98742018-05-02 16:19:04 -0700208helm install local/onap -n dev --namespace onap -f ~/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -0700209
hector56bc0dd2018-06-01 20:00:43 -0400210# Enable auto-completion for kubectl
211echo "source <(kubectl completion bash)" >> ~/.bashrc
Gary Wu14a6b302018-05-01 15:59:28 -0700212
213# Check ONAP status:
214sleep 3
215kubectl get pods --all-namespaces