Last active
June 9, 2021 06:54
-
-
Save rwd/ca61a0b7418deef09371c99d3387d8e1 to your computer and use it in GitHub Desktop.
CF app blue/green deployment from Jenkins
This file contains hidden or 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
# 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