Archive: 2014

0

Packer.io machine building and provisioning part 2

In the previous part of this series we had a look on building a bare Debian VM with the bare minimum packages installed to run a web server. In this part we will have a look on how we can improve our packer script with user variables and how to use the file and shell provisioner. User variablesVariables can be easily added to the packer script by adding following JSON. 1234567891011{ "variables": { "username": "root", "password": "r00tme", "memory": "1024", "cpus": "1", "database_name": "{{env `DB_NAME`}}" }, "builders": [{ // Left for brevity} Best practice is to put your variables as the first property in your JSON, before your builders. This way you have all the configurable values to your script quickly accessible. As you can see we define for each variable a default value, which will be used as the value when the user doesn’t provide one. For the “database_name” variable I used a special default. This default will be retrieved from your environment variables. You can set this kind of variable just as you would set any other variable from your command line/shell.

0

Packer.io machine building and provisioning part 1

Large development teams are often coping with the “It works on my machine” syndrome. One solution to solve these kind of issues is by give each single developer the same VM, which is most preferably the same as your production server. So imagine your company is building a web application. The web application is hosted on a Debian server using Apache, MySQL and PHP. So considering these preconditions I will give you a simple example to get your machines scripted en fully provisioned. In this first part of these series we will zoom in on the packer.io builders. So let me first explain you what packer is by quoting some statements of their webpage. Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.Modern, AutomatedPacker is easy to use and automates the creation of any type of machine image. It embraces modern configuration management by encouraging you to use automated scripts to install and configure the software within your Packer-made images. Packer brings machine images into the modern age, unlocking untapped potential and opening new opportunities. Works Great WithOut of the box Packer comes with support to build images for Amazon EC2, DigitalOcean, VirtualBox, and VMware. Support for more platforms is on the way, and anyone can add new platforms via plugins. In order to create an image for a specific platform packer uses builders. Since I don’t want to zoom in on creating your own builder plugin for your own platform and I don’t want you to have more cost to get up your VM I will use the VirtualBox builder in this example. VirtualBox is free to use, so if you don’t have it already installed on your machine please first install VirtualBox to continue with this example. VirtualBox will run on following OSes: Windows, Linux and Mac, so no matter what OS you’re on, you can continue reading.

0

Using Mocha Chai Sinon to test Node.js

In this article I’m going to show you how to write tests for your NodeJS application using Mocha, Chai and Sinon. Mocha is a feature-rich JavaScript test framework running on node.js and the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases. One of the cool things is you can choose your own assertion style when writing Mocha tests. In this article I will use Chai to do my assertions. Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any JavaScript testing framework. Chai supports 3 assertion styles. Should, expect and assert. This makes Mocha and Chai the ultimate combination to make your testing suite completely fit your own project needs and desires. As a mocking framework I choose Sinon since it integrates neatly with Mocha and Chai and dozens of other test frameworks. Standalone test spies, stubs and mocks for JavaScript. No dependencies, works with any unit testing framework. In order to start with writing your tests we first need to install Mocha, Chai and Sinon. Since I use Mocha for multiple projects I choose to install Mocha globally. 12npm install -g mochanpm install --save-dev mocha chai sinon To be sure the consumers of my node package also have mocha installed I also add it to the dev dependencies. Since I installed Mocha globally it won’t be installed in my package folder again. Now we can actually start writing our tests.

0

Automate your development tasks using Grunt

Grunt is an extremely useful Node.js package to automate lots of development and continuous integration tasks. The Grunt eco-system has lots of packages available on npm. This enables us to quickly setup our development/continuous integration environment. Grunt tasks mostly have two required properties. An files array, which is used to configure on what files the tasks is executed, and an options property which configures some task specific settings. The files array supports the globbing and minimatch pattern to match files based on the provided expression. So what tasks could you use for your projects, or for which project can you use Grunt? How do I configure Grunt tasks? How do I execute them? All these questions I try to answer for you in this article.