Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 1 | #!/bin/bash -x |
Gary Wu | a3fb86f | 2018-06-04 16:23:54 -0700 | [diff] [blame] | 2 | # |
| 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 Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 12 | printenv |
| 13 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 14 | mkdir -p /opt/config |
| 15 | echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt |
| 16 | echo "__k8s_vm_ips__" > /opt/config/k8s_vm_ips.txt |
Gary Wu | 978171e | 2018-07-24 11:56:01 -0700 | [diff] [blame] | 17 | echo "__public_net_id__" > /opt/config/public_net_id.txt |
| 18 | echo "__oam_network_cidr__" > /opt/config/oam_network_cidr.txt |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 19 | echo "__oam_network_id__" > /opt/config/oam_network_id.txt |
| 20 | echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt |
Gary Wu | 81836d2 | 2018-06-22 13:48:50 -0700 | [diff] [blame] | 21 | echo "__gerrit_branch__" > /opt/config/gerrit_branch.txt |
| 22 | echo "__gerrit_refspec__" > /opt/config/gerrit_refspec.txt |
| 23 | echo "__docker_manifest__" > /opt/config/docker_manifest.txt |
Gary Wu | 978171e | 2018-07-24 11:56:01 -0700 | [diff] [blame] | 24 | echo "__docker_proxy__" > /opt/config/docker_proxy.txt |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 25 | |
| 26 | cat <<EOF > /opt/config/integration-override.yaml |
| 27 | __integration_override_yaml__ |
| 28 | EOF |
Gary Wu | 978171e | 2018-07-24 11:56:01 -0700 | [diff] [blame] | 29 | sed -i 's/\_\_public_net_id__/__public_net_id__/g' /opt/config/integration-override.yaml |
| 30 | sed -i 's|\_\_oam_network_cidr__|__oam_network_cidr__|g' /opt/config/integration-override.yaml |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 31 | sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml |
| 32 | sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml |
Gary Wu | 0a67162 | 2018-05-14 12:59:03 -0700 | [diff] [blame] | 33 | sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml |
Gary Wu | 978171e | 2018-07-24 11:56:01 -0700 | [diff] [blame] | 34 | sed -i 's/\_\_docker_proxy__/__docker_proxy__/g' /opt/config/integration-override.yaml |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 35 | cp /opt/config/integration-override.yaml /root |
Gary Wu | 978171e | 2018-07-24 11:56:01 -0700 | [diff] [blame] | 36 | cat /root/integration-override.yaml |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 37 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 38 | echo `hostname -I` `hostname` >> /etc/hosts |
| 39 | mkdir -p /etc/docker |
Gary Wu | 3ad596f | 2018-02-08 07:16:37 -0800 | [diff] [blame] | 40 | if [ ! -z "__docker_proxy__" ]; then |
| 41 | cat > /etc/docker/daemon.json <<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 42 | { |
| 43 | "insecure-registries" : ["__docker_proxy__"] |
| 44 | } |
| 45 | EOF |
Gary Wu | 3ad596f | 2018-02-08 07:16:37 -0800 | [diff] [blame] | 46 | fi |
| 47 | if [ ! -z "__apt_proxy__" ]; then |
| 48 | cat > /etc/apt/apt.conf.d/30proxy<<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 49 | Acquire::http { Proxy "http://__apt_proxy__"; }; |
| 50 | Acquire::https::Proxy "DIRECT"; |
| 51 | EOF |
Gary Wu | 3ad596f | 2018-02-08 07:16:37 -0800 | [diff] [blame] | 52 | fi |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 53 | apt-get -y update |
Gary Wu | bc76450 | 2018-06-28 16:13:41 -0700 | [diff] [blame] | 54 | apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server moreutils |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 55 | |
| 56 | |
Gary Wu | c474970 | 2018-06-26 14:27:41 -0700 | [diff] [blame] | 57 | # use RAM disk for /dockerdata-nfs for testing |
Gary Wu | bc76450 | 2018-06-28 16:13:41 -0700 | [diff] [blame] | 58 | echo "tmpfs /dockerdata-nfs tmpfs noatime 1 2" >> /etc/fstab |
Gary Wu | c474970 | 2018-06-26 14:27:41 -0700 | [diff] [blame] | 59 | mkdir -pv /dockerdata-nfs |
| 60 | mount /dockerdata-nfs |
| 61 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 62 | # version control the persistence volume to see what's happening |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 63 | chmod 777 /dockerdata-nfs/ |
| 64 | chown nobody:nogroup /dockerdata-nfs/ |
| 65 | cd /dockerdata-nfs/ |
| 66 | git init |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 67 | git config user.email "root@onap" |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 68 | git config user.name "root" |
| 69 | git add -A |
| 70 | git commit -m "initial commit" |
| 71 | |
| 72 | # export NFS mount |
| 73 | NFS_EXP="" |
| 74 | for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_vm_ips.txt); do |
Gary Wu | bc76450 | 2018-06-28 16:13:41 -0700 | [diff] [blame] | 75 | NFS_EXP+="$K8S_VM_IP(rw,fsid=1,sync,no_root_squash,no_subtree_check) " |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 76 | done |
| 77 | echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports |
| 78 | |
| 79 | |
| 80 | exportfs -a |
| 81 | systemctl restart nfs-kernel-server |
| 82 | |
| 83 | cd ~ |
| 84 | |
| 85 | # install docker 17.03 |
| 86 | curl -s https://releases.rancher.com/install-docker/17.03.sh | sh |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 87 | usermod -aG docker ubuntu |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 88 | |
| 89 | docker 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 |
| 90 | |
Gary Wu | a0fe61c | 2018-06-08 08:06:47 -0700 | [diff] [blame] | 91 | # install kubernetes 1.8.10 |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 92 | curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.10/bin/linux/amd64/kubectl |
| 93 | chmod +x ./kubectl |
| 94 | sudo mv ./kubectl /usr/local/bin/kubectl |
| 95 | mkdir ~/.kube |
| 96 | |
| 97 | # install helm |
| 98 | wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz |
| 99 | tar -zxvf helm-v2.8.2-linux-amd64.tar.gz |
| 100 | sudo mv linux-amd64/helm /usr/local/bin/helm |
| 101 | |
| 102 | echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc |
| 103 | source api-keys-rc |
| 104 | |
| 105 | sleep 50 |
| 106 | until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do |
| 107 | sleep 10 |
| 108 | done |
| 109 | OLD_PID=$(jq -r '.data[0].id' projects.json) |
| 110 | |
| 111 | curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json |
| 112 | echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc |
| 113 | echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc |
| 114 | source api-keys-rc |
| 115 | |
| 116 | |
| 117 | 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 |
| 118 | |
| 119 | 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" |
| 120 | |
| 121 | until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do |
| 122 | sleep 5 |
| 123 | curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json |
| 124 | TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json) |
| 125 | done |
| 126 | |
| 127 | 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 |
| 128 | PID=`jq -r '.id' project.json` |
| 129 | echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc |
| 130 | source api-keys-rc |
| 131 | |
| 132 | until [ $(jq -r '.state' project.json) == "active" ]; do |
| 133 | sleep 5 |
| 134 | curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json |
| 135 | done |
| 136 | |
| 137 | |
| 138 | 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 |
| 139 | RID=$(jq -r '.id' registry.json) |
| 140 | |
| 141 | |
| 142 | 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" |
| 143 | |
| 144 | |
| 145 | |
| 146 | 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') |
| 147 | touch token.json |
| 148 | while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do |
| 149 | sleep 5 |
| 150 | curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json |
| 151 | done |
| 152 | jq -r .command token.json > rancher_agent_cmd.sh |
| 153 | chmod +x rancher_agent_cmd.sh |
| 154 | cp rancher_agent_cmd.sh /dockerdata-nfs |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 155 | cd /dockerdata-nfs |
| 156 | git add -A |
| 157 | git commit -a -m "Add rancher agent command file" |
| 158 | cd ~ |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 159 | |
| 160 | |
| 161 | KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0) |
| 162 | |
| 163 | # create .kube/config |
| 164 | cat > ~/.kube/config <<EOF |
| 165 | apiVersion: v1 |
| 166 | kind: Config |
| 167 | clusters: |
| 168 | - cluster: |
| 169 | api-version: v1 |
| 170 | insecure-skip-tls-verify: true |
| 171 | server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443" |
| 172 | name: "oom" |
| 173 | contexts: |
| 174 | - context: |
| 175 | cluster: "oom" |
| 176 | user: "oom" |
| 177 | name: "oom" |
| 178 | current-context: "oom" |
| 179 | users: |
| 180 | - name: "oom" |
| 181 | user: |
| 182 | token: "$KUBETOKEN" |
| 183 | EOF |
| 184 | |
| 185 | export KUBECONFIG=/root/.kube/config |
| 186 | kubectl config view |
| 187 | |
| 188 | # wait for kubernetes to initialze |
| 189 | sleep 100 |
| 190 | until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do |
| 191 | sleep 10 |
| 192 | done |
| 193 | |
| 194 | |
| 195 | # Install using OOM |
| 196 | export HOME=/root |
Gary Wu | 978171e | 2018-07-24 11:56:01 -0700 | [diff] [blame] | 197 | mkdir -p ~/.ssh |
| 198 | cp ~ubuntu/.ssh/authorized_keys ~/.ssh |
| 199 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 200 | |
Gary Wu | 0dfbea3 | 2018-05-12 09:27:44 -0700 | [diff] [blame] | 201 | # update and initialize git |
| 202 | apt-get -y install git |
| 203 | git config --global user.email root@rancher |
| 204 | git config --global user.name root@rancher |
| 205 | git config --global log.decorate auto |
| 206 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 207 | # Clone OOM: |
| 208 | cd ~ |
Gary Wu | 81836d2 | 2018-06-22 13:48:50 -0700 | [diff] [blame] | 209 | git clone -b master https://gerrit.onap.org/r/oom |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 210 | cd oom |
| 211 | git log -1 |
Gary Wu | 0dfbea3 | 2018-05-12 09:27:44 -0700 | [diff] [blame] | 212 | git tag -a "deploy0" -m "initial deployment" |
| 213 | git checkout -b workarounds |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 214 | |
Gary Wu | 81836d2 | 2018-06-22 13:48:50 -0700 | [diff] [blame] | 215 | # Clone integration |
| 216 | cd ~ |
| 217 | git clone -b __gerrit_branch__ https://gerrit.onap.org/r/integration |
| 218 | cd integration |
| 219 | git fetch https://gerrit.onap.org/r/integration __gerrit_refspec__ |
| 220 | git checkout FETCH_HEAD |
| 221 | |
| 222 | cd version-manifest/src/main/scripts |
| 223 | ./update-oom-image-versions.sh ../resources/__docker_manifest__ ~/oom/ |
| 224 | |
| 225 | cd ~/oom |
| 226 | git diff |
| 227 | |
| 228 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 229 | # Run ONAP: |
| 230 | cd ~/oom/kubernetes/ |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 231 | helm init --client-only |
| 232 | helm init --upgrade |
| 233 | helm serve & |
| 234 | sleep 3 |
| 235 | helm repo add local http://127.0.0.1:8879 |
| 236 | helm repo list |
| 237 | make all |
| 238 | helm search -l | grep local |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 239 | helm install local/onap -n dev --namespace onap -f ~/integration-override.yaml |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 240 | |
hector | 56bc0dd | 2018-06-01 20:00:43 -0400 | [diff] [blame] | 241 | # Enable auto-completion for kubectl |
| 242 | echo "source <(kubectl completion bash)" >> ~/.bashrc |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 243 | |
| 244 | # Check ONAP status: |
| 245 | sleep 3 |
| 246 | kubectl get pods --all-namespaces |