blob: f90957a5645c874b8fce825be94d8b21c07418fc [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 Wu17440fe2018-10-22 15:12:07 -070022echo "__sec_group__" > /opt/config/sec_group.txt
Gary Wu87aa8b52018-08-09 08:10:24 -070023echo "__integration_gerrit_branch__" > /opt/config/integration_gerrit_branch.txt
24echo "__integration_gerrit_refspec__" > /opt/config/integration_gerrit_refspec.txt
25echo "__oom_gerrit_branch__" > /opt/config/oom_gerrit_branch.txt
26echo "__oom_gerrit_refspec__" > /opt/config/oom_gerrit_refspec.txt
Gary Wu81836d22018-06-22 13:48:50 -070027echo "__docker_manifest__" > /opt/config/docker_manifest.txt
Gary Wu978171e2018-07-24 11:56:01 -070028echo "__docker_proxy__" > /opt/config/docker_proxy.txt
Gary Wu7a04b3d2018-08-15 12:31:46 -070029echo "__docker_version__" > /opt/config/docker_version.txt
30echo "__rancher_version__" > /opt/config/rancher_version.txt
31echo "__rancher_agent_version__" > /opt/config/rancher_agent_version.txt
32echo "__kubectl_version__" > /opt/config/kubectl_version.txt
33echo "__helm_version__" > /opt/config/helm_version.txt
Gary Wu11c98742018-05-02 16:19:04 -070034
35cat <<EOF > /opt/config/integration-override.yaml
36__integration_override_yaml__
37EOF
Gary Wu978171e2018-07-24 11:56:01 -070038sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml
39sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070040sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml
41sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml
Gary Wu17440fe2018-10-22 15:12:07 -070042sed -i 's/\_\_sec_group__/__sec_group__/g' /opt/config/integration-override.yaml
Gary Wued95ca72018-07-26 10:24:51 -070043sed -i 's/\_\_rancher_ip_addr__/__rancher_ip_addr__/g' /opt/config/integration-override.yaml
Gary Wu0a671622018-05-14 12:59:03 -070044sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml
Gary Wu978171e2018-07-24 11:56:01 -070045sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070046cp /opt/config/integration-override.yaml /root
Gary Wu978171e2018-07-24 11:56:01 -070047cat /root/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -070048
Gary Wu1ff56672018-01-17 20:51:45 -080049echo `hostname -I` `hostname` >> /etc/hosts
50mkdir -p /etc/docker
Gary Wu3ad596f2018-02-08 07:16:37 -080051if [ ! -z "__docker_proxy__" ]; then
52 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080053{
54 "insecure-registries" : ["__docker_proxy__"]
55}
56EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080057fi
58if [ ! -z "__apt_proxy__" ]; then
59 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080060Acquire::http { Proxy "http://__apt_proxy__"; };
61Acquire::https::Proxy "DIRECT";
62EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080063fi
Gary Wu14a6b302018-05-01 15:59:28 -070064
Gary Wub0e36502018-10-16 11:01:07 -070065while ! hash jq &> /dev/null; do
66 apt-get -y update
67 apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server moreutils
68 sleep 10
69done
Gary Wu14a6b302018-05-01 15:59:28 -070070
Gary Wuc4749702018-06-26 14:27:41 -070071# use RAM disk for /dockerdata-nfs for testing
Gary Wu1ac48832018-10-18 16:08:19 -070072echo "tmpfs /dockerdata-nfs tmpfs noatime,size=75% 1 2" >> /etc/fstab
Gary Wuece58582018-10-01 15:15:17 -070073mkdir -pv /dockerdata-nfs
Gary Wu1ac48832018-10-18 16:08:19 -070074mount /dockerdata-nfs
Gary Wuc4749702018-06-26 14:27:41 -070075
Gary Wu14a6b302018-05-01 15:59:28 -070076# version control the persistence volume to see what's happening
Gary Wu14a6b302018-05-01 15:59:28 -070077chmod 777 /dockerdata-nfs/
78chown nobody:nogroup /dockerdata-nfs/
79cd /dockerdata-nfs/
80git init
Gary Wu11c98742018-05-02 16:19:04 -070081git config user.email "root@onap"
Gary Wu14a6b302018-05-01 15:59:28 -070082git config user.name "root"
83git add -A
84git commit -m "initial commit"
85
86# export NFS mount
87NFS_EXP=""
Gary Wuad513722018-07-26 13:08:47 -070088for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_private_ips.txt); do
Gary Wu1ac48832018-10-18 16:08:19 -070089 NFS_EXP+="$K8S_VM_IP(rw,fsid=1,async,no_root_squash,no_subtree_check) "
Gary Wu14a6b302018-05-01 15:59:28 -070090done
91echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports
92
93
94exportfs -a
95systemctl restart nfs-kernel-server
96
97cd ~
98
Gary Wu7a04b3d2018-08-15 12:31:46 -070099# install docker __docker_version__
Gary Wub0e36502018-10-16 11:01:07 -0700100while ! hash docker &> /dev/null; do
101 curl -s https://releases.rancher.com/install-docker/__docker_version__.sh | sh
102 usermod -aG docker ubuntu
103 sleep 10
104done
Gary Wu14a6b302018-05-01 15:59:28 -0700105
Gary Wu7a04b3d2018-08-15 12:31:46 -0700106# install rancher __rancher_version__
107docker 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 -0700108
Gary Wu7a04b3d2018-08-15 12:31:46 -0700109# install kubectl __kubectl_version__
110curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v__kubectl_version__/bin/linux/amd64/kubectl
Gary Wu14a6b302018-05-01 15:59:28 -0700111chmod +x ./kubectl
112sudo mv ./kubectl /usr/local/bin/kubectl
113mkdir ~/.kube
114
Gary Wu7a04b3d2018-08-15 12:31:46 -0700115# install helm __helm_version__
116wget -q http://storage.googleapis.com/kubernetes-helm/helm-v__helm_version__-linux-amd64.tar.gz
117tar -zxvf helm-v__helm_version__-linux-amd64.tar.gz
Gary Wu14a6b302018-05-01 15:59:28 -0700118sudo mv linux-amd64/helm /usr/local/bin/helm
119
Gary Wuad513722018-07-26 13:08:47 -0700120echo export RANCHER_IP=__rancher_private_ip_addr__ > api-keys-rc
Gary Wu14a6b302018-05-01 15:59:28 -0700121source api-keys-rc
122
Gary Wu14a6b302018-05-01 15:59:28 -0700123until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
Gary Wub0e36502018-10-16 11:01:07 -0700124 sleep 30
Gary Wu14a6b302018-05-01 15:59:28 -0700125done
126OLD_PID=$(jq -r '.data[0].id' projects.json)
127
128curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
129echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
130echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
131source api-keys-rc
132
133
134curl -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
135
136curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
137
138until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
139 sleep 5
140 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
141 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
142done
143
144curl -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
145PID=`jq -r '.id' project.json`
146echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
147source api-keys-rc
148
149until [ $(jq -r '.state' project.json) == "active" ]; do
150 sleep 5
151 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
152done
153
154
155curl -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
156RID=$(jq -r '.id' registry.json)
157
158
159curl -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"
160
161
162
163TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
164touch token.json
165while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
166 sleep 5
167 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
168done
169jq -r .command token.json > rancher_agent_cmd.sh
170chmod +x rancher_agent_cmd.sh
171cp rancher_agent_cmd.sh /dockerdata-nfs
Gary Wu11c98742018-05-02 16:19:04 -0700172cd /dockerdata-nfs
173git add -A
174git commit -a -m "Add rancher agent command file"
175cd ~
Gary Wu14a6b302018-05-01 15:59:28 -0700176
177
178KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
179
180# create .kube/config
181cat > ~/.kube/config <<EOF
182apiVersion: v1
183kind: Config
184clusters:
185- cluster:
186 api-version: v1
187 insecure-skip-tls-verify: true
Gary Wuad513722018-07-26 13:08:47 -0700188 server: "https://__rancher_ip_addr__:8080/r/projects/$PID/kubernetes:6443"
Gary Wu14a6b302018-05-01 15:59:28 -0700189 name: "oom"
190contexts:
191- context:
192 cluster: "oom"
193 user: "oom"
194 name: "oom"
195current-context: "oom"
196users:
197- name: "oom"
198 user:
199 token: "$KUBETOKEN"
200EOF
201
202export KUBECONFIG=/root/.kube/config
203kubectl config view
204
Gary Wub0e36502018-10-16 11:01:07 -0700205# Enable auto-completion for kubectl
206echo "source <(kubectl completion bash)" >> ~/.bashrc
207
208
Gary Wu14a6b302018-05-01 15:59:28 -0700209# wait for kubernetes to initialze
Gary Wub0e36502018-10-16 11:01:07 -0700210sleep 3m
Gary Wu14a6b302018-05-01 15:59:28 -0700211until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
Gary Wub0e36502018-10-16 11:01:07 -0700212 sleep 1m
Gary Wu14a6b302018-05-01 15:59:28 -0700213done
214
215
216# Install using OOM
217export HOME=/root
Gary Wu978171e2018-07-24 11:56:01 -0700218mkdir -p ~/.ssh
219cp ~ubuntu/.ssh/authorized_keys ~/.ssh
220
Gary Wu14a6b302018-05-01 15:59:28 -0700221
Gary Wu0dfbea32018-05-12 09:27:44 -0700222# update and initialize git
223apt-get -y install git
224git config --global user.email root@rancher
225git config --global user.name root@rancher
226git config --global log.decorate auto
227
Gary Wu14a6b302018-05-01 15:59:28 -0700228# Clone OOM:
229cd ~
Gary Wu87aa8b52018-08-09 08:10:24 -0700230git clone -b __oom_gerrit_branch__ https://gerrit.onap.org/r/oom
Gary Wu14a6b302018-05-01 15:59:28 -0700231cd oom
Gary Wu87aa8b52018-08-09 08:10:24 -0700232git fetch https://gerrit.onap.org/r/oom __oom_gerrit_refspec__
233git checkout FETCH_HEAD
Gary Wu0dfbea32018-05-12 09:27:44 -0700234git checkout -b workarounds
Gary Wu87aa8b52018-08-09 08:10:24 -0700235git log -1
Gary Wu14a6b302018-05-01 15:59:28 -0700236
Gary Wu81836d22018-06-22 13:48:50 -0700237# Clone integration
238cd ~
Gary Wu87aa8b52018-08-09 08:10:24 -0700239git clone -b __integration_gerrit_branch__ https://gerrit.onap.org/r/integration
Gary Wu81836d22018-06-22 13:48:50 -0700240cd integration
Gary Wu87aa8b52018-08-09 08:10:24 -0700241git fetch https://gerrit.onap.org/r/integration __integration_gerrit_refspec__
Gary Wu81836d22018-06-22 13:48:50 -0700242git checkout FETCH_HEAD
243
Gary Wu87aa8b52018-08-09 08:10:24 -0700244if [ ! -z "__docker_manifest__" ]; then
245 cd version-manifest/src/main/scripts
246 ./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/
247fi
Gary Wu81836d22018-06-22 13:48:50 -0700248
249cd ~/oom
250git diff
Gary Wu87aa8b52018-08-09 08:10:24 -0700251git commit -a -m "apply manifest versions"
252git tag -a "deploy0" -m "initial deployment"
Gary Wu81836d22018-06-22 13:48:50 -0700253
254
Gary Wu14a6b302018-05-01 15:59:28 -0700255# Run ONAP:
256cd ~/oom/kubernetes/
Gary Wu14a6b302018-05-01 15:59:28 -0700257helm init --client-only
258helm init --upgrade
259helm serve &
Gary Wub0e36502018-10-16 11:01:07 -0700260sleep 10
Gary Wu14a6b302018-05-01 15:59:28 -0700261helm repo add local http://127.0.0.1:8879
262helm repo list
263make all
Gary Wu389aa902018-09-17 13:53:54 -0700264rsync -avt ~/oom/kubernetes/helm/plugins ~/.helm/
Gary Wu14a6b302018-05-01 15:59:28 -0700265helm search -l | grep local
Gary Wua8d6b122018-10-17 11:33:24 -0700266helm deploy dev local/onap -f ~/oom/kubernetes/onap/resources/environments/public-cloud.yaml -f ~/integration-override.yaml --namespace onap | tee ~/helm-deploy.log
Gary Wu389aa902018-09-17 13:53:54 -0700267helm list
Gary Wu14a6b302018-05-01 15:59:28 -0700268
269
270# Check ONAP status:
Gary Wub0e36502018-10-16 11:01:07 -0700271sleep 10
Gary Wu14a6b302018-05-01 15:59:28 -0700272kubectl get pods --all-namespaces
Gary Wub0e36502018-10-16 11:01:07 -0700273kubectl get nodes
274kubectl top nodes