Node’s a great language for web-applications that deal with a lot of I/O (like API-driven stuff) and earlier in the year I wrote some glue to Mocha and Atlassian Bamboo to let the latter collect test reports from the former. There are hints to Chef, Vagrant and CD goodness inside, too, so you can actually set up the same platform I’m presenting on to follow along with from home.
5. The Basics…
We
have a project, with tests (regression, unit, behavioral
– up to you)
Written in Node.js, tested with Mocha
We’d love to get Bamboo CI working
Now
what?
6. Before we get ahead of ourselves...
Continuous Integration is a practice of
constantly merging source code, and
building and testing the result as often as
possible (and useful)
Originally part of XP (Extreme
Programming) principles
Lately has extended to Continuous
Deployment – the practice of constantly
deploying the latest builds to a customer
/ production environment
Atlassian Bamboo was originally designed for CI, and recently extended to include CD features
8. Bring up the local environment
git clone --recursive https://github.com/issacg/mochademo.git
EDIT mocha-demo/bamboo/attributes/oracle.rb (change
FALSE to TRUE to accept Oracle’s license)
cd mocha-demo
vagrant up (This will take a while)
cd bamboo*
vagrant up* (This will take a while)
How cool was that?
*The final command will no longer be necessary in an upcoming release of vagrant-berkshelf
9. Node.js and Mocha Support for Bamboo
The
Node.js plugin is included in the VirtualBox image
Bamboo Node.js plugin via Atlassian Marketplace / UPM
You’ll also need the Mocha reporter via npm package
mocha-bamboo-reporter
Instructions at https://github.com/issacg/mochabamboo
11. Testing from node
$ git checkout example3
$ npm test
> mocha-bamboo-demo@0.9.1 test /opt/demo/node
> node node_modules/mocha/bin/mocha
.
1 passing (97 ms)
12. Don’t forget to run it!
$ node index.js
http://localhost:8080/reverse/hello
elloh
It’s ALIVE!!!
13. The Test
describe('GET /reverse', function() {
it('should reverse the string', function(done) {
request(app). get('/reverse/hello').
expect('Content-Type', 'text/plain').
expect(200, 'olleh', done);
});
});
14. What if it fails?
$ cd /opt/demo/node
$ git checkout example2
$ npm test
> mocha-bamboo-demo@0.9.1 test /opt/demo/node
> node node_modules/mocha/bin/mocha
0 passing (28 ms)
1 failing
1) Reverser GET /reverse should reverse the string:
Uncaught TypeError: Object #<IncomingMessage> has no method 'get‘
…
npm ERR! weird error 1
npm ERR! not ok code 0
15. Bring up the local Bamboo server
http://localhost:8085/
Get
a free evaluation license (https://my.atlassian.com/license/evaluation)
Use custom setup
Use external (MySQL 5.x) database
User bamboo, password bamboo
Create a new bamboo home
Set your initial user
16. Setting up Bamboo
Create
a new Plan
Source is Git (git@github.com:issacg/mocha-demo.git)
Add tasks (all in “node” subdirectory)
Add NPM task “install”
Add NPM task “run-script bamboo”
Add Mocha tests collector task as Final Task
17. Testing From
Bamboo
Default (build from
“master”) should pass –
green
Run Customized to
run specific revision
“example1” will have
no failed tests – syntax
error in logs
“example2” will have
one failed test
“example3” should
pass all tests
18. Continuous Integration
Use
triggers in Bamboo to
automate build
Polling Git repository
Push to Bamboo via Webhook
Timed (Daily build)
Use
(successful) builds (tests) to
trigger deployments…
20. Deployment
Deployment
options added since Bamboo 5
Intuitive and informative UI + JIRA integration
Build results marked as a “release” and “release” marked as
deployed in one or more environments
Also possible to mark a release (one mark) as Approved or
Rejected
Integrated with permissions system – give your developers control
(or at least make them think they have it )
21. Deploying via SCC tags
Extremely
popular deployment
pattern
… but Bamboo can’t mark a
“tag” as release, only an
Artifact…
… and your Git repository needs
to be firewall-accessible
22. Deploying via artifact
Especially
useful in compiled languages, or including runtime prerequisites (like npm packages)
Artifact Push – Supported by Bamboo, including firewall
transversal, but requires the target machine to have a
Remote Agent license
Artifact Pull – Supported by popular deployment tools
(Chef, Puppet, Capistrano) but requires Firewall access and
file access (FTP, HTTP) to Bamboo’s artifact store
External artifact store – No native Bamboo support. Vote for
it at https://jira.atlassian.com/browse/BAM-11876
29. In the meantime…
Hack
around it
I recommend either external artifact store by uploading
artifacts at the end of a build
OR
Tagging SCC at the end of a build and using the tag in
deployment scripts
30. To Summarize
Part One
Part Two
We learned about Continuous Integration and Continuous
Deployment principles
We saw how to set up a local environment to try all the examples
here (and peek at the source code where applicable)
We were able to run the Mocha unit tests from the command line
We integrated Bamboo and a Git repository, and had Bamboo run
the unit tests and show us the results
Part Three
We touched on Deployment with Bamboo and saw how to do it
today, and how it will (hopefully) be streamlined in the future
32. That’s All, Folks!
Issac Goldstand
issac@itsgoodconsulting.com
Link To Slides
http://www.itsgoodconsulting.com/blog/issac-presenting-continuous-integration-with-node-js-and-atlassian-bamboo/