2929CURRENT_COMMIT_HASH=$( cd " ${autoscaler_dir} " ; git log -1 --pretty=format:" %H" )
3030bosh_release_version=${RELEASE_VERSION:- ${CURRENT_COMMIT_HASH} -${deployment_name} }
3131
32- pushd " ${bbl_state_path} " > /dev/null
33- eval " $( bbl print-env) "
34- popd > /dev/null
32+ bosh_login " ${BBL_STATE_PATH} "
3533
3634function setup_autoscaler_uaac() {
37- local uaac_authorities=" cloud_controller.read,cloud_controller.admin,uaa.resource,routing.routes.write,routing.routes.read,routing.router_groups.read"
38- local autoscaler_secret=" autoscaler_client_secret"
39- local uaa_client_secret=$( credhub get -n /bosh-autoscaler/cf/uaa_admin_client_secret --quiet)
40-
41- uaac target " https://uaa.${system_domain} " --skip-ssl-validation > /dev/null
42- uaac token client get admin -s " ${uaa_client_secret} " > /dev/null
43-
44- if uaac client get autoscaler_client_id > /dev/null; then
45- step " updating autoscaler uaac client"
46- uaac client update " autoscaler_client_id" --authorities " $uaac_authorities " > /dev/null
47- else
48- step " creating autoscaler uaac client"
49- uaac client add " autoscaler_client_id" \
50- --authorized_grant_types " client_credentials" \
51- --authorities " $uaac_authorities " \
52- --secret " $autoscaler_secret " > /dev/null
53- fi
35+ local uaac_authorities=" cloud_controller.read,cloud_controller.admin,uaa.resource,routing.routes.write,routing.routes.read,routing.router_groups.read"
36+ local autoscaler_secret=" autoscaler_client_secret"
37+ local uaa_client_secret=$( credhub get -n /bosh-autoscaler/cf/uaa_admin_client_secret --quiet)
38+
39+ uaac target " https://uaa.${system_domain} " --skip-ssl-validation > /dev/null
40+ uaac token client get admin -s " ${uaa_client_secret} " > /dev/null
41+
42+ if uaac client get autoscaler_client_id > /dev/null; then
43+ step " updating autoscaler uaac client"
44+ uaac client update " autoscaler_client_id" --authorities " $uaac_authorities " > /dev/null
45+ else
46+ step " creating autoscaler uaac client"
47+ uaac client add " autoscaler_client_id" \
48+ --authorized_grant_types " client_credentials" \
49+ --authorities " $uaac_authorities " \
50+ --secret " $autoscaler_secret " > /dev/null
51+ fi
5452}
5553
5654function get_postgres_external_port() {
57- [[ -z " ${PR_NUMBER} " ]] && echo " 5432" || echo " ${PR_NUMBER} "
55+ [[ -z " ${PR_NUMBER} " ]] && echo " 5432" || echo " ${PR_NUMBER} "
5856}
5957
6058function create_manifest() {
61- local tmp_dir
62- local perform_as_gh_action=" ${GITHUB_ACTIONS:- false} "
59+ local tmp_dir
60+ local perform_as_gh_action=" ${GITHUB_ACTIONS:- false} "
6361
64- if " ${perform_as_gh_action} " ! = ' false' ; then
65- tmp_dir=" ${RUNNER_TEMP} "
66- else
67- tmp_dir=" $( pwd) /dev_releases"
68- mkdir -p " ${tmp_dir} "
69- fi
62+ if " ${perform_as_gh_action} " ! = ' false' ; then
63+ tmp_dir=" ${RUNNER_TEMP} "
64+ else
65+ tmp_dir=" $( pwd) /dev_releases"
66+ mkdir -p " ${tmp_dir} "
67+ fi
7068
71- tmp_manifest_file=" $( mktemp " ${tmp_dir} /${deployment_name} .bosh-manifest.yaml.XXX" ) "
72- credhub interpolate -f " ${autoscaler_dir} /ci/autoscaler/scripts/autoscaler-secrets.yml.tpl" > /tmp/autoscaler-secrets.yml
69+ tmp_manifest_file=" $( mktemp " ${tmp_dir} /${deployment_name} .bosh-manifest.yaml.XXX" ) "
70+ credhub interpolate -f " ${autoscaler_dir} /ci/autoscaler/scripts/autoscaler-secrets.yml.tpl" > /tmp/autoscaler-secrets.yml
7371
7472 add_variable " deployment_name" " ${deployment_name} "
7573 add_variable " system_domain" " ${system_domain} "
@@ -82,14 +80,14 @@ function create_manifest() {
8280 bosh_deploy_vars=" "
8381
8482 # add deployment name
85- bosh -n -d " ${deployment_name} " interpolate " ${deployment_manifest} " ${OPS_FILES_TO_USE} \
86- ${bosh_deploy_opts} ${BOSH_DEPLOY_VARS} \
87- --vars-file=/tmp/autoscaler-secrets.yml -v skip_ssl_validation=true > " ${tmp_manifest_file} "
88-
89- if [[ -z " ${debug} " || " ${debug} " = " false" ]]; then
90- # shellcheck disable=SC2064
91- trap " rm ${tmp_manifest_file} " EXIT
92- fi
83+ bosh -n -d " ${deployment_name} " interpolate " ${deployment_manifest} " ${OPS_FILES_TO_USE} \
84+ ${bosh_deploy_opts} ${BOSH_DEPLOY_VARS} \
85+ --vars-file=/tmp/autoscaler-secrets.yml -v skip_ssl_validation=true > " ${tmp_manifest_file} "
86+
87+ if [[ -z " ${debug} " || " ${debug} " = " false" ]]; then
88+ # shellcheck disable=SC2064
89+ trap " rm ${tmp_manifest_file} " EXIT
90+ fi
9391}
9492
9593add_variable () {
@@ -99,62 +97,62 @@ add_variable() {
9997}
10098
10199function check_ops_files() {
102- step " Using Ops files: '${ops_files} '"
103-
104- OPS_FILES_TO_USE=" "
105- for OPS_FILE in ${ops_files} ; do
106- if [[ -f " ${OPS_FILE} " ]]; then
107- OPS_FILES_TO_USE=" ${OPS_FILES_TO_USE} -o ${OPS_FILE} "
108- else
109- echo " ERROR: could not find ops file ${OPS_FILE} in ${PWD} "
110- exit 1
111- fi
112- done
100+ step " Using Ops files: '${ops_files} '"
101+
102+ OPS_FILES_TO_USE=" "
103+ for OPS_FILE in ${ops_files} ; do
104+ if [[ -f " ${OPS_FILE} " ]]; then
105+ OPS_FILES_TO_USE=" ${OPS_FILES_TO_USE} -o ${OPS_FILE} "
106+ else
107+ echo " ERROR: could not find ops file ${OPS_FILE} in ${PWD} "
108+ exit 1
109+ fi
110+ done
113111}
114112
115113function deploy() {
116- create_manifest
117- log " creating Bosh deployment '${deployment_name} ' with version '${bosh_release_version} ' in system domain '${system_domain} '"
118- debug " tmp_manifest_file=${tmp_manifest_file} "
119- step " Using Ops files: '${OPS_FILES_TO_USE} '"
120- step " Deploy options: '${bosh_deploy_opts} '"
121- bosh -n -d " ${deployment_name} " deploy " ${tmp_manifest_file} "
122- postgres_ip=" $( bosh curl " /deployments/${deployment_name} /vms" | jq ' . | .[] | select(.job == "postgres") | .ips[0]' -r) "
123- credhub set -n " /bosh-autoscaler/${deployment_name} /postgres_ip" -t value -v " ${postgres_ip} "
114+ create_manifest
115+ log " creating Bosh deployment '${deployment_name} ' with version '${bosh_release_version} ' in system domain '${system_domain} '"
116+ debug " tmp_manifest_file=${tmp_manifest_file} "
117+ step " Using Ops files: '${OPS_FILES_TO_USE} '"
118+ step " Deploy options: '${bosh_deploy_opts} '"
119+ bosh -n -d " ${deployment_name} " deploy " ${tmp_manifest_file} "
120+ postgres_ip=" $( bosh curl " /deployments/${deployment_name} /vms" | jq ' . | .[] | select(.job == "postgres") | .ips[0]' -r) "
121+ credhub set -n " /bosh-autoscaler/${deployment_name} /postgres_ip" -t value -v " ${postgres_ip} "
124122}
125123
126124function find_or_upload_stemcell() {
127- local stemcell_os stemcell_version stemcell_name
128- stemcell_os=$( yq eval ' .stemcells[] | select(.alias == "default").os' " ${deployment_manifest} " )
129- stemcell_version=$( yq eval ' .stemcells[] | select(.alias == "default").version' " ${deployment_manifest} " )
130- stemcell_name=" bosh-google-kvm-${stemcell_os} -go_agent"
131-
132- if ! bosh stemcells | grep " ${stemcell_name} " > /dev/null; then
133- local URL=" https://bosh.io/d/stemcells/${stemcell_name} "
134- [[ " ${stemcell_version} " != " latest" ]] && URL=" ${URL} ?v=${stemcell_version} "
135- wget " ${URL} " -O stemcell.tgz
136- bosh -n upload-stemcell $bosh_upload_stemcell_opts stemcell.tgz
137- fi
125+ local stemcell_os stemcell_version stemcell_name
126+ stemcell_os=$( yq eval ' .stemcells[] | select(.alias == "default").os' " ${deployment_manifest} " )
127+ stemcell_version=$( yq eval ' .stemcells[] | select(.alias == "default").version' " ${deployment_manifest} " )
128+ stemcell_name=" bosh-google-kvm-${stemcell_os} -go_agent"
129+
130+ if ! bosh stemcells | grep " ${stemcell_name} " > /dev/null; then
131+ local URL=" https://bosh.io/d/stemcells/${stemcell_name} "
132+ [[ " ${stemcell_version} " != " latest" ]] && URL=" ${URL} ?v=${stemcell_version} "
133+ wget " ${URL} " -O stemcell.tgz
134+ bosh -n upload-stemcell $bosh_upload_stemcell_opts stemcell.tgz
135+ fi
138136}
139137
140138function find_or_upload_release() {
141- if ! bosh releases | grep -E " ${bosh_release_version} [*]*\s" > /dev/null; then
142- local release_desc_file=" dev_releases/app-autoscaler/app-autoscaler-${bosh_release_version} .yml"
143- if [[ ! -f " ${release_desc_file} " ]]; then
144- echo " Creating Release with bosh version ${bosh_release_version} "
145- bosh create-release --force --version=" ${bosh_release_version} "
146- else
147- # shellcheck disable=SC2006
148- echo -e " Release with bosh-version ${bosh_release_version} already locally present. Reusing it." \
149- " \n\tIf this does not work, please consider executing ` bosh reset-release` ."
150- fi
151-
152- echo " Uploading Release"
153- bosh upload-release ${bosh_upload_release_opts} " ${release_desc_file} "
154- else
155- echo " the app-autoscaler release is already uploaded with the commit ${bosh_release_version} "
156- echo " Attempting redeploy..."
157- fi
139+ if ! bosh releases | grep -E " ${bosh_release_version} [*]*\s" > /dev/null; then
140+ local release_desc_file=" dev_releases/app-autoscaler/app-autoscaler-${bosh_release_version} .yml"
141+ if [[ ! -f " ${release_desc_file} " ]]; then
142+ echo " Creating Release with bosh version ${bosh_release_version} "
143+ bosh create-release --force --version=" ${bosh_release_version} "
144+ else
145+ # shellcheck disable=SC2006
146+ echo -e " Release with bosh-version ${bosh_release_version} already locally present. Reusing it." \
147+ " \n\tIf this does not work, please consider executing ` bosh reset-release` ."
148+ fi
149+
150+ echo " Uploading Release"
151+ bosh upload-release ${bosh_upload_release_opts} " ${release_desc_file} "
152+ else
153+ echo " the app-autoscaler release is already uploaded with the commit ${bosh_release_version} "
154+ echo " Attempting redeploy..."
155+ fi
158156}
159157
160158function pre_deploy() {
@@ -189,4 +187,3 @@ find_or_upload_stemcell
189187find_or_upload_release
190188deploy
191189popd > /dev/null
192-
0 commit comments