blob: 0a636e26076dc6f9106aa5566d023fae3c0a044e [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 Wu87aa8b52018-08-09 08:10:24 -070022echo "__integration_gerrit_branch__" > /opt/config/integration_gerrit_branch.txt
23echo "__integration_gerrit_refspec__" > /opt/config/integration_gerrit_refspec.txt
24echo "__oom_gerrit_branch__" > /opt/config/oom_gerrit_branch.txt
25echo "__oom_gerrit_refspec__" > /opt/config/oom_gerrit_refspec.txt
Gary Wu81836d22018-06-22 13:48:50 -070026echo "__docker_manifest__" > /opt/config/docker_manifest.txt
Gary Wu978171e2018-07-24 11:56:01 -070027echo "__docker_proxy__" > /opt/config/docker_proxy.txt
Gary Wu7a04b3d2018-08-15 12:31:46 -070028echo "__docker_version__" > /opt/config/docker_version.txt
29echo "__rancher_version__" > /opt/config/rancher_version.txt
30echo "__rancher_agent_version__" > /opt/config/rancher_agent_version.txt
31echo "__kubectl_version__" > /opt/config/kubectl_version.txt
32echo "__helm_version__" > /opt/config/helm_version.txt
Gary Wu11c98742018-05-02 16:19:04 -070033
34cat <<EOF > /opt/config/integration-override.yaml
35__integration_override_yaml__
36EOF
Gary Wu978171e2018-07-24 11:56:01 -070037sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml
38sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070039sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml
40sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml
Gary Wued95ca72018-07-26 10:24:51 -070041sed -i 's/\_\_rancher_ip_addr__/__rancher_ip_addr__/g' /opt/config/integration-override.yaml
Gary Wu0a671622018-05-14 12:59:03 -070042sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml
Gary Wu978171e2018-07-24 11:56:01 -070043sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070044cp /opt/config/integration-override.yaml /root
Gary Wu978171e2018-07-24 11:56:01 -070045cat /root/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -070046
Gary Wu1ff56672018-01-17 20:51:45 -080047echo `hostname -I` `hostname` >> /etc/hosts
48mkdir -p /etc/docker
Gary Wu3ad596f2018-02-08 07:16:37 -080049if [ ! -z "__docker_proxy__" ]; then
50 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080051{
52 "insecure-registries" : ["__docker_proxy__"]
53}
54EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080055fi
56if [ ! -z "__apt_proxy__" ]; then
57 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080058Acquire::http { Proxy "http://__apt_proxy__"; };
59Acquire::https::Proxy "DIRECT";
60EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080061fi
Gary Wu1ff56672018-01-17 20:51:45 -080062apt-get -y update
Gary Wubc764502018-06-28 16:13:41 -070063apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server moreutils
Gary Wu14a6b302018-05-01 15:59:28 -070064
65
Gary Wuc4749702018-06-26 14:27:41 -070066# use RAM disk for /dockerdata-nfs for testing
Gary Wubc764502018-06-28 16:13:41 -070067echo "tmpfs /dockerdata-nfs tmpfs noatime 1 2" >> /etc/fstab
Gary Wuc4749702018-06-26 14:27:41 -070068mkdir -pv /dockerdata-nfs
69mount /dockerdata-nfs
70
Gary Wu14a6b302018-05-01 15:59:28 -070071# version control the persistence volume to see what's happening
Gary Wu14a6b302018-05-01 15:59:28 -070072chmod 777 /dockerdata-nfs/
73chown nobody:nogroup /dockerdata-nfs/
74cd /dockerdata-nfs/
75git init
Gary Wu11c98742018-05-02 16:19:04 -070076git config user.email "root@onap"
Gary Wu14a6b302018-05-01 15:59:28 -070077git config user.name "root"
78git add -A
79git commit -m "initial commit"
80
81# export NFS mount
82NFS_EXP=""
Gary Wuad513722018-07-26 13:08:47 -070083for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_private_ips.txt); do
Gary Wubc764502018-06-28 16:13:41 -070084 NFS_EXP+="$K8S_VM_IP(rw,fsid=1,sync,no_root_squash,no_subtree_check) "
Gary Wu14a6b302018-05-01 15:59:28 -070085done
86echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports
87
88
89exportfs -a
90systemctl restart nfs-kernel-server
91
92cd ~
93
Gary Wu7a04b3d2018-08-15 12:31:46 -070094# install docker __docker_version__
95curl -s https://releases.rancher.com/install-docker/__docker_version__.sh | sh
Gary Wu1ff56672018-01-17 20:51:45 -080096usermod -aG docker ubuntu
Gary Wu14a6b302018-05-01 15:59:28 -070097
Gary Wu7a04b3d2018-08-15 12:31:46 -070098# install rancher __rancher_version__
99docker run --restart unless-stopped -d -p 8080:8080 -e CATTLE_BOOTSTRAP_REQUIRED_IMAGE=__docker_proxy__/rancher/agent:v__rancher_agent_version__ __docker_proxy__/rancher/server:v__rancher_version__
Gary Wu14a6b302018-05-01 15:59:28 -0700100
Gary Wu7a04b3d2018-08-15 12:31:46 -0700101# install kubectl __kubectl_version__
102curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v__kubectl_version__/bin/linux/amd64/kubectl
Gary Wu14a6b302018-05-01 15:59:28 -0700103chmod +x ./kubectl
104sudo mv ./kubectl /usr/local/bin/kubectl
105mkdir ~/.kube
106
Gary Wu7a04b3d2018-08-15 12:31:46 -0700107# install helm __helm_version__
108wget -q http://storage.googleapis.com/kubernetes-helm/helm-v__helm_version__-linux-amd64.tar.gz
109tar -zxvf helm-v__helm_version__-linux-amd64.tar.gz
Gary Wu14a6b302018-05-01 15:59:28 -0700110sudo mv linux-amd64/helm /usr/local/bin/helm
111
Gary Wuad513722018-07-26 13:08:47 -0700112echo export RANCHER_IP=__rancher_private_ip_addr__ > api-keys-rc
Gary Wu14a6b302018-05-01 15:59:28 -0700113source api-keys-rc
114
115sleep 50
116until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
117 sleep 10
118done
119OLD_PID=$(jq -r '.data[0].id' projects.json)
120
121curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
122echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
123echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
124source api-keys-rc
125
126
127curl -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
128
129curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
130
131until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
132 sleep 5
133 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
134 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
135done
136
137curl -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
138PID=`jq -r '.id' project.json`
139echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
140source api-keys-rc
141
142until [ $(jq -r '.state' project.json) == "active" ]; do
143 sleep 5
144 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
145done
146
147
148curl -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
149RID=$(jq -r '.id' registry.json)
150
151
152curl -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"
153
154
155
156TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
157touch token.json
158while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
159 sleep 5
160 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
161done
162jq -r .command token.json > rancher_agent_cmd.sh
163chmod +x rancher_agent_cmd.sh
164cp rancher_agent_cmd.sh /dockerdata-nfs
Gary Wu11c98742018-05-02 16:19:04 -0700165cd /dockerdata-nfs
166git add -A
167git commit -a -m "Add rancher agent command file"
168cd ~
Gary Wu14a6b302018-05-01 15:59:28 -0700169
170
171KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
172
173# create .kube/config
174cat > ~/.kube/config <<EOF
175apiVersion: v1
176kind: Config
177clusters:
178- cluster:
179 api-version: v1
180 insecure-skip-tls-verify: true
Gary Wuad513722018-07-26 13:08:47 -0700181 server: "https://__rancher_ip_addr__:8080/r/projects/$PID/kubernetes:6443"
Gary Wu14a6b302018-05-01 15:59:28 -0700182 name: "oom"
183contexts:
184- context:
185 cluster: "oom"
186 user: "oom"
187 name: "oom"
188current-context: "oom"
189users:
190- name: "oom"
191 user:
192 token: "$KUBETOKEN"
193EOF
194
195export KUBECONFIG=/root/.kube/config
196kubectl config view
197
198# wait for kubernetes to initialze
199sleep 100
200until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
201 sleep 10
202done
203
204
205# Install using OOM
206export HOME=/root
Gary Wu978171e2018-07-24 11:56:01 -0700207mkdir -p ~/.ssh
208cp ~ubuntu/.ssh/authorized_keys ~/.ssh
209
Gary Wu14a6b302018-05-01 15:59:28 -0700210
Gary Wu0dfbea32018-05-12 09:27:44 -0700211# update and initialize git
212apt-get -y install git
213git config --global user.email root@rancher
214git config --global user.name root@rancher
215git config --global log.decorate auto
216
Gary Wu14a6b302018-05-01 15:59:28 -0700217# Clone OOM:
218cd ~
Gary Wu87aa8b52018-08-09 08:10:24 -0700219git clone -b __oom_gerrit_branch__ https://gerrit.onap.org/r/oom
Gary Wu14a6b302018-05-01 15:59:28 -0700220cd oom
Gary Wu87aa8b52018-08-09 08:10:24 -0700221git fetch https://gerrit.onap.org/r/oom __oom_gerrit_refspec__
222git checkout FETCH_HEAD
Gary Wu0dfbea32018-05-12 09:27:44 -0700223git checkout -b workarounds
Gary Wu87aa8b52018-08-09 08:10:24 -0700224git log -1
Gary Wu14a6b302018-05-01 15:59:28 -0700225
Gary Wu81836d22018-06-22 13:48:50 -0700226# Clone integration
227cd ~
Gary Wu87aa8b52018-08-09 08:10:24 -0700228git clone -b __integration_gerrit_branch__ https://gerrit.onap.org/r/integration
Gary Wu81836d22018-06-22 13:48:50 -0700229cd integration
Gary Wu87aa8b52018-08-09 08:10:24 -0700230git fetch https://gerrit.onap.org/r/integration __integration_gerrit_refspec__
Gary Wu81836d22018-06-22 13:48:50 -0700231git checkout FETCH_HEAD
232
Gary Wu87aa8b52018-08-09 08:10:24 -0700233if [ ! -z "__docker_manifest__" ]; then
234 cd version-manifest/src/main/scripts
235 ./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/
236fi
Gary Wu81836d22018-06-22 13:48:50 -0700237
238cd ~/oom
239git diff
Gary Wu87aa8b52018-08-09 08:10:24 -0700240git commit -a -m "apply manifest versions"
241git tag -a "deploy0" -m "initial deployment"
Gary Wu81836d22018-06-22 13:48:50 -0700242
243
Gary Wu14a6b302018-05-01 15:59:28 -0700244# Run ONAP:
245cd ~/oom/kubernetes/
Gary Wu14a6b302018-05-01 15:59:28 -0700246helm init --client-only
247helm init --upgrade
248helm serve &
249sleep 3
250helm repo add local http://127.0.0.1:8879
251helm repo list
252make all
Gary Wu389aa902018-09-17 13:53:54 -0700253rsync -avt ~/oom/kubernetes/helm/plugins ~/.helm/
Gary Wu14a6b302018-05-01 15:59:28 -0700254helm search -l | grep local
Gary Wu389aa902018-09-17 13:53:54 -0700255helm deploy dev local/onap -f ~/integration-override.yaml --namespace onap | tee ~/helm-deploy.log
256helm list
Gary Wu14a6b302018-05-01 15:59:28 -0700257
hector56bc0dd2018-06-01 20:00:43 -0400258# Enable auto-completion for kubectl
259echo "source <(kubectl completion bash)" >> ~/.bashrc
Gary Wu14a6b302018-05-01 15:59:28 -0700260
261# Check ONAP status:
262sleep 3
263kubectl get pods --all-namespaces