node-packer

Keith Chester
2 min readOct 22, 2014

--

Skip to the code already?

Recently I’ve had to develop a very large infrastructure for a particular app at work. Sparing you the details, a quick 50k foot view of it would be:

  • A trio-cluster MongoDB server setup for automatic backup and failover, with an additional arbiter server for management
  • Multiple daemon task servers
  • An administrative server with limited IP access
  • Multiple node.js API servers
  • Load balancers and auto-scaling groups for aforementioned API servers and, finally,
  • Security groups to manage network security for the whole shebang.

I documented every step necessary to create the massive environment for maintenance and re-deployment purposes, but I couldn’t help but feel that there had to be a better way to quickly deploy infrastructure. My searches led me back to Hashicorp, a company that creates wonderful tools. I use one of their tools — Vagrant, already on my Surface to use Linux-only modules of node development.

Hashicorp has released two tools that caught my attention. Packer, and Terraform. Packer allows you to easily describe a server’s provisioning, then go out onto a given platform (AWS, Digital Ocean, VirtualBox, etc) and create the image for you. Terraform will take images (see the connection here?) and then build out entire infrastructures on cloud providers for you. The synergy is beautiful and I like where Hashicorp is going.

I want to build out some more automated deployment software for upcoming projects, but needed to wrap these two projects in a node module. I've just finished the first run-through on writing node-packer. It consists of two parts — packerCmd, a wrapper for the Packer build command, and PackerFile, a class to easily allow programmatically creating and managing a Packer file. PackerFile is the jewel of the module. Check out this working example:

var PackerFile = require(‘node-packerio’).PackerFilevar newImage = new PackerFile()
newImage.addAmazonEBS(process.env.AMAZON_ACCESS_TOKEN,
process.env.AMAZON_SECRET_TOKEN,
‘t1.micro’,
‘us-east-1',
‘ami-3d8457d’,
‘ubuntu’)
.shellCmd(‘sleep 30')
.shellCmd(‘sudo apt-get update’)
.shellCmd(‘sudo apt-get install nginx’)
.uploadFile(‘path/to/my/app’)
.build()

This would go out, create a micro-image on amazon AWS with nginx installed and configured.

This is, hopefully, one small step and piece that is part of a much larger and cooler project. I’m especially excited because it’s my first open sourced library of any signifigance.

Check it out.

--

--

Keith Chester

Developer + R&D for Fusion Marketing. Hardware maker. Node programmer. Entrepreneur. Curious fellow.