3 # Copyright 2018 Huawei Technologies Co., Ltd.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
15 echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt
16 echo "__k8s_vm_ips__" > /opt/config/k8s_vm_ips.txt
17 echo "__k8s_private_ips__" > /opt/config/k8s_private_ips.txt
18 echo "__public_net_id__" > /opt/config/public_net_id.txt
19 echo "__oam_network_cidr__" > /opt/config/oam_network_cidr.txt
20 echo "__oam_network_id__" > /opt/config/oam_network_id.txt
21 echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt
22 echo "__integration_gerrit_branch__" > /opt/config/integration_gerrit_branch.txt
23 echo "__integration_gerrit_refspec__" > /opt/config/integration_gerrit_refspec.txt
24 echo "__oom_gerrit_branch__" > /opt/config/oom_gerrit_branch.txt
25 echo "__oom_gerrit_refspec__" > /opt/config/oom_gerrit_refspec.txt
26 echo "__docker_manifest__" > /opt/config/docker_manifest.txt
27 echo "__docker_proxy__" > /opt/config/docker_proxy.txt
28 echo "__docker_version__" > /opt/config/docker_version.txt
29 echo "__rancher_version__" > /opt/config/rancher_version.txt
30 echo "__rancher_agent_version__" > /opt/config/rancher_agent_version.txt
31 echo "__kubectl_version__" > /opt/config/kubectl_version.txt
32 echo "__helm_version__" > /opt/config/helm_version.txt
34 cat <<EOF > /opt/config/integration-override.yaml
35 __integration_override_yaml__
37 sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml
38 sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml
39 sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml
40 sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml
41 sed -i 's/\_\_rancher_ip_addr__/__rancher_ip_addr__/g' /opt/config/integration-override.yaml
42 sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml
43 sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml
44 cp /opt/config/integration-override.yaml /root
45 cat /root/integration-override.yaml
47 echo `hostname -I` `hostname` >> /etc/hosts
49 if [ ! -z "__docker_proxy__" ]; then
50 cat > /etc/docker/daemon.json <<EOF
52 "insecure-registries" : ["__docker_proxy__"]
56 if [ ! -z "__apt_proxy__" ]; then
57 cat > /etc/apt/apt.conf.d/30proxy<<EOF
58 Acquire::http { Proxy "http://__apt_proxy__"; };
59 Acquire::https::Proxy "DIRECT";
63 while ! hash jq &> /dev/null; do
65 apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server moreutils
69 # use RAM disk for /dockerdata-nfs for testing
70 echo "tmpfs /dockerdata-nfs tmpfs noatime,size=75% 1 2" >> /etc/fstab
71 mkdir -pv /dockerdata-nfs
74 # version control the persistence volume to see what's happening
75 chmod 777 /dockerdata-nfs/
76 chown nobody:nogroup /dockerdata-nfs/
79 git config user.email "root@onap"
80 git config user.name "root"
82 git commit -m "initial commit"
86 for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_private_ips.txt); do
87 NFS_EXP+="$K8S_VM_IP(rw,fsid=1,async,no_root_squash,no_subtree_check) "
89 echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports
93 systemctl restart nfs-kernel-server
97 # install docker __docker_version__
98 while ! hash docker &> /dev/null; do
99 curl -s https://releases.rancher.com/install-docker/__docker_version__.sh | sh
100 usermod -aG docker ubuntu
104 # install rancher __rancher_version__
105 docker 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__
107 # install kubectl __kubectl_version__
108 curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v__kubectl_version__/bin/linux/amd64/kubectl
110 sudo mv ./kubectl /usr/local/bin/kubectl
113 # install helm __helm_version__
114 wget -q http://storage.googleapis.com/kubernetes-helm/helm-v__helm_version__-linux-amd64.tar.gz
115 tar -zxvf helm-v__helm_version__-linux-amd64.tar.gz
116 sudo mv linux-amd64/helm /usr/local/bin/helm
118 echo export RANCHER_IP=__rancher_private_ip_addr__ > api-keys-rc
121 until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
124 OLD_PID=$(jq -r '.data[0].id' projects.json)
126 curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
127 echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
128 echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
132 curl -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
134 curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
136 until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
138 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
139 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
142 curl -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
143 PID=`jq -r '.id' project.json`
144 echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
147 until [ $(jq -r '.state' project.json) == "active" ]; do
149 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
153 curl -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
154 RID=$(jq -r '.id' registry.json)
157 curl -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"
161 TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
163 while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
165 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
167 jq -r .command token.json > rancher_agent_cmd.sh
168 chmod +x rancher_agent_cmd.sh
169 cp rancher_agent_cmd.sh /dockerdata-nfs
172 git commit -a -m "Add rancher agent command file"
176 KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
178 # create .kube/config
179 cat > ~/.kube/config <<EOF
185 insecure-skip-tls-verify: true
186 server: "https://__rancher_ip_addr__:8080/r/projects/$PID/kubernetes:6443"
193 current-context: "oom"
200 export KUBECONFIG=/root/.kube/config
203 # Enable auto-completion for kubectl
204 echo "source <(kubectl completion bash)" >> ~/.bashrc
207 # wait for kubernetes to initialze
209 until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
217 cp ~ubuntu/.ssh/authorized_keys ~/.ssh
220 # update and initialize git
221 apt-get -y install git
222 git config --global user.email root@rancher
223 git config --global user.name root@rancher
224 git config --global log.decorate auto
228 git clone -b __oom_gerrit_branch__ https://gerrit.onap.org/r/oom
230 git fetch https://gerrit.onap.org/r/oom __oom_gerrit_refspec__
231 git checkout FETCH_HEAD
232 git checkout -b workarounds
237 git clone -b __integration_gerrit_branch__ https://gerrit.onap.org/r/integration
239 git fetch https://gerrit.onap.org/r/integration __integration_gerrit_refspec__
240 git checkout FETCH_HEAD
242 if [ ! -z "__docker_manifest__" ]; then
243 cd version-manifest/src/main/scripts
244 ./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/
249 git commit -a -m "apply manifest versions"
250 git tag -a "deploy0" -m "initial deployment"
255 helm init --client-only
259 helm repo add local http://127.0.0.1:8879
262 rsync -avt ~/oom/kubernetes/helm/plugins ~/.helm/
263 helm search -l | grep local
264 helm deploy dev local/onap -f ~/integration-override.yaml --namespace onap | tee ~/helm-deploy.log
270 kubectl get pods --all-namespaces