Grunt deploy, fabric-style

October 3, 2013

Fabric is a great little deployment gem from the Python world. It enables you to define simple tasks aimed towards a smooth deployment process. What I like the most is that it is all about bash commands: tar -xvf ..., mv .., cp ... It is not exactly 'low-level', but it doesn't hide anything in abstract wrapper functions either.

Although ..

There are some functionalities (operations) that abstract away some of the regular tasks.

In comes Grunt-fabric-deploy

Heavily inspired on the concept of Fabric I build grunt-fabric-deploy. It contains the same sort of no-nonsense operations and functionality, but wrapped in a descriptive style and as a Grunt plugin.

Install the plugin via npm

$ npm install grunt-fabric-deploy

Create your Gruntfile

 1 module.exports = function(grunt) {
 2   grunt.initConfig({
 3 
 4     deploy: {
 5       options: {
 6         stdout: true,
 7         failOnError: true,
 8         variables: {
 9           packed: 'filename'
10           host: 'server.com',
11           port: 22,
12           user: 'deploy_user'
13         }
14       },
15 
16       pack: {
17         local: '/usr/bin/gnutar -zcf /tmp/{packed}.tar.gz -C ./ .'
18       },
19 
20       upload: {
21         put: {
22           src: '/tmp/{packed}.tar.gz',
23           dest: '/tmp/{packed}.tar.gz'
24         },
25         run: [
26           'rm -rf /tmp/{packed}',
27           'mkdir -p /tmp/{packed}',
28           'tar -zxf /tmp/{packed}.tar.gz -C /tmp/{packed}',
29 
30           'rm -rf /srv/www/server.com/public',
31           'mkdir -p /srv/www/server.com/public',
32           'mv /tmp/{packed}/* /srv/www/server.com/public/'
33         ]
34       }
35     }
36 
37   });
38 }

Result of a 'grunt deploy'

recorded via asciinema

Configuration

More information can be found on the Github page of grunt-fabric-deploy.

Discussion, links, and tweets

I'm a developer.