blob: 098abbd394371c16c54af101b552f6b5318f8a32 [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 Wuad513722018-07-26 13:08:47 -070017echo "__k8s_private_ips__" > /opt/config/k8s_private_ips.txt
Gary Wu978171e2018-07-24 11:56:01 -070018echo "__public_net_id__" > /opt/config/public_net_id.txt
19echo "__oam_network_cidr__" > /opt/config/oam_network_cidr.txt
Gary Wu11c98742018-05-02 16:19:04 -070020echo "__oam_network_id__" > /opt/config/oam_network_id.txt
21echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt
Gary Wu81836d22018-06-22 13:48:50 -070022echo "__gerrit_branch__" > /opt/config/gerrit_branch.txt
23echo "__gerrit_refspec__" > /opt/config/gerrit_refspec.txt
24echo "__docker_manifest__" > /opt/config/docker_manifest.txt
Gary Wu978171e2018-07-24 11:56:01 -070025echo "__docker_proxy__" > /opt/config/docker_proxy.txt
Gary Wu11c98742018-05-02 16:19:04 -070026
27cat <<EOF > /opt/config/integration-override.yaml
28__integration_override_yaml__
29EOF
Gary Wu978171e2018-07-24 11:56:01 -070030sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml
31sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070032sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml
33sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml
Gary Wued95ca72018-07-26 10:24:51 -070034sed -i 's/\_\_rancher_ip_addr__/__rancher_ip_addr__/g' /opt/config/integration-override.yaml
Gary Wu0a671622018-05-14 12:59:03 -070035sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml
Gary Wu978171e2018-07-24 11:56:01 -070036sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070037cp /opt/config/integration-override.yaml /root
Gary Wu978171e2018-07-24 11:56:01 -070038cat /root/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -070039
Gary Wu1ff56672018-01-17 20:51:45 -080040echo `hostname -I` `hostname` >> /etc/hosts
41mkdir -p /etc/docker
Gary Wu3ad596f2018-02-08 07:16:37 -080042if [ ! -z "__docker_proxy__" ]; then
43 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080044{
45 "insecure-registries" : ["__docker_proxy__"]
46}
47EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080048fi
49if [ ! -z "__apt_proxy__" ]; then
50 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080051Acquire::http { Proxy "http://__apt_proxy__"; };
52Acquire::https::Proxy "DIRECT";
53EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080054fi
Gary Wu1ff56672018-01-17 20:51:45 -080055apt-get -y update
Gary Wubc764502018-06-28 16:13:41 -070056apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server moreutils
Gary Wu14a6b302018-05-01 15:59:28 -070057
58
Gary Wuc4749702018-06-26 14:27:41 -070059# use RAM disk for /dockerdata-nfs for testing
Gary Wubc764502018-06-28 16:13:41 -070060echo "tmpfs /dockerdata-nfs tmpfs noatime 1 2" >> /etc/fstab
Gary Wuc4749702018-06-26 14:27:41 -070061mkdir -pv /dockerdata-nfs
62mount /dockerdata-nfs
63
Gary Wu14a6b302018-05-01 15:59:28 -070064# version control the persistence volume to see what's happening
Gary Wu14a6b302018-05-01 15:59:28 -070065chmod 777 /dockerdata-nfs/
66chown nobody:nogroup /dockerdata-nfs/
67cd /dockerdata-nfs/
68git init
Gary Wu11c98742018-05-02 16:19:04 -070069git config user.email "root@onap"
Gary Wu14a6b302018-05-01 15:59:28 -070070git config user.name "root"
71git add -A
72git commit -m "initial commit"
73
74# export NFS mount
75NFS_EXP=""
Gary Wuad513722018-07-26 13:08:47 -070076for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_private_ips.txt); do
Gary Wubc764502018-06-28 16:13:41 -070077 NFS_EXP+="$K8S_VM_IP(rw,fsid=1,sync,no_root_squash,no_subtree_check) "
Gary Wu14a6b302018-05-01 15:59:28 -070078done
79echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports
80
81
82exportfs -a
83systemctl restart nfs-kernel-server
84
85cd ~
86
87# install docker 17.03
88curl -s https://releases.rancher.com/install-docker/17.03.sh | sh
Gary Wu1ff56672018-01-17 20:51:45 -080089usermod -aG docker ubuntu
Gary Wu14a6b302018-05-01 15:59:28 -070090
91docker 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
92
Gary Wua0fe61c2018-06-08 08:06:47 -070093# install kubernetes 1.8.10
Gary Wu14a6b302018-05-01 15:59:28 -070094curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.10/bin/linux/amd64/kubectl
95chmod +x ./kubectl
96sudo mv ./kubectl /usr/local/bin/kubectl
97mkdir ~/.kube
98
99# install helm
100wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz
101tar -zxvf helm-v2.8.2-linux-amd64.tar.gz
102sudo mv linux-amd64/helm /usr/local/bin/helm
103
Gary Wuad513722018-07-26 13:08:47 -0700104echo export RANCHER_IP=__rancher_private_ip_addr__ > api-keys-rc
Gary Wu14a6b302018-05-01 15:59:28 -0700105source api-keys-rc
106
107sleep 50
108until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
109 sleep 10
110done
111OLD_PID=$(jq -r '.data[0].id' projects.json)
112
113curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
114echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
115echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
116source api-keys-rc
117
118
119curl -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
120
121curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
122
123until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
124 sleep 5
125 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
126 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
127done
128
129curl -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
130PID=`jq -r '.id' project.json`
131echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
132source api-keys-rc
133
134until [ $(jq -r '.state' project.json) == "active" ]; do
135 sleep 5
136 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
137done
138
139
140curl -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
141RID=$(jq -r '.id' registry.json)
142
143
144curl -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"
145
146
147
148TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
149touch token.json
150while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
151 sleep 5
152 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
153done
154jq -r .command token.json > rancher_agent_cmd.sh
155chmod +x rancher_agent_cmd.sh
156cp rancher_agent_cmd.sh /dockerdata-nfs
Gary Wu11c98742018-05-02 16:19:04 -0700157cd /dockerdata-nfs
158git add -A
159git commit -a -m "Add rancher agent command file"
160cd ~
Gary Wu14a6b302018-05-01 15:59:28 -0700161
162
163KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
164
165# create .kube/config
166cat > ~/.kube/config <<EOF
167apiVersion: v1
168kind: Config
169clusters:
170- cluster:
171 api-version: v1
172 insecure-skip-tls-verify: true
Gary Wuad513722018-07-26 13:08:47 -0700173 server: "https://__rancher_ip_addr__:8080/r/projects/$PID/kubernetes:6443"
Gary Wu14a6b302018-05-01 15:59:28 -0700174 name: "oom"
175contexts:
176- context:
177 cluster: "oom"
178 user: "oom"
179 name: "oom"
180current-context: "oom"
181users:
182- name: "oom"
183 user:
184 token: "$KUBETOKEN"
185EOF
186
187export KUBECONFIG=/root/.kube/config
188kubectl config view
189
190# wait for kubernetes to initialze
191sleep 100
192until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
193 sleep 10
194done
195
196
197# Install using OOM
198export HOME=/root
Gary Wu978171e2018-07-24 11:56:01 -0700199mkdir -p ~/.ssh
200cp ~ubuntu/.ssh/authorized_keys ~/.ssh
201
Gary Wu14a6b302018-05-01 15:59:28 -0700202
Gary Wu0dfbea32018-05-12 09:27:44 -0700203# update and initialize git
204apt-get -y install git
205git config --global user.email root@rancher
206git config --global user.name root@rancher
207git config --global log.decorate auto
208
Gary Wu14a6b302018-05-01 15:59:28 -0700209# Clone OOM:
210cd ~
Gary Wu81836d22018-06-22 13:48:50 -0700211git clone -b master https://gerrit.onap.org/r/oom
Gary Wu14a6b302018-05-01 15:59:28 -0700212cd oom
213git log -1
Gary Wu0dfbea32018-05-12 09:27:44 -0700214git tag -a "deploy0" -m "initial deployment"
215git checkout -b workarounds
Gary Wu14a6b302018-05-01 15:59:28 -0700216
Gary Wu81836d22018-06-22 13:48:50 -0700217# Clone integration
218cd ~
219git clone -b __gerrit_branch__ https://gerrit.onap.org/r/integration
220cd integration
221git fetch https://gerrit.onap.org/r/integration __gerrit_refspec__
222git checkout FETCH_HEAD
223
224cd version-manifest/src/main/scripts
225./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/
226
227cd ~/oom
228git diff
229
230
Gary Wu14a6b302018-05-01 15:59:28 -0700231# Run ONAP:
232cd ~/oom/kubernetes/
Gary Wu14a6b302018-05-01 15:59:28 -0700233helm init --client-only
234helm init --upgrade
235helm serve &
236sleep 3
237helm repo add local http://127.0.0.1:8879
238helm repo list
239make all
240helm search -l | grep local
Gary Wu11c98742018-05-02 16:19:04 -0700241helm install local/onap -n dev --namespace onap -f ~/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -0700242
hector56bc0dd2018-06-01 20:00:43 -0400243# Enable auto-completion for kubectl
244echo "source <(kubectl completion bash)" >> ~/.bashrc
Gary Wu14a6b302018-05-01 15:59:28 -0700245
246# Check ONAP status:
247sleep 3
248kubectl get pods --all-namespaces