#!/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 img_push.sh 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 image push from ${marvel2_dir}"
for dirname in $subdirs
do
    # always start from the marvel2 dir
    cd $marvel2_dir
    cd $dirname
    echo
    echo "===== Pushing image in $(pwd)"
    if [ -f ./img_push.sh ]; then
        push_script="./img_push.sh"
    else
        push_script="${scripts}/img_push.sh"
    done

    ${push_script}
    if [ $? -ne 0 ]
    then
        echo
        echo "===== ERROR in Pushing image in $(pwd)"
        exit 1
    fi
done

echo
echo "===== SUCCESS in Pushing all images"
exit 0
