blob: 3bc811b8f2e938f3b209d6f5a1f4bfaa4963f9b4 [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 Wu3fd6c2a2018-10-28 21:44:00 -070012export DEBIAN_FRONTEND=noninteractive
Gary Wu1ff56672018-01-17 20:51:45 -080013printenv
14
Gary Wu14a6b302018-05-01 15:59:28 -070015mkdir -p /opt/config
16echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt
17echo "__k8s_vm_ips__" > /opt/config/k8s_vm_ips.txt
Gary Wuad513722018-07-26 13:08:47 -070018echo "__k8s_private_ips__" > /opt/config/k8s_private_ips.txt
Gary Wu978171e2018-07-24 11:56:01 -070019echo "__public_net_id__" > /opt/config/public_net_id.txt
20echo "__oam_network_cidr__" > /opt/config/oam_network_cidr.txt
Gary Wu11c98742018-05-02 16:19:04 -070021echo "__oam_network_id__" > /opt/config/oam_network_id.txt
22echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt
Gary Wu17440fe2018-10-22 15:12:07 -070023echo "__sec_group__" > /opt/config/sec_group.txt
Gary Wu87aa8b52018-08-09 08:10:24 -070024echo "__integration_gerrit_branch__" > /opt/config/integration_gerrit_branch.txt
25echo "__integration_gerrit_refspec__" > /opt/config/integration_gerrit_refspec.txt
26echo "__oom_gerrit_branch__" > /opt/config/oom_gerrit_branch.txt
27echo "__oom_gerrit_refspec__" > /opt/config/oom_gerrit_refspec.txt
Gary Wu81836d22018-06-22 13:48:50 -070028echo "__docker_manifest__" > /opt/config/docker_manifest.txt
Gary Wu978171e2018-07-24 11:56:01 -070029echo "__docker_proxy__" > /opt/config/docker_proxy.txt
Gary Wu7a04b3d2018-08-15 12:31:46 -070030echo "__docker_version__" > /opt/config/docker_version.txt
31echo "__rancher_version__" > /opt/config/rancher_version.txt
32echo "__rancher_agent_version__" > /opt/config/rancher_agent_version.txt
33echo "__kubectl_version__" > /opt/config/kubectl_version.txt
34echo "__helm_version__" > /opt/config/helm_version.txt
Gary Wu11c98742018-05-02 16:19:04 -070035
36cat <<EOF > /opt/config/integration-override.yaml
37__integration_override_yaml__
38EOF
Gary Wu978171e2018-07-24 11:56:01 -070039sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml
40sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070041sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml
42sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml
Gary Wu17440fe2018-10-22 15:12:07 -070043sed -i 's/\_\_sec_group__/__sec_group__/g' /opt/config/integration-override.yaml
Gary Wued95ca72018-07-26 10:24:51 -070044sed -i 's/\_\_rancher_ip_addr__/__rancher_ip_addr__/g' /opt/config/integration-override.yaml
Gary Wu0a671622018-05-14 12:59:03 -070045sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml
Gary Wu978171e2018-07-24 11:56:01 -070046sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml
Gary Wu11c98742018-05-02 16:19:04 -070047cp /opt/config/integration-override.yaml /root
Gary Wu978171e2018-07-24 11:56:01 -070048cat /root/integration-override.yaml
Gary Wu14a6b302018-05-01 15:59:28 -070049
Gary Wu1ff56672018-01-17 20:51:45 -080050echo `hostname -I` `hostname` >> /etc/hosts
51mkdir -p /etc/docker
Gary Wu3ad596f2018-02-08 07:16:37 -080052if [ ! -z "__docker_proxy__" ]; then
53 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080054{
55 "insecure-registries" : ["__docker_proxy__"]
56}
57EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080058fi
59if [ ! -z "__apt_proxy__" ]; then
60 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080061Acquire::http { Proxy "http://__apt_proxy__"; };
62Acquire::https::Proxy "DIRECT";
63EOF
Gary Wu3ad596f2018-02-08 07:16:37 -080064fi
Gary Wu14a6b302018-05-01 15:59:28 -070065
Gary Wu675eb152018-10-26 10:50:27 -070066# workaround for OpenStack intermittent failure to change default apt mirrors
67sed -i 's|http://archive.ubuntu.com|http://nova.clouds.archive.ubuntu.com|g' /etc/apt/sources.list
68
Gary Wub0e36502018-10-16 11:01:07 -070069while ! hash jq &> /dev/null; do
70 apt-get -y update
Gary Wu675eb152018-10-26 10:50:27 -070071 apt-get -y install linux-image-extra-$(uname -r) apt-transport-https ca-certificates curl software-properties-common jq make nfs-kernel-server moreutils
Gary Wub0e36502018-10-16 11:01:07 -070072 sleep 10
73done
Gary Wu14a6b302018-05-01 15:59:28 -070074
Gary Wuc4749702018-06-26 14:27:41 -070075# use RAM disk for /dockerdata-nfs for testing
Gary Wu1ac48832018-10-18 16:08:19 -070076echo "tmpfs /dockerdata-nfs tmpfs noatime,size=75% 1 2" >> /etc/fstab
Gary Wuece58582018-10-01 15:15:17 -070077mkdir -pv /dockerdata-nfs
Gary Wu1ac48832018-10-18 16:08:19 -070078mount /dockerdata-nfs
Gary Wuc4749702018-06-26 14:27:41 -070079
Gary Wu14a6b302018-05-01 15:59:28 -070080# version control the persistence volume to see what's happening
Gary Wu14a6b302018-05-01 15:59:28 -070081chmod 777 /dockerdata-nfs/
82chown nobody:nogroup /dockerdata-nfs/
83cd /dockerdata-nfs/
84git init
Gary Wu11c98742018-05-02 16:19:04 -070085git config user.email "root@onap"
Gary Wu14a6b302018-05-01 15:59:28 -070086git config user.name "root"
87git add -A
88git commit -m "initial commit"
89
90# export NFS mount
Gary Wu3fd6c2a2018-10-28 21:44:00 -070091echo "/dockerdata-nfs *(rw,fsid=1,async,no_root_squash,no_subtree_check)" | tee /etc/exports
Gary Wu14a6b302018-05-01 15:59:28 -070092
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 Wu3fd6c2a2018-10-28 21:44:00 -0700105apt-mark hold docker-ce
Gary Wu14a6b302018-05-01 15:59:28 -0700106
Gary Wu7a04b3d2018-08-15 12:31:46 -0700107# install rancher __rancher_version__
Gary Wu3fd6c2a2018-10-28 21:44:00 -0700108docker run --name rancher-server --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 -0700109
Gary Wu7a04b3d2018-08-15 12:31:46 -0700110# install kubectl __kubectl_version__
111curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v__kubectl_version__/bin/linux/amd64/kubectl
Gary Wu14a6b302018-05-01 15:59:28 -0700112chmod +x ./kubectl
113sudo mv ./kubectl /usr/local/bin/kubectl
114mkdir ~/.kube
115
Gary Wu7a04b3d2018-08-15 12:31:46 -0700116# install helm __helm_version__
117wget -q http://storage.googleapis.com/kubernetes-helm/helm-v__helm_version__-linux-amd64.tar.gz
118tar -zxvf helm-v__helm_version__-linux-amd64.tar.gz
Gary Wu14a6b302018-05-01 15:59:28 -0700119sudo mv linux-amd64/helm /usr/local/bin/helm
120
Gary Wuad513722018-07-26 13:08:47 -0700121echo export RANCHER_IP=__rancher_private_ip_addr__ > api-keys-rc
Gary Wu14a6b302018-05-01 15:59:28 -0700122source api-keys-rc
123
Gary Wu14a6b302018-05-01 15:59:28 -0700124until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
Gary Wub0e36502018-10-16 11:01:07 -0700125 sleep 30
Gary Wu14a6b302018-05-01 15:59:28 -0700126done
127OLD_PID=$(jq -r '.data[0].id' projects.json)
128
129curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
Gary Wu3fd6c2a2018-10-28 21:44:00 -0700130echo export CATTLE_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
131echo export CATTLE_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
Gary Wu14a6b302018-05-01 15:59:28 -0700132source api-keys-rc
133
134
Gary Wu3fd6c2a2018-10-28 21:44:00 -0700135curl -u "${CATTLE_ACCESS_KEY}:${CATTLE_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
Gary Wu14a6b302018-05-01 15:59:28 -0700136
Gary Wu3fd6c2a2018-10-28 21:44:00 -0700137curl -s -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
Gary Wu14a6b302018-05-01 15:59:28 -0700138
139until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
140 sleep 5
141 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
142 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
143done
144
Gary Wu3fd6c2a2018-10-28 21:44:00 -0700145
146curl -s -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" \
147-X PUT \
148-H 'Accept: application/json' \
149-H 'Content-Type: application/json' \
150-d '{"stacks":[{"type":"catalogTemplate", "answers":{"CONSTRAINT_TYPE":"required"}, "name":"kubernetes", "templateVersionId":"library:infra*k8s:52"}, {"type":"catalogTemplate", "name":"network-services", "templateId":"library:infra*network-services"}, {"type":"catalogTemplate", "name":"ipsec", "templateId":"library:infra*ipsec"}, {"type":"catalogTemplate", "name":"healthcheck", "templateId":"library:infra*healthcheck"}]}' \
151"http://$RANCHER_IP:8080/v2-beta/projecttemplates/$TEMPLATE_ID"
152
153curl -s -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" -X POST -H 'Content-Type: application/json' -d '{ "name":"oom", "projectTemplateId":"'$TEMPLATE_ID'" }' "http://$RANCHER_IP:8080/v2-beta/projects" > project.json
Gary Wu14a6b302018-05-01 15:59:28 -0700154PID=`jq -r '.id' project.json`
155echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
156source api-keys-rc
157
158until [ $(jq -r '.state' project.json) == "active" ]; do
159 sleep 5
160 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
161done
162
163
Gary Wu3fd6c2a2018-10-28 21:44:00 -0700164curl -s -u $CATTLE_ACCESS_KEY:$CATTLE_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
Gary Wu14a6b302018-05-01 15:59:28 -0700165RID=$(jq -r '.id' registry.json)
166
167
Gary Wu3fd6c2a2018-10-28 21:44:00 -0700168curl -u "${CATTLE_ACCESS_KEY}:${CATTLE_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"
Gary Wu14a6b302018-05-01 15:59:28 -0700169
170
171
172TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
173touch token.json
174while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
175 sleep 5
176 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
177done
178jq -r .command token.json > rancher_agent_cmd.sh
179chmod +x rancher_agent_cmd.sh
180cp rancher_agent_cmd.sh /dockerdata-nfs
Gary Wu11c98742018-05-02 16:19:04 -0700181cd /dockerdata-nfs
182git add -A
183git commit -a -m "Add rancher agent command file"
184cd ~
Gary Wu14a6b302018-05-01 15:59:28 -0700185
186
Gary Wu3fd6c2a2018-10-28 21:44:00 -0700187KUBETOKEN=$(echo -n 'Basic '$(echo -n "$CATTLE_ACCESS_KEY:$CATTLE_SECRET_KEY" | base64 -w 0) | base64 -w 0)
Gary Wu14a6b302018-05-01 15:59:28 -0700188
189# create .kube/config
190cat > ~/.kube/config <<EOF
191apiVersion: v1
192kind: Config
193clusters:
194- cluster:
195 api-version: v1
196 insecure-skip-tls-verify: true
Gary Wuad513722018-07-26 13:08:47 -0700197 server: "https://__rancher_ip_addr__:8080/r/projects/$PID/kubernetes:6443"
Gary Wu14a6b302018-05-01 15:59:28 -0700198 name: "oom"
199contexts:
200- context:
201 cluster: "oom"
202 user: "oom"
203 name: "oom"
204current-context: "oom"
205users:
206- name: "oom"
207 user:
208 token: "$KUBETOKEN"
209EOF
210
211export KUBECONFIG=/root/.kube/config
212kubectl config view
213
Gary Wub0e36502018-10-16 11:01:07 -0700214# Enable auto-completion for kubectl
215echo "source <(kubectl completion bash)" >> ~/.bashrc
216
217
Gary Wu14a6b302018-05-01 15:59:28 -0700218# wait for kubernetes to initialze
Gary Wub0e36502018-10-16 11:01:07 -0700219sleep 3m
Gary Wu14a6b302018-05-01 15:59:28 -0700220until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
Gary Wub0e36502018-10-16 11:01:07 -0700221 sleep 1m
Gary Wu14a6b302018-05-01 15:59:28 -0700222done
223
224
225# Install using OOM
226export HOME=/root
Gary Wu978171e2018-07-24 11:56:01 -0700227mkdir -p ~/.ssh
228cp ~ubuntu/.ssh/authorized_keys ~/.ssh
229
Gary Wu14a6b302018-05-01 15:59:28 -0700230
Gary Wu0dfbea32018-05-12 09:27:44 -0700231# update and initialize git
232apt-get -y install git
233git config --global user.email root@rancher
234git config --global user.name root@rancher
235git config --global log.decorate auto
236
Gary Wu14a6b302018-05-01 15:59:28 -0700237# Clone OOM:
238cd ~
Gary Wu87aa8b52018-08-09 08:10:24 -0700239git clone -b __oom_gerrit_branch__ https://gerrit.onap.org/r/oom
Gary Wu14a6b302018-05-01 15:59:28 -0700240cd oom
Gary Wu87aa8b52018-08-09 08:10:24 -0700241git fetch https://gerrit.onap.org/r/oom __oom_gerrit_refspec__
242git checkout FETCH_HEAD
Gary Wu0dfbea32018-05-12 09:27:44 -0700243git checkout -b workarounds
Gary Wu87aa8b52018-08-09 08:10:24 -0700244git log -1
Gary Wu14a6b302018-05-01 15:59:28 -0700245
Gary Wu81836d22018-06-22 13:48:50 -0700246# Clone integration
247cd ~
Gary Wu87aa8b52018-08-09 08:10:24 -0700248git clone -b __integration_gerrit_branch__ https://gerrit.onap.org/r/integration
Gary Wu81836d22018-06-22 13:48:50 -0700249cd integration
Gary Wu87aa8b52018-08-09 08:10:24 -0700250git fetch https://gerrit.onap.org/r/integration __integration_gerrit_refspec__
Gary Wu81836d22018-06-22 13:48:50 -0700251git checkout FETCH_HEAD
252
Gary Wu87aa8b52018-08-09 08:10:24 -0700253if [ ! -z "__docker_manifest__" ]; then
254 cd version-manifest/src/main/scripts
255 ./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/
256fi
Gary Wu81836d22018-06-22 13:48:50 -0700257
258cd ~/oom
259git diff
Gary Wu87aa8b52018-08-09 08:10:24 -0700260git commit -a -m "apply manifest versions"
261git tag -a "deploy0" -m "initial deployment"
Gary Wu81836d22018-06-22 13:48:50 -0700262
263
Gary Wu14a6b302018-05-01 15:59:28 -0700264# Run ONAP:
265cd ~/oom/kubernetes/
Gary Wu14a6b302018-05-01 15:59:28 -0700266helm init --client-only
267helm init --upgrade
268helm serve &
Gary Wub0e36502018-10-16 11:01:07 -0700269sleep 10
Gary Wu14a6b302018-05-01 15:59:28 -0700270helm repo add local http://127.0.0.1:8879
271helm repo list
272make all
Gary Wu389aa902018-09-17 13:53:54 -0700273rsync -avt ~/oom/kubernetes/helm/plugins ~/.helm/
Gary Wu14a6b302018-05-01 15:59:28 -0700274helm search -l | grep local
Gary Wua8d6b122018-10-17 11:33:24 -0700275helm 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 -0700276helm list
Gary Wu14a6b302018-05-01 15:59:28 -0700277
278
279# Check ONAP status:
Gary Wub0e36502018-10-16 11:01:07 -0700280sleep 10
Gary Wu14a6b302018-05-01 15:59:28 -0700281kubectl get pods --all-namespaces
Gary Wub0e36502018-10-16 11:01:07 -0700282kubectl get nodes
283kubectl top nodes