Wercker is a continuous integration service that lets you use private bitbucket repos for no cost. I like the way they do things and see a lot of potential with the service.
A few weeks ago I wrote a post about using Yeoman, Travis-Ci, and Heroku. I have since used that method for a few more projects and it worked well.
Last week I started working on a small team project that we did not want to be completely open source, but we still wanted to deploy upon successful build. Using Travis-Ci with private GitHub repos is too expensive for us right now.
After some quick research we settled on using bitbucket for source code management and wercker for continuous integration. At the time of this post both were free and private for our purposes.
Wercker uses the concepts of boxes, which are preconfigured machines, and steps to perform its ci duties. The solution I am going to describe is not optimized to use prebuilt boxes and steps, but that is something I plan on doing in the future.
We want wercker to do the following on every commit to bitbucket:
The fist thing to configure is your wercker.yml file.
The default wercker/nodejs box does not have bower and grunt installed, so be sure to include them.
- script: name: install bower grunt run bower code: |- npm install bower grunt-cli node_modules/bower/bin/bower install
This is a prebuilt wercker step that lets us deploy to heroku without a bunch of warnings.
- add-to-known_hosts: hostname: heroku.com
It is a best practice to execute long scripts in a separate file to keep the yml file clean and more modular. We will be executing the heroku.sh script.
Note that we are only executing on commits to the master branch. This lets the team develop on feature branches on the main repo.
- script: name: deploy code: |- chmod u+x heroku.sh if [[ $WERCKER_GIT_BRANCH == "master" ]]; then ./heroku.sh; fi
box: wercker/nodejs services: - wercker/mongodb # Build definition build: # The steps that will be executed on build steps: - npm-install - script: name: run bower code: node_modules/bower/bin/bower install - npm-test - add-to-known_hosts: hostname: heroku.com - script: name: deploy code: |- chmod u+x testScript.sh if [[ $WERCKER_GIT_BRANCH == "master" ]]; then ./testScript.sh; fi
grunt build
This code builds the project in the dist/ folder
cd dist
git config --global user.email "[your email address]" git config --global user.name "[your name]"
sudo gem install heroku
Here we clear the existing ssh keys from heroku and then add a new one.
heroku keys:clear yes | heroku keys:add
Here we setup the git repo and then commit to heroku
git init git add . git commit -m 'deploy' git remote add heroku [your heroku git repo] git push heroku master -f
heroku keys:clear
grunt build cd dist git config --global user.email "caseyg1204@gmail.com" git config --global user.name "Casey" sudo gem install heroku heroku keys:clear yes | heroku keys:add git init git add . git commit -m 'deploy' git remote add heroku git@heroku.com:yo-wercker.git git push heroku master -f heroku keys:clear echo "...done."
Originally published at www.parsed.io.