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