hh54188
hh54188

Reputation: 15646

Node.js: the website deploy strategy

I use node.js to develop web app and website

but when I want deploy the app to some Pass, I have to optimize the app by myself, hand by hand

like

this workflow upset me, so my question is, is there some tool or modules could optimize this workflow, or do this job in automatic

what's your deploy strategy ?

Upvotes: 3

Views: 1711

Answers (2)

jonschlinkert
jonschlinkert

Reputation: 11007

You should really look at Grunt.js.

Brandon's answer is good, but I can only guess he hasn't had experience with Grunt. Make is now nothing but a distant and painful memory for me.

Grunt itself is just a "task runner", while all of the heavy lifting is done by "plugins", each of which powers a specific "task" inside your Gruntfile. So there is a plugin for compiling SASS to CSS, a plugin for YUI doc, and so on. You can find hundreds of Grunt plugins in the GitHub community and on the Grunt.js website, here: http://gruntjs.com/plugins.

Also, all of the "grunt-contrib-" plugins are curated by the Grunt.js core team, and each focuses on doing a really great job at something specific. There is a plugin for minifying CSS, another for uglifying (minifying/obscuring) JavaScripts, one for concatenating files, and so on. There is even a plugin for generating static sites, assemble (I'm one of the maintainers).

Upvotes: 2

Brandon
Brandon

Reputation: 10058

What you need is a build tool. In Java, ant and maven are the popular choices. In the node.js world, there are a ton of build tools. The two I am the most familiar with are grunt and buildr (full disclosure: I am a maintainer of buildr).

Either tool boils down to you writing a configuration file specifying your source files/directories and what you would like done to them, options being minification, concatenation, Saas or Stylus compilation, etc.

https://github.com/gruntjs/grunt

https://github.com/balupton/buildr.npm

For a deployment workflow, I recommend the following steps:

  1. Clean checkout of your web site or app code from source control (Git or Subversion or whatnot).
  2. Run the grunt or buildr command to compile all of your web site resources.
  3. Upload the results to your web server and then restart the node.js process. Lots of ways to do this.

For an application, I would recommend deleting the installation directory on the remote system and SCP'ing the new version up in its place. This assumes the presence of a load balancer.

Depending on your app, this may be simple enough to script yourself with a shell script, or you could use a tool like capistrano or fleet.

https://github.com/capistrano/capistrano

https://github.com/substack/fleet

For a simple web site, I recommend something that looks at file differences like rsync. I use rsync for my personal web site since it's just static content and I don't have to worry about dependencies and such.

So a release could go something like

$ git clone git://github.com/whatever.git && (cd whatever && buildr && rsync -avz --delete -e ssh <remote server>:webroot)

Or for an app, a little more automated:

$ git clone git://github.com/whatever.git && (cd whatever && buildr && make upload)

For a major app:

$ buildApp && deployApp

With buildApp and deployApp being scripts that contain all of the commands, logging, configuration, etc. needed to build and deploy.

Upvotes: 4

Related Questions