Rna gem

Build History

Rna is a ruby gem that provides simple DSL for generating node.json files required by chef-solo.

Requirements


$ gem install rna

Usage


$ mkdir rna_project
$ cd rna_project
$ rna init

This will sets starter config/rna.rb and config/s3.yml files.

Example rna.rb file

# This is starter example rna template.
# This is meant be be modified to your needs.
###################################
# Settings
default_inherits 'base'
global(:except => 'base') do
  set 'framework_env', 'production'
end

###################################
pre_rule do
  set 'chef_branch', 'prod' if role =~ /^prod/
  set 'chef_branch', 'master' if role =~ /^stag/
end

###################################
# Roles
# base
role 'base' do
  run_list ['base']
end
# api
role 'prod-api-redis', 'stag-api-redis' do
  run_list ['base','api_redis']
end
role 'prod-api-app', 'stag-api-app' do
  run_list ['base','api_app']
  set 'application', 'api'
  set 'deploy_code', true
  set 'repository', '[email protected]:br/api.git'
end
role 'prod-api-resque', 'stag-api-resque' do
  inherits 'prod-api-app'
  run_list ['base','api_resque']
  set 'workers', 8
end

###################################
# Post processing rules that run at the end
post_rule do
  set 'framework_env', 'production' if role =~ /^prod/
  set 'framework_env', 'staging' if role =~ /^stag/
end

$ rna generate

Here's the example of the output looks like:

output/base.json:

{
  "role": "base",
  "run_list": [
    "base"
  ]
}

output/prod-api-app.json:

{
  "framework_env": "production",
  "role": "prod-api-app",
  "run_list": [
    "base",
    "api_app"
  ],
  "application": "api",
  "deploy_code": true,
  "repository": "[email protected]:br/api.git"
}

output/prod-api-redis.json:

{
  "framework_env": "production",
  "role": "prod-api-redis",
  "run_list": [
    "base",
    "api_redis"
  ]
}

output/prod-api-resque.json:

{
  "framework_env": "production",
  "role": "prod-api-resque",
  "run_list": [
    "base",
    "api_resque"
  ],
  "application": "api",
  "deploy_code": true,
  "repository": "[email protected]:br/api.git",
  "workers": 8
}

output/stag-api-app.json:

{
  "framework_env": "staging",
  "role": "stag-api-app",
  "run_list": [
    "base",
    "api_app"
  ],
  "application": "api",
  "deploy_code": true,
  "repository": "[email protected]:br/api.git"
}

output/stag-api-redis.json:

{
  "framework_env": "staging",
  "role": "stag-api-redis",
  "run_list": [
    "base",
    "api_redis"
  ]
}

output/stag-api-resque.json:

{
  "framework_env": "staging",
  "role": "stag-api-resque",
  "run_list": [
    "base",
    "api_resque"
  ],
  "application": "api",
  "deploy_code": true,
  "repository": "[email protected]:br/api.git",
  "workers": 8
}

$ rna build -o s3 # saves s3 based on config/s3.yml settings

The config/s3.yml should look like this:

access_key_id: hocuspocus
secret_access_key: opensesame
bucket: my-bucket
folder: chef/rna