Nodejitsu

Save time managing and deploying your node.js app. Code faster with jitsu and npm

Continuous Deployment with Github and Nodejitsu

About the author

Name
Location
Worldwide
nodejitsu nodejitsu

Today, we would like to announce that from now on you can deploy your open-source Github repositories directly to Nodejitsu.

How does this work? By implementing a Github service for Nodejitsu, you will now be able to deploy your open-source application anytime you push a commit to Github.

But that's not good enough Continuous Deployment you say? We have also added an integration with TravisCI so that you can also deploy your open-source application only after a successful test run.

Open-source is a core value at Nodejitsu. We all maintain several open-source modules that make the node.js community a better place, and promote high profile projects like flatiron and http-proxy so we want to make sure that Open Source developers have the best experience available for deploying their application.

Keep reading to learn all the details about getting setup with Continuous Deployment on Nodejitsu!

Getting started

To setup continuous deployment with Github and Nodejitsu, first, access the Admin section on your Open Source node.js Github repository. Click Service Hooks and then Nodejitsu. You will be presented with a form with four fields:

The Github Interface for Nodejitsu

Select Active and hit Update Settings. From now on every-time you commit to github (in the designated deployment branch) we will deploy that application for you. That simple.

But wait, I have API keys I can't commit to Github as open source?!

Don't worry, you can use jitsu set env to set environment variables that you can access with process.env. Check our handbook for more information. Environment variables set this way persist across deployments and are also available in our webops application.

If this is your first time getting this setup, then you probably want to set those environment variables first in a new nodejitsu application before deploying from Github. Otherwise, your first deployment will fail because the environment variables are not yet set.

  jitsu apps create your-app
  jitsu env set <key> <value>

Monitoring deployments

There's several ways to access the deployment status in the Nodejitsu Webhook API, and you can find the complete documentation at webhooks.nodejitsu.com.

The most fun way to monitor your deployment is with the realtime status changes feed.

  #
  # if your username is foo and password is bar this would be 
  # https://foo:bar@webhooks.nodejitsu.com/1/status/foo/changes
  #
  curl https://username:password@webhooks.nodejitsu.com/1/status/username/changes?include_docs=auto

This will create an HTTP keep alive connection that pushes the status to you in realtime every time someone invokes our API:

  {
    "id": "https://webhooks.nodejitsu.com/1/status/dscape/changes/2b3de47c2ce04a9dda4d31aac5000a8d",
    "app_name": "hello-world-api-flatiron",
    "uuid": "5p45jm1332436661256",
    "status": "waiting",
    "provider": "github",
    "commit": "dscape/hello-world-flatiron-api/96410ed970f6224a4cd3c450150c5d65bbc77fcd"
  }
  {
    "id": "https://webhooks.nodejitsu.com/1/status/dscape/changes/2b3de47c2ce04a9dda4d31aac5000bab",
    "app_name": "hello-world-api-flatiron",
    "uuid": "aa6e9b1332436698771",
    "status": "ok",
    "provider": "travis",
    "commit": "dscape/hello-world-flatiron-api/96410ed970f6224a4cd3c450150c5d65bbc77fcd"
  }

Each request to our API is logged with a unique uuid, so you can use it to refer possible issues to our support staff.

We are now ready to deploy, go back to Github and click Test Hook. You should be up and running shortly.

Working with Travis

What about continuous integration? We added Travis-CI so you can feel safe about your deployments. Simply add something like this in your .travis.yml file.

notifications:  
  webhooks: 
    urls:
      - http://webhooks.nodejitsu.com/1/deploy
    on_success: always
    on_failure: never

Internally our API will try to see if you have Travis configured like this, and if you do it will put the deployment request from Github on a hold until Travis informs us all tests have passed.

If tests failed we won't deploy. Simple.

What's next?

If you don't have a Nodejitsu account sign up for one at nodejitsu.com. Feel free to take a peek at our Getting Started guide, and also to check out webops.nodejitsu.com to see the status of your applications.

Join #nodejitsu on irc.freenode.net and get immediate assistance from our support team! Alternatively you can email support@nodejitsu.com.