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