blob: 0dc432b108f1dc244f466ce6815768bba7d1acdd [file] [log] [blame]
Gary Wu1ff56672018-01-17 20:51:45 -08001#!/bin/bash -x
2printenv
3
4mkdir -p /opt/config
5echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt
6echo `hostname -I` `hostname` >> /etc/hosts
7mkdir -p /etc/docker
8cat > /etc/docker/daemon.json <<EOF
9{
10 "insecure-registries" : ["__docker_proxy__"]
11}
12EOF
13cat > /etc/apt/apt.conf.d/30proxy<<EOF
14Acquire::http { Proxy "http://__apt_proxy__"; };
15Acquire::https::Proxy "DIRECT";
16EOF
17apt-get -y update
18apt-get -y install jq
19
20cd ~
21
22# install docker 1.12
23curl -s https://releases.rancher.com/install-docker/1.12.sh | sh
24usermod -aG docker ubuntu
25
26# install kubernetes 1.8.6
27curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.6/bin/linux/amd64/kubectl
28chmod +x ./kubectl
29sudo mv ./kubectl /usr/local/bin/kubectl
30mkdir ~/.kube
31
32# install helm 2.3
33wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.3.0-linux-amd64.tar.gz
34tar -zxvf helm-v2.3.0-linux-amd64.tar.gz
35sudo mv linux-amd64/helm /usr/local/bin/helm
36
37# Fix virtual memory allocation for onap-log:elasticsearch:
38echo "vm.max_map_count=262144" >> /etc/sysctl.conf
39sysctl -p
40
41# install rancher agent
42echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc
43source api-keys-rc
44
45sleep 50
46until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
47 sleep 10
48done
49OLD_PID=$(jq -r '.data[0].id' projects.json)
50
51curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys | tee apikeys.json
52echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
53echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
54source api-keys-rc
55
56curl -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
57
58until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
59 sleep 5
60 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes | tee projectTemplatesKubernetes.json
61 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
62done
63
64curl -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" | tee project.json
65PID=`jq -r '.id' project.json`
66echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
67source api-keys-rc
68
69until [ $(jq -r '.state' project.json) == "active" ]; do
70 sleep 5
71 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID | tee project.json
72done
73
74TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
75touch token.json
76while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
77 sleep 5
78 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID | tee token.json
79done
80CMD=$(jq -r .command token.json)
81eval $CMD
82
83# download rancher CLI
84wget -q https://github.com/rancher/cli/releases/download/v0.6.7/rancher-linux-amd64-v0.6.7.tar.xz
85unxz rancher-linux-amd64-v0.6.7.tar.xz
86tar xvf rancher-linux-amd64-v0.6.7.tar
87
88# Clone OOM:
89cd ~
90git clone -b amsterdam http://gerrit.onap.org/r/oom
91
92# Update values.yaml to point to docker-proxy instead of nexus3:
93cd ~/oom/kubernetes
94perl -p -i -e 's/nexus3.onap.org:10001/__docker_proxy__/g' `find ./ -name values.yaml`
95
96KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
97
98# create .kube/config
99cat > ~/.kube/config <<EOF
100apiVersion: v1
101kind: Config
102clusters:
103- cluster:
104 api-version: v1
105 insecure-skip-tls-verify: true
106 server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443"
107 name: "oom"
108contexts:
109- context:
110 cluster: "oom"
111 user: "oom"
112 name: "oom"
113current-context: "oom"
114users:
115- name: "oom"
116 user:
117 token: "$KUBETOKEN"
118EOF
119cat ~/.kube/config
120
121# Update ~/oom/kubernetes/kube2msb/values.yaml kubeMasterAuthToken to use the token from ~/.kube/config
122sed -i "s/kubeMasterAuthToken:.*/kubeMasterAuthToken: $KUBETOKEN/" ~/oom/kubernetes/kube2msb/values.yaml
123
124export KUBECONFIG=/root/.kube/config
125kubectl config view
126
127# wait for kubernetes to initialze
128sleep 100
129until [ $(kubectl get pods --all-namespaces | tail -n +2 | grep -c Running) -ge 6 ]; do
130 sleep 10
131done
132
133# Put your onap_key ssh private key in ~/.ssh/onap_key
134
135# Create or edit ~/oom/kubernetes/config/onap-parameters.yaml
136cp ~/oom/kubernetes/config/onap-parameters-sample.yaml ~/oom/kubernetes/config/onap-parameters.yaml
137cat >> ~/oom/kubernetes/config/onap-parameters.yaml <<EOF
138OPENSTACK_UBUNTU_14_IMAGE: "trusty"
139OPENSTACK_PUBLIC_NET_ID: "024582bd-ef9b-48b9-9e70-e6732559d9df"
140OPENSTACK_OAM_NETWORK_ID: "a899f36c-28e1-4aa9-9451-1b9f41feefa5"
141OPENSTACK_OAM_SUBNET_ID: "b9627602-2908-4aee-94b5-4f1dc92017df"
142OPENSTACK_OAM_NETWORK_CIDR: "172.16.1.0/24"
143OPENSTACK_USERNAME: "demo"
144OPENSTACK_API_KEY: "demo"
145OPENSTACK_TENANT_NAME: "demo"
146OPENSTACK_TENANT_ID: "__public_net_id__"
147OPENSTACK_REGION: "RegionOne"
148OPENSTACK_KEYSTONE_URL: "http://192.168.1.11:5000"
149OPENSTACK_FLAVOUR_MEDIUM: "m1.medium"
150OPENSTACK_SERVICE_TENANT_NAME: "service"
151DMAAP_TOPIC: "AUTO"
152DEMO_ARTIFACTS_VERSION: "1.1.0-SNAPSHOT"
153EOF
154
155# Source the environment file:
156cd ~/oom/kubernetes/oneclick/
157source setenv.bash
158
159# run the config pod creation
160cd ~/oom/kubernetes/config
161./createConfig.sh -n onap
162
163# Wait until the config container completes.
164sleep 200
165until [ $(kubectl get pods --namespace onap -a | tail -n +2 | grep -c Completed) -eq 1 ]; do
166 sleep 10
167done
168
169# Run ONAP:
170cd ~/oom/kubernetes/oneclick/
171./createAll.bash -n onap
172
173# Check ONAP status: