A talk given at a SYDJS.com meetup held at the Atlassian offices on Wednesday 16th, February 2011.
Audio has been recorded and will be released at some stage.
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
Sydjs – Deploying Node.js and Staying Sane
1. Deploying Node.js
and staying sane
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
2. Quick Introduction
Micheil Smith
• An Engineer at Votizen (votizen.com)
• A core contributor to Node.js
• Current Node.js Documentation Lead
• Author of ‘node-websocket-server’
• Twittter: @miksago
• Email: micheil@votizen.com
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
3. What is Node.js
• Evented I/O For V8 JavaScript
• http://github.com/ry/node
• http://nodejs.org
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
4. In other words, you can build
some really awesome shit.
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
8. • Git based deployment honestly sucks
• Existing solutions do work, but aren’t perfect
• Rolling it ourselves is too much work
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
9. Git based deployment
honestly sucks
• Having multiple remotes isn’t much fun
• Repositories become out of sync
• Writing post-receive hooks is awful
• Can only really push to one server at a time
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
10. Existing solutions do
work, but aren’t perfect
Existing tools require you to work outside of
JavaScript & don’t integrate with the node.js
ecosystem.
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
11. Rolling it ourselves is
too much work
Nobody honestly wants to spend heaps of time
writing stuff just so they can get their code into
production.
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
13. Look, Learn, Create
• Other platforms have solutions
• What do we need in deployment?
• NPM exists, make use of it
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
14. Other platforms have
solutions
Java: CruiseControl
Ruby: Capistrano, Bundler
Twitter: Murder
Python: Fabric
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
15. What do we need in
deployment?
• Simple Configuration
• Versioning & Rollbacks
• Logs (well, duh, right?)
• Integration with NPM
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
16. NPM exists, make
use of it
NPM is great:
• It’s in the background
• It can handle a lot of the hard work
• Package.json files are great, use them
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
18. `npm install deploy`
The idea is to have a tool that:
• Doesn’t require too much setup
• Makes use of existing standards & extends them
• Doesn’t get in the way; you can do without it
• Stand-alone, not part of an existing tool
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
19. How’s it work? (part 1)
• Made up of two components:
• client-side CLI
• server-side daemon
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
20. How’s it work? (part 2)
Client-side: (Developer side)
• The application directory has a deploy.json
• A user or global .deployrc file
Server-side:
• A daemon for accepting deploys is running
• A global .deployrc file
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
21. deploy.json
Much like package.json, but contains:
• which servers to deploy to
• any dependencies that can’t be found on NPM
• any scripts to be run at different phases of
deployment
• location of the source code repository
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
23. Server-side .deployrc
A json file, telling the daemon the following:
• where to place code for certain sites
• users from which to accept deploys
• various other configuration
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
25. The server-side daemon
• A thin node net.Server
• Uses a protocol similar to netstrings + json
• Uses gzipped tarballs to transfer files
• Maintains logs and handles user management
• Could use alternative file-transfer methods
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
27. Not yet.
Over the next few months.
https://github.com/votizen/deploy
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
28. Other issues in deployment
• Ensuring your server is always up
• Managing settings & configuration
• Binding to privileged ports but not running as root?
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
29. Ensuring your server is
always up
• Use the tools that come with your OS, eg:
• Ubuntu has upstart
• Solaris has SMF
• Debian has Sysvconfig (can probably get Upstart)
• Monitor your processes
• Just to keep resources in check really.
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
30. Managing settings &
configuration
A few options available on the modules wiki page:
https://github.com/ry/node/wiki/Modules
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
31. Another way for Settings
Management
• Keep settings & commonly done stuff as a central
module.
• Use something like settings.js:
• https://gist.github.com/824688
Ask me after the talk and I can go into further detail
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH
32. Binding to privileged ports
but not running as root?
• Fairly easy to do with Node:
• first start with a umask of 007
• bind to the privileged port
• use process.setgid() and process.setuid() to drop
down privileges
SYDJS 2011-02-16 18:00:00 MICHEIL SMITH