Cloud Foundry blue-green deployment
Allows zero-downtime deployments of applications within Cloud Foundry, with no additional setup needed.
- Install the
npm install -g cf-blue-green.
- See Notes below for non-Node installation.
cf-blue-green <appname>(instead of
cf-push) from your application directory to deploy.
This creates a copy of your already-running application, and safely switches traffic over to it. It's recommended that you try this script on a non-production application environment first, just to ensure that everything is switched over properly.
The script is distributed via NPM, but doesn't actually require Node.js beyond that. If you don't want to install Node, simply:
- Download the script.
chmod a+x cf-blue-green.
- Move the file somewhere in your PATH.
Using with Travis
Travis supports continuous deployment, which will automatically deploy your application after its tests pass on a specified branch. To use
cf-blue-green with Travis, you need to use a script provider instead of the default Cloud Foundry provider. Your Cloud Foundry settings are read from environment variables.
Set up continuous deployment with the following settings in your
sudo: true env: global: - CF_APP=[app name] - CF_API=[API endpoint] - CF_USERNAME=[user] - CF_ORGANIZATION=[organization] - CF_SPACE=[space] - secure: [CF_PASSWORD=[encrypted with Travis](http://docs.travis-ci.com/user/environment-variables/#Encrypted-Variables)] before_deploy: npm install -g cf-blue-green deploy: provider: script script: cf-blue-green-travis on: branch: [git branch you want to deploy]
cf-blue-green creates a temporary manifest from your live application, meaning that it ignores the
manifest.yml in your directory, if you have one. To deploy any changes to your manifest, use
cf push directly.
The script fails on apps with multiple domains, because the domains in the manifest are in the form of a list:
domain: - 18f.gov - digitalgov.gov
To work around this, use the env var
B_DOMAIN for the domain you'd like the B instance to use.
More information about blue-green deployment, all of which this script drew from.
Alternatives for Blue/Green Deploys in Cloud Foundry
- Autopilot: Autopilot is a CloudFoundry Go plugin that provides a subcommand,
zero-downtime-pushfor hands-off, zero-downtime application deploys.
- BlueGreenDeploy: cf-blue-green-deploy is a plugin, written in Go, for the CF command line tool that automates a few steps involved in zero-downtime deploys.