Wednesday, 3 June 2015

codeship + heroku ci+cd continuously integration+ continuously deployment, what your build is what you get


codeship + heroku is the solution of continuously integration and continuously deployment.

However, most of users just use codeship for unit test, which is not an even continuously integration test, and they use codeship as a host server, which do the compiling(building) and deployment and hosting jobs.

Actually you can do everything by heroku, but codeship can only do the compiling and running tests. However you won't do everything on heroku. Because it is a hosting server, it is nonsense to run unit test and e2e test on it. First all tests take times to run, you can't stop you app/website to run tests, even you keep running the app/website and parallelly run your tests , your tests are using CPU and other resource which will impact your app/website. Second, it doesn't make sense to have tests packages libraries in live environment. So, even heroku has the cability to handle all jobs we still want to do compiling and testing on another server. Heroku only do hosting.

Codeship can do the build and "deploy" the project into heroku. However,  it is not a real deployment. Because codeship just push all your source code into heroku and let it runs compile and deploy.

The basic rule of testing and deploying is what your compiled is what you need to deploy. Because codeship done the compile, the output archive should be pushed to heroku to host directly.

however, your output folder (/bin or /dist) is in your .gitignore file. You can't push your output folder into github, codeship also can't push their output into heroku. How to solve it?

Solution1:      Delete /dist from .gitignore file and clean /dist folder before you push to github

However, this is a ugly solution, because developers may forget clean the folder and your github will have a lot of garbage. This is not acceptable for enterprise-level projects. personal project is ok .

Solution 2:    Delete /dist from .gitignore file on codeship.

After compared with different similar solutions, I think my solution below is the best so far:

My solution has less changes (less changes means less faults and less maintenances), and users still can get benefit from all codeship deployment stuffs e.g. application health checking after deployed, and if it is failed the build failed.


Setup Commands

# By default we use the Node.js version set in your package.json or 0.10.25
# You can use nvm to install any Node.js version.
# i.e.: nvm install 0.10.25
# This is to get compass on the server
# rvm use 2.0.0-p195
rvm use ruby-2.1.2
bundle install
# nvm install 0.10.32
# nvm use 0.10.32
npm install
npm install bower -g
bower install
# Install grunt-cli for running your tests or other tasks
npm install grunt-cli
grunt build
#below code are used to remove .gitignore to push output into heroku.
ls -la dist/
rm -f .gitignore
ls -la
pwd
git config --global user.email "herokukiller@f.com"
git config --global user.name "herokukiller"
git add --all
git commit -m "remove .gitignore"
export COMMIT_ID=`git rev-parse HEAD`
export CI_COMMIT_ID=`git rev-parse HEAD`


(the last line is added 2015-11-20, due to the change of codeship: http://baiduhix.blogspot.co.uk/2015/11/codeship-build-error-follow-my-previous.html)

Configure Test Pipelines:


npm test
npm run e2e







No comments:

Post a comment