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