Skip to content

Instantly share code, notes, and snippets.

@willis7
Created August 3, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willis7/08a162776f2131c1f998b61f30eaf968 to your computer and use it in GitHub Desktop.
Save willis7/08a162776f2131c1f998b61f30eaf968 to your computer and use it in GitHub Desktop.
Blue Green Deployment with Cloud Foundry
#!/bin/bash
set -euo pipefail
cf login -a "$CF_API" -u "$CF_USER" -p "$CF_PASSWORD" -o "$CF_ORG" -s "$CF_SPACE"
APP_NAME_TMP="${APP_NAME}-venerable"
# Deploy a new application if doesn't exist and do blue-green otherwise
if [[ $(cf app "$APP_NAME" --guid 2>&1 1>/dev/null) == "App $APP_NAME not found" ]]; then
cf push
else
cf rename "$APP_NAME" "$APP_NAME_TMP"
if cf push; then
cf delete -f "$APP_NAME_TMP"
else
cf delete -f "$APP_NAME"
cf rename "$APP_NAME_TMP" "$APP_NAME"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment