#!/usr/bin/env bash usage() { printf "$0 usage: \n -i: interactive\n -p : Postgres version\n -s : enable SSL\n -r : API replicas\n" $0 exit 0 } interactive=false postgres_version= enable_ssl= api_replicas= fluentd=false seed_db=false uninstall=false while getopts "idufhp:s:r:" arg; do case $arg in i) interactive=true ;; p) postgres_version=${OPTARG} ;; s) enable_ssl=${OPTARG} ;; r) api_replicas=${OPTARG} ;; f) fluentd=true ;; d) seed_db=true ;; u) uninstall=true ;; *) usage ;; esac done if [ "$#" -gt 1 ] && [ "$1" = "-i" ]; then interactive=false fi minikube status | grep -q "Running" && START_MINIKUBE=false || START_MINIKUBE=true $START_MINIKUBE && minikube start $START_MINIKUBE && eval $(minikube docker-env) if [ "$interactive" == true ]; then read -p "Enter the Postgres version (press Enter for default 13.3): " postgres_version read -p "Do you want to enable SSL? [y/N]: " enable_ssl read -p "Enter the number of replicas for the API: " api_replicas read -p "Do you want to enable fluentd? [y/N]: " fluentd read -p "Do you want to seed the database with some data? [y/N]: " seed_db fi if [ -n "$postgres_version" ]; then ./build.sh -v "${postgres_version}" sed -ni "/repository: db/ { p; n; /tag:.*/ { s/tag:.*/tag: ${postgres_version}/; p; d; } } p;" helm/values.yaml else ./build.sh fi if [ -n "$enable_ssl" ]; then if [ "$enable_ssl" == "y" ] || [ "$enable_ssl" == "Y" ]; then sed -i "s/ssl: .*/ssl: true/" helm/values.yaml else sed -i "s/ssl: .*/ssl: false/" helm/values.yaml fi fi if [ -n "$api_replicas" ]; then sed -ni "/port: \*apiPort/ { p; n; /replicas:.*/ { s/replicas:.*/replicas: ${api_replicas}/; p; d; } } p;" helm/values.yaml fi $START_MINIKUBE && minikube addons enable ingress helm dependency list helm | grep -q "missing" && helm dependency build helm if [ "$uninstall" == true ]; then helm uninstall exam -n exam exit 0 fi VALUES=("-f" "helm/values.yaml") if [ "$fluentd" == true ] || [ "$fluentd" == "y" ] || [ "$fluentd" == "Y" ]; then VALUES+=("-f" "helm/fluentd.yaml") [ -f 'helm/secrets.yaml' ] && VALUES+=("-f" "helm/secrets.yaml") helm status exam -n exam > /dev/null 2>&1 && helm upgrade exam ./helm -n exam ${VALUES[@]} || helm install exam ./helm -n exam ${VALUES[@]} else [ -f 'helm/secrets.yaml' ] && VALUES+=("-f" "helm/secrets.yaml") helm status exam -n exam > /dev/null 2>&1 && helm upgrade exam ./helm -n exam ${VALUES[@]} || helm install exam ./helm -n exam ${VALUES[@]} fi if [ -n "$seed_db" ]; then if [ "$seed_db" == true ] || [ "$seed_db" == "y" ] || [ "$seed_db" == "Y" ]; then API_POD=$(kubectl get pods -n exam --selector=app=api --template '{{range .items}}{{.metadata.name}}{{break}}{{end}}') if [ -z "$API_POD" ]; then echo "No API pod found. Exiting..." exit 1 fi echo "Waiting for the API pod to start. Please be patient..." kubectl -n exam wait pod/${API_POD} --for=condition=Ready --timeout=-1s kubectl -n exam exec -it ${API_POD} -- python manage.py seed_db fi fi