Created
February 3, 2016 20:57
-
-
Save mdcarlson/21b00cb04d9b95254c0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
set -e -x | |
<% | |
def grab_app_domain_name | |
app_domains_str = properties.app_domains.to_s | |
array_start = ( app_domains_str =~ /^\[/ ) | |
if (array_start == 0) | |
app_domain_entry = app_domains_str.gsub(/^\[/, '').gsub(/\]/,'').gsub(/,.*/, '') | |
else | |
app_domain_entry = app_domains_str | |
end | |
app_domain_entry | |
end | |
app_domain = grab_app_domain_name | |
%> | |
export SCHEME=https | |
export PATH="/var/vcap/packages/cf_cli/bin:$PATH" | |
export ADMIN_USER=<%= properties.cf.admin_user %> | |
export ADMIN_PASSWORD=<%= properties.cf.admin_password %> | |
export DOMAIN=<%= properties.domain %> | |
export API_ENDPOINT=$SCHEME://api.$DOMAIN | |
export APP_DOMAIN=<%="#{app_domain}"%> | |
export APP_NAME=<%= properties.pact_broker_docker_app.app_name %> | |
export APP_VERSION=<%= properties.pact_broker_docker_app.app_version %> | |
export APP_URI=<%= properties.pact_broker_docker_app.app_uri %> | |
export PERSISTENCE_STORE_TYPE=<%= properties.pact_broker_docker_app.persistence_store_type %> | |
export ORG=${APP_NAME}-org | |
export SPACE=${APP_NAME}-space | |
export DB_NAME=${APP_NAME}-${APP_VERSION}-mysql | |
function authenticate_and_target() { | |
cf api $API_ENDPOINT <% if properties.ssl.skip_cert_verify %>--skip-ssl-validation<% end %> | |
cf auth $ADMIN_USER $ADMIN_PASSWORD | |
cf target -o $ORG -s $SPACE | |
} | |
function unbind_and_unprovision_db() { | |
db_plan=`cf marketplace | grep p-mysql | awk '{ print $2 }' | sed 's/,//g'` | |
if [ "$db_plan" != "" ]; then | |
cf unbind-service ${APP_NAME}-${APP_VERSION} $DB_NAME | |
cf delete-service -f $DB_NAME | |
fi | |
} | |
function unbind_services() { | |
for service in `cf services | grep ${APP_NAME}-${APP_VERSION} | grep "." | awk '{ print $1 }' ` | |
if [ "$service" != "" ]; then | |
cf unbind-service ${APP_NAME}-${APP_VERSION} $service | |
cf delete-service -f $service | |
fi | |
} | |
cf -v | |
authenticate_and_target | |
unbind_services | |
cf delete -f ${APP_NAME}-${APP_VERSION} | |
cf delete-space -f $SPACE | |
cf delete-org -f $ORG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment