|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +echo This script helps configure codeflow for the initial deployment into a K8S environment. |
| 4 | +echo REQUIRES: jq |
| 5 | +echo |
| 6 | +echo Additional settings can be configured prior to running this script by editing the files: |
| 7 | +echo "* codeflow-services.yaml (optional annotations for your service like SSL)" |
| 8 | +echo "* ../server/configs/codeflow.dev.yml (optional)" |
| 9 | +echo |
| 10 | +if [ -z "$NONINTERACTIVE" ]; then |
| 11 | + read -p "Continue with the current settings? (y/n)" yn |
| 12 | + if [ "$yn" != "y" ]; then |
| 13 | + echo Aborting.. |
| 14 | + exit 1 |
| 15 | + fi |
| 16 | +fi |
| 17 | + |
| 18 | +# This requires jq to be installed |
| 19 | +if [ ! -x "$(command -v jq)" ]; then |
| 20 | + echo up.sh requires jq to be installed. |
| 21 | + echo OSX: brew install jq |
| 22 | + echo Linux: apt-get |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# Sanity check, the config exists |
| 27 | +if [ ! -e ../server/configs/codeflow.dev.yml ]; then |
| 28 | + echo file not found: ../server/configs/codeflow.dev.yml. Please cp codeflow.yml to codeflow.dev.yml and re-run. |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +get_ingress_hostname () { |
| 33 | + ingress_hostname=$(kubectl get services --namespace=development-checkr-codeflow -ojson |jq -r ".items[] | select(.metadata.name==\"${1}\") | .status.loadBalancer.ingress[0].ip") |
| 34 | +} |
| 35 | + |
| 36 | +wait_for_ingress_hostname () { |
| 37 | + get_ingress_hostname codeflow-api |
| 38 | + echo waiting for hostname for codeflow-api ... |
| 39 | + until [ -n "$ingress_hostname" ] && [ "$ingress_hostname" != "null" ]; do |
| 40 | + sleep 5 |
| 41 | + get_ingress_hostname codeflow-api |
| 42 | + done |
| 43 | + |
| 44 | + get_ingress_hostname codeflow-dashboard |
| 45 | + echo waiting for hostname for codeflow-dashboard ... |
| 46 | + until [ -n "$ingress_hostname" ] && [ "$ingress_hostname" != "null" ]; do |
| 47 | + sleep 5 |
| 48 | + get_ingress_hostname codeflow-dashboard |
| 49 | + done |
| 50 | + |
| 51 | +} |
| 52 | + |
| 53 | +# get_url 'servicename' 'scheme' |
| 54 | +get_url () { |
| 55 | + url=${3}://$(kubectl get services --namespace=development-checkr-codeflow -ojson |jq -r ".items[] | select(.metadata.name==\"${2}\") | [ .status.loadBalancer.ingress[0].ip, (.spec.ports[] | select(.name==\"${1}\") | .port |tostring) ] |join(\":\")") |
| 56 | +} |
| 57 | + |
| 58 | +get_dashboard_port () { |
| 59 | + port=$(kubectl get services --namespace=development-checkr-codeflow -ojson |jq ".items[] | select(.metadata.name==\"codeflow-dashboard\") | .spec.ports[] | select(.name==\"dashboard-port\") | .targetPort |tostring") |
| 60 | +} |
| 61 | + |
| 62 | +detect_ssl () { |
| 63 | + ssl_arn=$(kubectl get services --namespace=development-checkr-codeflow -ojson |jq -r ".items[] | select(.metadata.name==\"codeflow-dashboard\") |.metadata.annotations.\"service.beta.kubernetes.io\/aws-load-balancer-ssl-cert\"") |
| 64 | + if [ -n "$ssl_arn" ] && [ "$ssl_arn" != "null" ]; then |
| 65 | + echo Using TCP+SSL protocol.. |
| 66 | + protocol=s |
| 67 | + fi |
| 68 | +} |
| 69 | + |
| 70 | +set +e |
| 71 | +echo creating namespaces |
| 72 | +kubectl create namespace development-checkr-codeflow |
| 73 | + |
| 74 | +echo creating mongodb and redis |
| 75 | +kubectl create -f mongodb-service.yaml |
| 76 | +kubectl create -f mongodb-deployment.yaml |
| 77 | +kubectl create -f redis-service.yaml |
| 78 | +kubectl create -f redis-deployment.yaml |
| 79 | + |
| 80 | +echo creating codeflow services |
| 81 | +kubectl create -f codeflow-services.yaml |
| 82 | +set -e |
| 83 | + |
| 84 | +echo configuring codeflow dashboard |
| 85 | +envfile=react-configmap.yaml |
| 86 | +cat << EOF > $envfile |
| 87 | +# This ConfigMap is used to configure codeflow react service (dashboard). |
| 88 | +kind: ConfigMap |
| 89 | +apiVersion: v1 |
| 90 | +metadata: |
| 91 | + name: react-config |
| 92 | + namespace: development-checkr-codeflow |
| 93 | +data: |
| 94 | +EOF |
| 95 | + |
| 96 | +detect_ssl |
| 97 | + |
| 98 | +wait_for_ingress_hostname |
| 99 | + |
| 100 | +get_url 'api-port' 'codeflow-api' "http${protocol}" |
| 101 | +echo " REACT_APP_API_ROOT: $url" >> $envfile |
| 102 | + |
| 103 | +get_url 'webhooks-port' 'codeflow-api' "http${protocol}" |
| 104 | +echo " REACT_APP_WEBHOOKS_ROOT: $url" >> $envfile |
| 105 | + |
| 106 | +get_url 'websockets-port' 'codeflow-api' "ws${protocol}" |
| 107 | +echo " REACT_APP_WS_ROOT: $url" >> $envfile |
| 108 | + |
| 109 | +get_url 'dashboard-port' 'codeflow-dashboard' "http${protocol}" |
| 110 | +echo " REACT_APP_ROOT: $url" >> $envfile |
| 111 | + |
| 112 | +get_dashboard_port |
| 113 | +echo " REACT_APP_PORT: $port" >> $envfile |
| 114 | + |
| 115 | +kubectl apply -f $envfile --namespace=development-checkr-codeflow |
| 116 | + |
| 117 | +echo react-configmap generated and applied from file: $envfile |
| 118 | +echo Services configured successfully.. |
| 119 | +echo |
| 120 | +echo Dashboard URL: $url |
| 121 | + |
| 122 | +echo |
| 123 | +echo configuring codeflow api |
| 124 | +kubectl create configmap codeflow-config --from-file=../server/configs/codeflow.dev.yml --namespace=development-checkr-codeflow |
| 125 | + |
| 126 | +echo running codeflow database migration job |
| 127 | +kubectl create -f codeflow-migration-job.yaml |
| 128 | + |
| 129 | +echo creating codeflow deployment |
| 130 | +kubectl create -f codeflow-deployment.yaml |
0 commit comments