Rapid Application Deployment Engine

Deploying node.js Applications

Deploy your node.js applications using git and git alone, with our without Web Server proxying.

Preparing

When you initialize Rapp on your node.js application, we’ll always look for a server.js file. If this file is not found, the deployment will fail.

When you run wn init for the first time, Rapp will try to search inside your server.js file for the node.js listening port.

It searches for the /listen\((\d+)\)/ regular expression that matches the usual code. For instance, if you have this:

http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/html"});
  response.write("<html><head><title>Node, node, node</title>
    </head>\n");
  response.write("<body>\n");
  response.write("<a href='http://www.youtube.com/watch?v=C526lxeHo-M'>
    Node, Node, Node!</a>\n");
  response.write("</body>\n");
  response.write("</html>\n");
  response.end();
}).listen(1234);

When you initialize, it will default to port 1234, as can be seen below:

$ wn init
Webbynode Rapp - http://rapp.webbynode.com

Current Webbies in your account:

  1. hasmany.info (208.88.124.89)
  2. sandbox (208.88.125.207)
  3. wbno.de (208.88.125.65)
  4. wcdcompany (208.88.124.171)

Which Webby do you want to deploy to:
4

Set deployment Webby to wcdcompany.
[Webbynode] Initializing application nodeapp with dns nodeapp

Configure NodeJS Application

  Proxy requests (Y/n) [Y]? 
     Listening port [1234]:

In case we don’t have a match, or a wrong match, you can always override the value yourself.

The other question we ask when initializing is whether you want to proxy your node.js app or not. If you do, we’ll make sure that the Web Server maps your requests from port 80 and a given domain (for instance, nodeapp.webbyapp.com) to your app port. This way you can deploy multiple node.js applications in the same server and make it work parallel to Rails, Rack, and other apps you want.

Publishing

To publish your app, just run the usual wn push command:

$ wn push
[Webbynode] Pushing napp
Counting objects: 18, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (18/18), 1.71 KiB, done.
Total 18 (delta 4), reused 0 (delta 0)
remote: Checked out master branch
remote: 
remote: ----------------------------
remote:   Webbynode git deployment 
remote: ----------------------------
remote: 
remote: Nginx+Passenger webserver detected...
remote: Setting up DNS...
remote: 
remote: Deploying application napp as napp.webbyapp.com...
remote: 
remote: Configuring addons...
remote: 
remote: Configuring node.js application...
remote:   => Configuring nginx vHost...
remote:   => Configuring database...
remote:   => Configuring monit...
remote:   => Starting app...
remote: 
remote: napp deployed successfully.
remote: 
remote: Created http://napp.webbyapp.com/
remote: 
To ssh://git@208.88.124.171:22/var/rapp/napp
 * [new branch]      master -> master

[Webbynode] Finished pushing napp

Lifecycle

After your application is pushed to the server, we create a upstart script to start and stop your app quickly, and also make sure you app gets started between reboots.

Whenever you want to stop it, you can run this from the command line:

$ wn remote sudo stop napp

And then start it again:

$ wn remote sudo start napp

We also install and configure monit service for each application. So, if for any reason your application halts, it will be automatically restarted.

Installing npm packages

To install npm packages, just run:

$ wn remote npm install [package]

The goodness

Along with your application, we created an upstart script (so your application is always started when your Webby reboots) and a monit script, so if your application goes down, we attempt to restart it.

The monit script is always installed to /etc/monit/services/your_app_name and the upstart script to /etc/init/your_app.conf, in case you need to customize them for your needs.

Summary

As you can see, we do all the heavy lifting for you. When you first push a node.js app, we install and configure node.js and all its dependencies, along with monit and npm.

And here’s a summary of what takes place when deploying each app:

  1. Transfers all application files to the remote server;
  2. Creates a new dns in the format appname.webbyapp.com;
  3. If you answer Y to proxy, adds a new vHost to the WebServer (nginx or Apache), pointing to your node.js app;
  4. Creates a new database and database user for your app (MySQL or PostgreSQL) — this will become optional soon;
  5. Creates an upstart script for stopping and starting your node.js app;
  6. Creates a monit service for monitoring your node.js app;
Comments
blog comments powered by Disqus