#!/usr/bin/env bash

set -e

if [ $# -ne 2 ]; then
    echo "Usage: ./helpers/deploy_geo2grid.sh <values_base_dir> <deploy_suffix>"
    exit 1
fi

# ci_geosphere-test
values_base="$1"
# Example: -g16-radf
deploy_suffix="$2"

ns=$(./helpers/get_namespace.sh)
cd geosphere-geo2grid/chart
source cspp-geo-geo2grid/cibuild.env
# copy secret kubeconfig to the mounted (pwd) directory
cp $kubekorner_k3s_config .
kubeconfig=$(basename $kubekorner_k3s_config)
echo "Deploying version $docker_tag to cluster namespace $ns"
# copy extra values files to the local directory (where helm has access via docker mount)
cp ../../${values_base}/values-geo2grid${deploy_suffix}.yaml .
# namespace names are the same as domain names
helm upgrade -v 2 --install --kubeconfig $kubeconfig --namespace $ns -f values-geo2grid${deploy_suffix}.yaml cspp-geo-geo2grid${deploy_suffix} cspp-geo-geo2grid/
