#!/bin/bash
set -euo pipefail
# When changing this script, remember to modify the corresponding github action
vendor=${1}
env=${2}
region=${3}
logical_region=${4}
cluster=${5}
json_file_path=${6}
args=$(jq -r '.' "${json_file_path}")

ROOT=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
deploy_dir="${ROOT}/envs/${env}"
deploy_file="${deploy_dir}/regional-${vendor}-${logical_region}.yaml"
variant_dir="${ROOT}/variants"
mkdir -p ${deploy_dir}

image_registry=$(echo ${args} | jq -r '.imageRegistry')

if [ -e ${deploy_file} ]; then
  echo "New region deploy file already exist, skip it"
else
  echo "Prepare manifest files"
  cp "${variant_dir}/values_tmpl.yaml" "${deploy_file}"
  sed -i "s|TMPL_IMAGE_REGISTRY|${image_registry}|g" ${deploy_file}
fi

