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