blob: 89f942739712932a8c8574a68fb01114e86d7079 [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 Wubc764502018-06-28 16:13:41 -070047apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server moreutils
Gary Wu14a6b302018-05-01 15:59:28 -070048
49
Gary Wuc4749702018-06-26 14:27:41 -070050# use RAM disk for /dockerdata-nfs for testing
Gary Wubc764502018-06-28 16:13:41 -070051echo "tmpfs /dockerdata-nfs tmpfs noatime 1 2" >> /etc/fstab
Gary Wuc4749702018-06-26 14:27:41 -070052mkdir -pv /dockerdata-nfs
53mount /dockerdata-nfs
54
Gary Wu14a6b302018-05-01 15:59:28 -070055# version control the persistence volume to see what's happening
Gary Wu14a6b302018-05-01 15:59:28 -070056chmod 777 /dockerdata-nfs/
57chown nobody:nogroup /dockerdata-nfs/
58cd /dockerdata-nfs/
59git init
Gary Wu11c98742018-05-02 16:19:04 -070060git config user.email "root@onap"
Gary Wu14a6b302018-05-01 15:59:28 -070061git config user.name "root"
62git add -A
63git commit -m "initial commit"
64
65# export NFS mount
66NFS_EXP=""
67for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_vm_ips.txt); do
Gary Wubc764502018-06-28 16:13:41 -070068 NFS_EXP+="$K8S_VM_IP(rw,fsid=1,sync,no_root_squash,no_subtree_check) "
Gary Wu14a6b302018-05-01 15:59:28 -070069done
70echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports
71
72
73exportfs -a
74systemctl restart nfs-kernel-server
75
76cd ~
77
78# install docker 17.03
79curl -s https://releases.rancher.com/install-docker/17.03.sh | sh
Gary Wu1ff56672018-01-17 20:51:45 -080080usermod -aG docker ubuntu
Gary Wu14a6b302018-05-01 15:59:28 -070081
82docker 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
83
Gary Wua0fe61c2018-06-08 08:06:47 -070084# install kubernetes 1.8.10
Gary Wu14a6b302018-05-01 15:59:28 -070085curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.10/bin/linux/amd64/kubectl
86chmod +x ./kubectl
87sudo mv ./kubectl /usr/local/bin/kubectl
88mkdir ~/.kube
89
90# install helm
91wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz
92tar -zxvf helm-v2.8.2-linux-amd64.tar.gz
93sudo mv linux-amd64/helm /usr/local/bin/helm
94
95echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc
96source api-keys-rc
97
98sleep 50
99until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
100 sleep 10
101done
102OLD_PID=$(jq -r '.data[0].id' projects.json)
103
104curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
105echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
106echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
107source api-keys-rc
108
109
110curl -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
111
112curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
113
114until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
115 sleep 5
116 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
117 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
118done
119
120curl -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
121PID=`jq -r '.id' project.json`
122echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
123source api-keys-rc
124
125until [ $(jq -r '.state' project.json) == "active" ]; do
126 sleep 5
127 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
128done
129
130
131curl -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
132RID=$(jq -r '.id' registry.json)
133
134
135curl -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"
136
137
138
139TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
140touch token.json
141while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
142 sleep 5
143 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
144done
145jq -r .command token.json > rancher_agent_cmd.sh
146chmod +x rancher_agent_cmd.sh
147cp rancher_agent_cmd.sh /dockerdata-nfs
Gary Wu11c98742018-05-02 16:19:04 -0700148cd /dockerdata-nfs
149git add -A
150git commit -a -m "Add rancher agent command file"
151cd ~
Gary Wu14a6b302018-05-01 15:59:28 -0700152
153
154KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
155
156# create .kube/config
157cat > ~/.kube/config <<EOF
158apiVersion: v1
159kind: Config
160clusters:
161- cluster:
162 api-version: v1
163 insecure-skip-tls-verify: true
164 server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443"
165 name: "oom"
166contexts:
167- context:
168 cluster: "oom"
169 user: "oom"
170 name: "oom"
171current-context: "oom"
172users:
173- name: "oom"
174 user:
175 token: "$KUBETOKEN"
176EOF
177
178export KUBECONFIG=/root/.kube/config
179kubectl config view
180
181# wait for kubernetes to initialze
182sleep 100
183until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
184 sleep 10
185done
186
187
188# Install using OOM
189export HOME=/root
190
Gary Wu0dfbea32018-05-12 09:27:44 -0700191# update and initialize git
192apt-get -y install git
193git config --global user.email root@rancher
194git config --global user.name root@rancher
195git config --global log.decorate auto
196
Gary Wu14a6b302018-05-01 15:59:28 -0700197# Clone OOM:
198cd ~
Gary Wu81836d22018-06-22 13:48:50 -0700199git clone -b master https://gerrit.onap.org/r/oom
Gary Wu14a6b302018-05-01 15:59:28 -0700200cd oom
201git log -1
Gary Wu0dfbea32018-05-12 09:27:44 -0700202git tag -a "deploy0" -m "initial deployment"
203git checkout -b workarounds
Gary Wu14a6b302018-05-01 15:59:28 -0700204
Gary Wu81836d22018-06-22 13:48:50 -0700205# Clone integration
206cd ~
207git clone -b __gerrit_branch__ https://gerrit.onap.org/r/integration
208cd integration
209git fetch https://gerrit.onap.org/r/integration __gerrit_refspec__
210git checkout FETCH_HEAD
211
212cd version-manifest/src/main/scripts
213./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/
214
215cd ~/oom
216git diff
217
218
Gary Wu14a6b302018-05-01 15:59:28 -0700219# Run ONAP:
220cd ~/oom/kubernetes/
Gary Wu14a6b302018-05-01 15:59:28 -0700221helm init --client-only
222helm init --upgrade
223helm serve &
224sleep 3
225helm repo add local http://127.0.0.1:8879
226helm repo list
227make all
228helm search -l | grep local
Gary Wu11c98742018-05-02 16:19:04 -0700229helm install local/onap -n dev --namespace onap -f ~/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -0700230
hector56bc0dd2018-06-01 20:00:43 -0400231# Enable auto-completion for kubectl
232echo "source <(kubectl completion bash)" >> ~/.bashrc
Gary Wu14a6b302018-05-01 15:59:28 -0700233
234# Check ONAP status:
235sleep 3
236kubectl get pods --all-namespaces