|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +function install_bluemix_cli() { |
| 4 | +#statements |
| 5 | +echo "Installing Bluemix cli" |
| 6 | +curl -L "https://cli.run.pivotal.io/stable?release=linux64-binary&source=github" | tar -zx |
| 7 | +sudo mv cf /usr/local/bin |
| 8 | +sudo curl -o /usr/share/bash-completion/completions/cf https://raw.githubusercontent.com/cloudfoundry/cli/master/ci/installers/completion/cf |
| 9 | +cf --version |
| 10 | +curl -L public.dhe.ibm.com/cloud/bluemix/cli/bluemix-cli/Bluemix_CLI_0.5.1_amd64.tar.gz > Bluemix_CLI.tar.gz |
| 11 | +tar -xvf Bluemix_CLI.tar.gz |
| 12 | +cd Bluemix_CLI |
| 13 | +sudo ./install_bluemix_cli |
| 14 | +} |
| 15 | + |
| 16 | +function bluemix_auth() { |
| 17 | +echo "Authenticating with Bluemix" |
| 18 | +echo "1" | bx login -a https://api.ng.bluemix.net -u $BLUEMIX_USER -p $BLUEMIX_PASS |
| 19 | +curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl |
| 20 | +bx plugin install container-service -r Bluemix |
| 21 | +echo "Installing kubectl" |
| 22 | +chmod +x ./kubectl |
| 23 | +sudo mv ./kubectl /usr/local/bin/kubectl |
| 24 | +} |
| 25 | + |
| 26 | +function cluster_setup() { |
| 27 | +bx cs workers cluster-travis |
| 28 | +$(bx cs cluster-config cassandra-demo | grep export) |
| 29 | +git clone https://github.com/IBM/kubernetes-container-service-gameon-java-microservices.git |
| 30 | +cd kubernetes-container-service-gameon-java-microservices |
| 31 | +kubectl delete pvc -l app=gameon |
| 32 | +kubectl delete --ignore-not-found=true -f core |
| 33 | +kubectl delete --ignore-not-found=true -f platform |
| 34 | +kubectl delete --ignore-not-found=true -f setup.yaml |
| 35 | +kuber=$(kubectl get pods -l app=gameon) |
| 36 | +while [ ${#kuber} -ne 0 ] |
| 37 | +do |
| 38 | + sleep 5s |
| 39 | + kubectl get pods -l app=gameon |
| 40 | + kuber=$(kubectl get pods -l app=gameon) |
| 41 | +done |
| 42 | +kubectl delete --ignore-not-found=true -f local-volume.yaml |
| 43 | +} |
| 44 | + |
| 45 | +function initial_setup() { |
| 46 | +kubectl create -f local-volume.yaml |
| 47 | +sleep 5s |
| 48 | +kubectl create -f setup.yaml |
| 49 | +echo "Waiting for container to setup" |
| 50 | +sleep 15s |
| 51 | + |
| 52 | +keystore=$(kubectl logs setup | grep Import | awk '{print $4}') |
| 53 | +TRIES=0 |
| 54 | +while [ "$keystore" != "104" ] |
| 55 | +do |
| 56 | + echo "Setting up keystore values..." |
| 57 | + keystore=$(kubectl logs setup | grep Import | awk '{print $4}') |
| 58 | + if [ "$keystore" = "104" ] |
| 59 | + then |
| 60 | + echo "Setup successfull" |
| 61 | + break |
| 62 | + fi |
| 63 | + if [ $TRIES -eq 10 ] |
| 64 | + then |
| 65 | + echo "Failed setting up keystore values." |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + TRIES=$((TRIES+1)) |
| 69 | + sleep 5s |
| 70 | +done |
| 71 | +} |
| 72 | + |
| 73 | +function create_platform_services() { |
| 74 | +IP=$(kubectl get nodes | grep Ready | awk '{print $1}') |
| 75 | +kubectl create -f platform |
| 76 | + |
| 77 | +echo "Waiting for pods to setup" |
| 78 | +sleep 10s |
| 79 | +PODS=$(kubectl get pods | grep ContainerCreating | grep Pending) |
| 80 | +while [ ${#PODS} -ne 0 ] |
| 81 | +do |
| 82 | + echo "Pods are not yet Running..." |
| 83 | + PODS=$(kubectl get pods | grep ContainerCreating | grep Pending) |
| 84 | + sleep 5s |
| 85 | +done |
| 86 | + |
| 87 | +TRIES=0 |
| 88 | +while true |
| 89 | +do |
| 90 | +code=$(curl -w '%{http_code}' http://$IP:31200/health -o /dev/null) |
| 91 | + if [ "$code" = "200" ]; then |
| 92 | + echo "Controller is up" |
| 93 | + break |
| 94 | + fi |
| 95 | + if [ $TRIES -eq 10 ] |
| 96 | + then |
| 97 | + echo "Failed setting up controlplane." |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | + TRIES=$((TRIES+1)) |
| 101 | + sleep 5s |
| 102 | +done |
| 103 | + |
| 104 | +TRIES=0 |
| 105 | +while true |
| 106 | +do |
| 107 | +code=$(curl -w '%{http_code}' http://$IP:31300/uptime -o /dev/null) |
| 108 | + if [ "$code" = "200" ]; then |
| 109 | + echo "Registry is up" |
| 110 | + break |
| 111 | + fi |
| 112 | + if [ $TRIES -eq 10 ] |
| 113 | + then |
| 114 | + echo "Failed setting up controlplane." |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | + TRIES=$((TRIES+1)) |
| 118 | + sleep 5s |
| 119 | +done |
| 120 | +} |
| 121 | + |
| 122 | +function create_core_services() { |
| 123 | +IP=$(kubectl get nodes | grep Ready | awk '{print $1}') |
| 124 | + |
| 125 | +sed -i s#169.47.241.213#$IP#g core/* |
| 126 | + |
| 127 | +kubectl create -f core |
| 128 | + |
| 129 | +echo "Waiting for pods to setup" |
| 130 | +sleep 10s |
| 131 | +PODS=$(kubectl get pods | grep Pending) |
| 132 | +while [ ${#PODS} -ne 0 ] |
| 133 | +do |
| 134 | + echo "Some Pods are Pending..." |
| 135 | + PODS=$(kubectl get pods | grep Pending) |
| 136 | + sleep 5s |
| 137 | +done |
| 138 | + |
| 139 | +PODS=$(kubectl get pods | grep ContainerCreating) |
| 140 | +while [ ${#PODS} -ne 0 ] |
| 141 | +do |
| 142 | + echo "Some Pods are not yet Running..." |
| 143 | + PODS=$(kubectl get pods | grep ContainerCreating) |
| 144 | + sleep 5s |
| 145 | +done |
| 146 | + |
| 147 | +# kubectl logs $(kubectl get pods | grep proxy | awk '{print $1}') | tail -10 |
| 148 | + |
| 149 | +TRIES=0 |
| 150 | + |
| 151 | +while true |
| 152 | +do |
| 153 | +CORE=$(kubectl logs $(kubectl get pods | grep proxy | awk '{print $1}') | grep UP | awk '{print $8}' | xargs | sed -e s/,//g) |
| 154 | + |
| 155 | + if [ $CORE = "UP UP UP UP UP" ] |
| 156 | + then |
| 157 | + echo "You can now access your Gameon App at https://$IP:30443" |
| 158 | + echo "If you'd like to add social logins, please follow the instructions in the Repository's README" |
| 159 | + fi |
| 160 | + |
| 161 | + if [ $TRIES -eq 60 ] |
| 162 | + then |
| 163 | + echo "Failed to setup core services." |
| 164 | + echo "Printing running services detected by proxy:" |
| 165 | + kubectl logs $(kubectl get pods | grep proxy | awk '{print $1}') | grep UP | awk '{print $6}' |
| 166 | + exit 1 |
| 167 | + fi |
| 168 | + sleep 10s |
| 169 | +} |
| 170 | + |
| 171 | + |
| 172 | +install_bluemix_cli |
| 173 | +bluemix_auth |
| 174 | +initial_setup |
| 175 | +create_platform_services |
| 176 | +create_core_services |
0 commit comments