#!/bin/bash

# shellcheck disable=SC1091
source control-tower/ci/tasks/lib/test-setup.sh

handleVerboseMode
setDeploymentName region

# shellcheck disable=SC2034
region=eu-west-3
trapCustomCleanup

cp "$BINARY_PATH" ./cup
chmod +x ./cup

echo "DEPLOY WITH AUTOGENERATED CERT, NO DOMAIN, CUSTOM REGION, m5 WORKERS"
./cup deploy --worker-type m5 --region eu-west-3 --zone eu-west-3b "$deployment"

sleep 60

config=$(./cup info --region eu-west-3 --json "$deployment")
# shellcheck disable=SC2034
domain=$(echo "$config" | jq -r '.config.domain')
# shellcheck disable=SC2034
username=$(echo "$config" | jq -r '.config.concourse_username')
# shellcheck disable=SC2034
password=$(echo "$config" | jq -r '.config.concourse_password')
echo "$config" | jq -r '.config.concourse_ca_cert' > generated-ca-cert.pem

# shellcheck disable=SC2034
cert="generated-ca-cert.pem"
# shellcheck disable=SC2034
manifest="$(dirname "$0")/hello.yml"
# shellcheck disable=SC2034
job="hello"

# Download the right version of fly from Concourse UI
updateFly "${domain}"

assertPipelineIsSettableAndRunnable

echo "DEPLOY WITH AUTOGENERATED CERT, NO DOMAIN, CUSTOM REGION, m5a WORKERS"
./cup deploy --worker-type m5a --region eu-west-3 --zone eu-west-3b "$deployment"

sleep 30

assertPipelineIsSettableAndRunnable
