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