Cloud Foundry / Pivotal and Bitbucket pipelines
Bitbucket pipelines is a really cool feature for continuous delivery. I’ve been using it extensively in our team with AWS and Heroku (for my personal projects). In new setup, we are going with Cloud Foundry/Pivotal instead of Heroku due to cost reason, so I’ve spent sometime to getting the pipelines working with our new setup as well.
I shared the information below, hopefully it could save you time if you are having similar setup.
After setting up your app on bitbucket and push the initial code there, you could go to Pipelines tab and enable that feature.
Once enabling, bitbucket will create a bitbucket-pipelines.yml file in your project.
You could edit and reuse our YML file and it should work. Basically, our pipelines just install Cloud Foundry CLI, login to the service and using Blue-Green deployment to deploy the app with minimum downtime. Initially we are using simple “cf push” command but it will bring down our service for few minutes every time we deploy which won’t work very well in production, so we moved to Blue-Green deployment. (You could read more about Blue-Green deployment here https://docs.cloudfoundry.org/devguide/deploy-apps/blue-green.html )
# You can specify a custom docker image from Docker Hub as your build environment.
script: # Modify the commands below to build your repository.
- npm install
#- npm test : enable this if you have working tests in pipeline
- apt-get update
- wget -O /tmp/cf-cli.tgz “https://cli.run.pivotal.io/stable?release=linux64-binary&version=6.27.0" #current version of cli is 6.27.0
- ls -alF /tmp/
- mkdir -p /usr/local/bin
- tar -xzf /tmp/cf-cli.tgz -C /usr/local/bin
- cf — version
- cf login -a https://api.run.pivotal.io -u $PIVOTAL_USERNAME -p $PIVOTAL_PASSWORD
- cf add-plugin-repo CF-Community https://plugins.cloudfoundry.org
- cf install-plugin blue-green-deploy -r CF-Community -f
- ls -alF
- cf blue-green-deploy srve-api -f manifest.yml