Skip to content

Instantly share code, notes, and snippets.

@rwd
Last active June 9, 2021 06:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwd/ca61a0b7418deef09371c99d3387d8e1 to your computer and use it in GitHub Desktop.
Save rwd/ca61a0b7418deef09371c99d3387d8e1 to your computer and use it in GitHub Desktop.
CF app blue/green deployment from Jenkins
# Given an app with mirrors web-blue and web-green in the CF test space with hostname www.example.org...
# Find which mirror is already active, which to switch to
export OLD_MIRROR=$(cf routes | sed -nr 's/^(test\s+)?www\s+example\.org\s+web-(blue|green).*$/\2/p')
if [ "$OLD_MIRROR" = "blue" ]; then
export NEW_MIRROR="green"
elif [ "$OLD_MIRROR" = "green" ]; then
export NEW_MIRROR="blue"
else
export OLD_MIRROR="green"
export NEW_MIRROR="blue"
fi
## Push to Cloud Foundry
cf push web-${NEW_MIRROR} --no-route
## Switch route targets
cf map-route web-${NEW_MIRROR} example.org -n www
cf unmap-route web-${OLD_MIRROR} example.org -n www
## Stop old mirror
cf stop web-${OLD_MIRROR}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment