demo-infra-jenkins-install.sh 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/sh

__is_pod_ready() {
  POD_STATUS="False"
  while [ "$POD_STATUS" != "True" ];
  do
    echo "waiting for pod..."
    sleep 5
    POD_STATUS=$(kubectl get pods --namespace demo-infra -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=demo-infra-jenkins" -o jsonpath='{..status.conditions[?(@.type=="Ready")].status}')
  done
}

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
__expose_pod() {
  # kill any previous proxy
  kill $(ps aux | grep '8180[:]8080' | awk '{print $2}')

  # print admin password
  export JENKINS_PASS=$(kubectl get secret --namespace demo-infra demo-infra-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode)
  echo "HOST: http://192.168.1.194:8180  USERNAME: admin  PASSWORD: $JENKINS_PASS"

  # expose
  export POD_NAME=$(kubectl get pods --namespace demo-infra -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=demo-infra-jenkins" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace demo-infra port-forward $POD_NAME 8180:8080  --address 0.0.0.0 &
}

POD_STATUS=$(kubectl get pods --namespace demo-infra -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=demo-infra-jenkins" -o jsonpath='{..status.conditions[?(@.type=="Ready")].status}')
if [ "$POD_STATUS" = 'True' ]; then
  echo "pod already installed, exposing it..."

  # create proxy into the pod
  __expose_pod

else
  echo "pod missing, installing it..."

  # install nexus
  helm install -f values.yaml --namespace demo-infra --kubeconfig ~/.kube/config demo-infra-jenkins ./
38

39 40
  # wait for it to become ready
  __is_pod_ready
41

42 43
  # create proxy into the pod
  __expose_pod
44

45
fi