#!/usr/bin/env bash

scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd ${scripts}/..
marvel2_dir="$(pwd)"

# names of the sub directories from where `k8s_deploy.sh dev` should be run
subdirs="kong kong/kafka/databricks-scheduler-consumer kong/kafka/echo-sim-results-consumer kong/kafka/run-summaries-consumer jobz frontend"

echo
echo "===== Starting all deploy k8s dev from ${marvel2_dir}"
for dirname in $subdirs
do
    # always start from the marvel2 dir
    cd $marvel2_dir
    cd $dirname
    echo
    echo "===== Deploying to k8s dev in $(pwd)"

    if [ -f ./k8s_deploy.sh ]; then
        ./k8s_deploy.sh dev
    else
        ${scripts}/k8s_deploy.sh dev
    done

    if [ $? -ne 0 ]
    then
        echo
        echo "===== ERROR in Deploying to k8s dev in $(pwd)"
        exit 1
    fi
done

echo
echo "===== SUCCESS in Deploying all services to k8s dev"
exit 0
