#!/usr/bin/env bash

set -e

if [ $# -ne 2 ]; then
    echo "Usage: ./helpers/deploy_tile_gen.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-tile-gen/chart
source geosphere-tile-gen/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-tile-gen${deploy_suffix}.yaml .
# namespace names are the same as domain names
helm upgrade -v 2 --install --kubeconfig $kubeconfig --namespace $ns -f values-tile-gen${deploy_suffix}.yaml geosphere-tile-gen${deploy_suffix} geosphere-tile-gen/
