blob: 7e8ca46fe54e81e6c56f889c14530a1dfa9134c8 [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
Gary Wu374498a2018-02-06 17:31:04 -08008if [ ! -z "__docker_proxy__" ]; then
9 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080010{
11 "insecure-registries" : ["__docker_proxy__"]
12}
13EOF
Gary Wu374498a2018-02-06 17:31:04 -080014fi
15if [ ! -z "__apt_proxy__" ]; then
16 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080017Acquire::http { Proxy "http://__apt_proxy__"; };
18Acquire::https::Proxy "DIRECT";
19EOF
Gary Wu374498a2018-02-06 17:31:04 -080020fi
Gary Wu1ff56672018-01-17 20:51:45 -080021apt-get -y update
Gary Wub5529a62018-04-03 14:57:17 -070022apt-get -y install linux-image-extra-$(uname -r) jq make
Gary Wu1ff56672018-01-17 20:51:45 -080023
24cd ~
25
Gary Wu57abb1a2018-03-09 13:38:28 -080026# install docker 17.03
27curl -s https://releases.rancher.com/install-docker/17.03.sh | sh
Gary Wu1ff56672018-01-17 20:51:45 -080028usermod -aG docker ubuntu
29
30# install kubernetes 1.8.6
31curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.6/bin/linux/amd64/kubectl
32chmod +x ./kubectl
33sudo mv ./kubectl /usr/local/bin/kubectl
34mkdir ~/.kube
35
Gary Wu57abb1a2018-03-09 13:38:28 -080036# install helm
Helen Chen1451db42018-04-12 15:54:24 -070037wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.7.2-linux-amd64.tar.gz
38tar -zxvf helm-v2.7.2-linux-amd64.tar.gz
Gary Wu1ff56672018-01-17 20:51:45 -080039sudo mv linux-amd64/helm /usr/local/bin/helm
40
41# Fix virtual memory allocation for onap-log:elasticsearch:
42echo "vm.max_map_count=262144" >> /etc/sysctl.conf
43sysctl -p
44
45# install rancher agent
46echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc
47source api-keys-rc
48
49sleep 50
50until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
51 sleep 10
52done
53OLD_PID=$(jq -r '.data[0].id' projects.json)
54
Gary Wu52dfdcb2018-01-25 11:02:48 -080055curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
Gary Wu1ff56672018-01-17 20:51:45 -080056echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
57echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
58source api-keys-rc
59
Gary Wu60dd0d82018-01-18 14:54:47 -080060curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
Gary Wu1ff56672018-01-17 20:51:45 -080061
62until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
63 sleep 5
Gary Wu52dfdcb2018-01-25 11:02:48 -080064 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
Gary Wu1ff56672018-01-17 20:51:45 -080065 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
66done
67
Gary Wu52dfdcb2018-01-25 11:02:48 -080068curl -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
Gary Wu1ff56672018-01-17 20:51:45 -080069PID=`jq -r '.id' project.json`
70echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
71source api-keys-rc
72
73until [ $(jq -r '.state' project.json) == "active" ]; do
74 sleep 5
Gary Wu52dfdcb2018-01-25 11:02:48 -080075 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
Gary Wu1ff56672018-01-17 20:51:45 -080076done
77
78TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
79touch token.json
80while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
81 sleep 5
Gary Wu52dfdcb2018-01-25 11:02:48 -080082 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
Gary Wu1ff56672018-01-17 20:51:45 -080083done
Gary Wu52dfdcb2018-01-25 11:02:48 -080084RANCHER_AGENT_CMD=$(jq -r .command token.json)
85eval $RANCHER_AGENT_CMD
Gary Wu1ff56672018-01-17 20:51:45 -080086
Gary Wu1ff56672018-01-17 20:51:45 -080087
88KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
89
90# create .kube/config
91cat > ~/.kube/config <<EOF
92apiVersion: v1
93kind: Config
94clusters:
95- cluster:
96 api-version: v1
97 insecure-skip-tls-verify: true
98 server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443"
99 name: "oom"
100contexts:
101- context:
102 cluster: "oom"
103 user: "oom"
104 name: "oom"
105current-context: "oom"
106users:
107- name: "oom"
108 user:
109 token: "$KUBETOKEN"
110EOF
Gary Wu1ff56672018-01-17 20:51:45 -0800111
112export KUBECONFIG=/root/.kube/config
113kubectl config view
114
Gary Wuc98156d2018-01-18 12:03:26 -0800115# wait for kubernetes to initialze
116sleep 100
117until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
118 sleep 10
119done
Gary Wu1ff56672018-01-17 20:51:45 -0800120
Gary Wu1ff56672018-01-17 20:51:45 -0800121
Gary Wuca219e02018-04-04 11:35:55 -0700122# Install using OOM
123export HOME=/root
Gary Wu1ff56672018-01-17 20:51:45 -0800124
Gary Wuca219e02018-04-04 11:35:55 -0700125# Clone OOM:
126cd ~
127git clone -b master http://gerrit.onap.org/r/oom
Gary Wu19c81b42018-04-17 11:35:48 -0700128cd oom
Gary Wuca219e02018-04-04 11:35:55 -0700129git log -1
130
131# Update values.yaml to point to docker-proxy instead of nexus3:
132cd ~/oom/kubernetes
133#perl -p -i -e 's/nexus3.onap.org:10001/__docker_proxy__/g' `find ./ -name values.yaml`
134sed -i 's/nexus3.onap.org:10001/__docker_proxy__/g' onap/values.yaml
135sed -i 's/#repository:/repository:/g' onap/values.yaml
136sed -i 's/#repositorySecret:/repositorySecret:/g' onap/values.yaml
137git diff
138
139
Gary Wu19c81b42018-04-17 11:35:48 -0700140# Clone integration:
141cd ~
142git clone -b master http://gerrit.onap.org/r/integration
143cd integration
144git log -1
145
146cd ~
147ln -s ~/integration/deployment/heat/onap-oom/env/__lab_name__/integration-override.yaml
Gary Wu34f65d52018-04-25 09:57:34 -0700148sed -i 's/nexus3.onap.org:10001/__docker_proxy__/g' integration-override.yaml
Gary Wu19c81b42018-04-17 11:35:48 -0700149
150
Gary Wuca219e02018-04-04 11:35:55 -0700151# version control the persistence volume to see what's happening
152mkdir -p /dockerdata-nfs/
Gary Wu60dd0d82018-01-18 14:54:47 -0800153cd /dockerdata-nfs/
154git init
155git config user.email "root@k8s"
156git config user.name "root"
157git add -A
158git commit -m "initial commit"
159
Gary Wu1ff56672018-01-17 20:51:45 -0800160# Run ONAP:
Gary Wub5529a62018-04-03 14:57:17 -0700161cd ~/oom/kubernetes/
Gary Wuca219e02018-04-04 11:35:55 -0700162# verify version
163helm version
Gary Wub5529a62018-04-03 14:57:17 -0700164helm init --client-only
Gary Wu90d878d2018-04-12 16:15:19 -0700165helm init --upgrade
Gary Wub5529a62018-04-03 14:57:17 -0700166helm serve &
167sleep 3
168helm repo add local http://127.0.0.1:8879
Gary Wuca219e02018-04-04 11:35:55 -0700169helm repo list
Gary Wub5529a62018-04-03 14:57:17 -0700170make all
Gary Wuca219e02018-04-04 11:35:55 -0700171helm search -l | grep local
Gary Wu34f65d52018-04-25 09:57:34 -0700172if [ -e ~/integration-override.yaml ]; then
173 helm install local/onap -n dev --namespace onap -f ~/integration-override.yaml
174else
175 helm install local/onap -n dev --namespace onap
176fi
177
Gary Wu1ff56672018-01-17 20:51:45 -0800178
179# Check ONAP status:
Gary Wu60dd0d82018-01-18 14:54:47 -0800180sleep 3
Gary Wuc98156d2018-01-18 12:03:26 -0800181kubectl get pods --all-namespaces