Continuous integration - Gitification/gitification GitHub Wiki

This page presents our Continuous Integration (CI) pipeline and technologies associated.

Scheme

This figure presents each steps of our continuous integration. CI Scheme

Technologies

This sections present each technologies used in the pipeline.

Node.js & Angular.js

Framework used on the developer side to create the server and client application.

Git

Our SVC is Git powered by GitHub.

Node module dependency management

Node offer a powerful module management for development. Two way can be used to install dependencies :

  • npm install which will parse package.json file
  • npm install [-g] name_of_module where -g indicate global install

The package.json file contains meta information, project dependencies, licenses, issue reporting url, ... Refer to the documentation for more information.

Travis-CI

Continuous integration free service linked with GitHub through WebHook. Each time code is published with git push, an event is sent to Travis-CI to start a new build test.

The build will checkout the specified version. Travis is guided by the .travis.yml file in the root directory. It contains build information, build steps and notification. The build life-cycle is the following :

  • Switch language runtime (e.g. C, Java, Node.js)
  • Clone repository
  • Run before_install commands
  • cd into repository directory and run dependency installation (npm install for Node.js)
  • Run before_script commands
  • Run test script commands (npm test for Node.js)
  • Run after_success/after_failure commands
  • Run after_script commands

Each steps must exit with a status code 0 to execute the next (except for after_success, after_failure and after_scripts). It is possible to extend build life-cycle, refer to the documentation for more information.

The following example shows a .travis.yml file using Node.js, performing a build and testing. First, the language is indicating Node.js with a 0.8 version. Travis will use nvm to get the correct version. Then, it will run npm install specific to Node.js environment. Once modules are successfully installed, the before_script is ran. It install Grunt CLI globally. The testing phase executes npm test which is defined in package.json file (in this case, we run grunt travis --verbose).

If an error occur during the build, an email is sent to the email recipient until the build is successful again.

---
language: node_js
node_js:
- 0.8
before_script:
  - npm install -g grunt-cli
notifications:
  email:
  - '[email protected]'

This snippet is from package.json file. It shows how to set the npm test command.

{
  "scripts": {
    "test": "grunt travis --verbose"
  }
}

Grunt

Grunt is a task runner based on plugins. It automates task execution using target similar to Maven of Make. The Gruntfile.js specify plugin usage, loading and parameters. It registers tasks that can be used with the Grunt CLI command (installed with npm install -g grunt-cli).

For our project, we used several tasks :

  • jshint to execute a syntax check
  • watch to reload file when change occurs
  • vows-runner to launch vows BDD tests
  • env to specify environment variables
  • karma to test the client-side application

The travis target executes, on the server code, env:dev, jshint and vows. On the client code, it runs karma.

Grunt has more than 800 plugin available, 23 officials the other being third-party. To find more plugins, refer to the plugin list on Grunt website.

SSH Deploy

To deploy our application, we chose to use Travis after_success target. A well known program called Capistrano could have been used but we chose to do it manually. First, the SSH private key to authenticate through RSA is required on Travis. The key is encoded with travis encrypt on chunk of the SSH key. Encrypted content is stored into .travis.yml in the environment section.

On the server, it will decrypt the SSH key, add it to the keychain and configure the server access. Then, it will connect on the server, checkout latest version with git and manage server instance with forever.

Refrences