Skip to content

Commit

Permalink
Merge pull request aspring#2 from tdg5/ws
Browse files Browse the repository at this point in the history
Correct whitespace errors
  • Loading branch information
aspring committed Sep 23, 2014
2 parents d7f1f0a + 6e31d2c commit 96a4388
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 33 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ Racker is able to take multiple Racker templates, merge them together, and gener
## Installation

$ gem install racker

## Usage
To generate a Packer template from a Racker template, run:

$ racker rackertemplate1.rb packertemplate.json

To generate a Packer template from multiple Racker templates, run:

$ racker rackertemplate1.rb rackertemplate2.rb packertemplate.json

To merge multiple templates you can keep adding Racker templates:

$ racker rackertemplate1.rb rackertemplate2.rb rackertemplate3.rb packertemplate.json

The output of the previous command will be template 1 deep merged with template2, the result of this merge is deep merged with template 3 then output as a packer template.

## Racker Template Syntax
The goal of Racker is to provide a template structure that allows for allowing full control of the template merging process to achieve the desired Packer template.
The goal of Racker is to provide a template structure that allows for allowing full control of the template merging process to achieve the desired Packer template.

In order to do this Racker takes an opinionated stance on the following:

Expand Down Expand Up @@ -73,7 +73,7 @@ end

#### Builders Namespace

Racker templates support the `builders` namespace which is a hash, keyed by the name of the builder.
Racker templates support the `builders` namespace which is a hash, keyed by the name of the builder.

All Packer arrays inside of this namespace should be represented as hashes in Racker. Racker will use the value when creating the template, the key is there purely for allowing you to override/knockout as necessary.

Expand Down Expand Up @@ -115,7 +115,7 @@ One of the sections of node in this builder is the `vboxmanage`. It has been co

#### Provisioners Namespace

Racker templates support the `provisioners` namespace which is a Fixnum keyed hash.
Racker templates support the `provisioners` namespace which is a Fixnum keyed hash.

When generating the Packer template, Racker will order the provisioners based upon the Fixnum key, this allows complete control on the ordering of provisioners throughout Racker templates.

Expand Down Expand Up @@ -189,7 +189,7 @@ Racker offers 2 very basic example templates `example/template1.rb` and `example
To experiement with these templates, after installing Racker, and cloning this repo you can execute the following:

$ racker ./example/template1rb ./example/tempalte2.rb ./example/packer.json

While these two templates are not all inclusive of the capabilities of Racker, it shows off the ability to have a basic template, and a second template that removes the pieces of the template that target Amazon, as well as adds two chef solo provisioner steps.

## Testing
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |t|
# Specify the files we will look at
t.patterns = ['bin', File.join('{lib}','**', '*.rb')]

# Do not fail on error
t.fail_on_error = false
end
Expand Down
4 changes: 2 additions & 2 deletions bin/racker
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if RUBY_VERSION >= '1.9.2'
begin
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
require 'racker'

# Create the initial logger
log = Log4r::Logger.new('racker')

Expand All @@ -16,7 +16,7 @@ if RUBY_VERSION >= '1.9.2'

# We set the initial log level to ERROR
log.level = Log4r::ERROR

# Let the CLI do its thing
exit_code = Racker::CLI.new(ARGV.dup).execute!

Expand Down
4 changes: 2 additions & 2 deletions example/template1.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Racker::Processor.register_template do |t|

# Define the variables
t.variables = {
'iso_checksum' => '6232efa014d9c6798396b63152c4c9a08b279f5e',
Expand Down Expand Up @@ -181,5 +181,5 @@
'keep_input_artifact' => true,
'only' => ['virtualbox-vagrant','vmware-vagrant']
}

end
2 changes: 1 addition & 1 deletion example/template2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Knock out the amazon builder as it is not needed by this template
t.builders['amazon'] = '~~'

# Define the provisioners
t.provisioners = {
600 => {
Expand Down
2 changes: 1 addition & 1 deletion lib/racker/builders/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Builder
def to_packer(name, config)
log = Log4r::Logger['racker']
log.debug("Entering #{self.class}.#{__method__}")

# Set the name of the builder
log.info("Setting config name to #{name}")
config['name'] = name
Expand Down
2 changes: 1 addition & 1 deletion lib/racker/builders/digitalocean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def to_packer(name, config)
config = super(name, config)

# There are no special cases at this point

# %w().each do |key|
# if config.key? key
# log.info("Converting #{key} to packer value...")
Expand Down
2 changes: 1 addition & 1 deletion lib/racker/builders/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def to_packer(name, config)
config = super(name, config)

# There are no special cases at this point

# %w().each do |key|
# if config.key? key
# log.info("Converting #{key} to packer value...")
Expand Down
2 changes: 1 addition & 1 deletion lib/racker/builders/null.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def to_packer(name, config)
config = super(name, config)

# There are no special cases at this point

# %w().each do |key|
# if config.key? key
# log.info("Converting #{key} to packer value...")
Expand Down
10 changes: 5 additions & 5 deletions lib/racker/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def execute!

# Display the options if a minimum of 1 template and an output file is not provided
if @argv.length < 2
puts option_parser
puts option_parser
Kernel.exit!(1)
end

Expand All @@ -49,7 +49,7 @@ def execute!

return 0
end

private

def get_log4r_level(level)
Expand All @@ -72,17 +72,17 @@ def get_log4r_level(level)
def options
@options ||= {
log_level: :warn,
knockout: '~~',
knockout: '~~',
output: '',
templates: [],
quiet: false,
quiet: false,
}
end

def option_parser
@option_parser ||= OptionParser.new do |opts|
opts.banner = "Usage: #{opts.program_name} [options] [TEMPLATE1, TEMPLATE2, ...] OUTPUT"

opts.on('-l', '--log-level [LEVEL]', [:fatal, :error, :warn, :info, :debug], 'Set log level') do |v|
options[:log_level] = v
end
Expand Down
10 changes: 5 additions & 5 deletions lib/racker/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(options)
def execute!
# Get the global logger
log = Log4r::Logger['racker']

# Verify that the templates exist
@options[:templates].each do |template|
raise "File does not exist! (#{template})" unless ::File.exists?(template)
Expand Down Expand Up @@ -60,16 +60,16 @@ def execute!
templates.each do |template|
current_template = current_template.deep_merge!(template, {:knockout_prefix => @options[:knockout]})
end

# Compact the residual template to remove nils
log.info('Compacting racker template...')
compact_template = current_template.compact(:recurse => true)

# Write the compact template out to file
File.open(@options[:output], 'w') do |file|
log.info('Writing packer template...')
log.info('Writing packer template...')
file.write(JSON.pretty_generate(compact_template.to_packer))
log.info('Writing packer template complete.')
log.info('Writing packer template complete.')
end
end

Expand Down Expand Up @@ -98,4 +98,4 @@ def capture_templates
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/racker/smash/deep_merge_modified.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class InvalidParameter < StandardError; end
# dest = {:x => [{:z => 2}]}
# dest.deep_merge!(source, {:merge_hash_arrays => true})
# Results: {:x => [{:y => 1, :z => 2}]}
#
#
# There are many tests for this library - and you can learn more about the features
# and usages of deep_merge! by just browsing the test examples
def self.deep_merge!(source, dest, options = {})
Expand Down
4 changes: 2 additions & 2 deletions lib/racker/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Template < Smash
def to_packer
# Get the global logger
log = Log4r::Logger['racker']

# Create the new smash
packer = Smash.new

# Variables
packer['variables'] = self['variables'].dup unless self['variables'].nil? || self['variables'].empty?

# Builders
packer['builders'] = [] unless self['builders'].nil? || self['builders'].empty?
log.info("Processing builders...")
Expand Down
2 changes: 1 addition & 1 deletion racker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |gem|

gem.add_dependency 'multi_json', '~> 1.8'
gem.add_dependency 'log4r', '~> 1.1.10'

gem.add_development_dependency 'bundler', '~> 1.3'
gem.add_development_dependency 'coveralls', '~> 0.6.7'
gem.add_development_dependency 'guard', '~> 2.2.3'
Expand Down

0 comments on commit 96a4388

Please sign in to comment.