Permalink
Browse files

Extract Jamie code to jamie gem, whoo boy.

  • Loading branch information...
1 parent 931edaf commit d452be2e71cf0adcc179a719d13240c50263c264 @fnichol fnichol committed Dec 1, 2012
Showing with 4 additions and 235 deletions.
  1. +2 −3 Gemfile
  2. +1 −1 Rakefile
  3. +1 −1 Vagrantfile
  4. +0 −110 test/jamie.rb
  5. +0 −51 test/jamie/rake_task.rb
  6. +0 −69 test/jamie/vagrant.rb
View
@@ -8,7 +8,6 @@ gem 'foodcritic', :platforms => :ruby_19
gem 'chef', (ENV['CHEF_VERSION'] || '>= 0.10.10')
group :integration do
- gem 'berkshelf', '>= 1.0.0.rc3'
- gem 'hashie'
- gem 'mixlib-shellout'
+ gem 'berkshelf', '>= 1.0.0'
+ gem 'jamie', :git => 'git://github.com/jamie-ci/jamie.git'
end
View
@@ -1,7 +1,7 @@
#!/usr/bin/env rake
require 'foodcritic'
-require_relative 'test/jamie/rake_task'
+require 'jamie/rake_task'
FoodCritic::Rake::LintTask.new do |t|
t.options = { :fail_tags => ['any'] }
View
@@ -2,7 +2,7 @@
# vi: set ft=ruby :
require 'berkshelf/vagrant'
-require_relative 'test/jamie/vagrant'
+require 'jamie/vagrant'
Vagrant::Config.run do |config|
Jamie::Vagrant.define_vms(config)
View
@@ -1,110 +0,0 @@
-# -*- encoding: utf-8 -*-
-
-require 'yaml'
-require 'hashie/dash'
-require 'mixlib/shellout'
-
-module Jamie
- class Platform < Hashie::Dash
- property :name, :required => true
- property :vagrant_box
- property :vagrant_box_url
- property :base_run_list, :default => []
- end
-
- class Suite < Hashie::Dash
- property :name, :required => true
- property :run_list, :required => true
- property :json, :default => Hash.new
- end
-
- class Config
- attr_writer :yaml
- attr_writer :platforms
- attr_writer :suites
- attr_writer :backend
- attr_writer :log_level
- attr_writer :data_bags_base_path
-
- def yaml
- @yaml ||= File.join(Dir.pwd, '.jamie.yml')
- end
-
- def platforms
- @platforms ||=
- Array(yaml_data["platforms"]).map { |hash| Platform.new(hash) }
- end
-
- def suites
- @suites ||=
- Array(yaml_data["suites"]).map { |hash| Suite.new(hash) }
- end
-
- def backend
- @backend ||= backend_for(yaml_data["backend"] || "vagrant")
- end
-
- def log_level
- @log_level ||= :info
- end
-
- def data_bags_base_path
- default_path = File.join(Dir.pwd, 'test/integration')
-
- @data_bags_path ||= File.directory?(default_path) ? default_path : nil
- end
-
- def instances
- result = []
- suites.each do |suite|
- platforms.each do |platform|
- result << instance_name(suite, platform)
- end
- end
- result
- end
-
- private
-
- def yaml_data
- @yaml_data ||= YAML.load_file(yaml)
- end
-
- def instance_name(suite, platform)
- "#{suite.name}-#{platform.name}".gsub(/_/, '-').gsub(/\./, '')
- end
-
- def backend_for(backend)
- klass = Jamie::Backend.const_get(backend.capitalize)
- klass.new
- end
- end
-
- module Backend
- class CommandFailed < StandardError ; end
-
- class Vagrant
- def up(instance)
- exec! "vagrant up #{instance}"
- rescue Mixlib::ShellOut::ShellCommandFailed => ex
- raise CommandFailed, ex.message
- end
-
- def destroy(instance)
- exec! "vagrant destroy #{instance} -f"
- rescue Mixlib::ShellOut::ShellCommandFailed => ex
- raise CommandFailed, ex.message
- end
-
- def exec!(cmd)
- puts "-----> [vagrant command] #{cmd}"
- shellout = Mixlib::ShellOut.new(
- cmd, :live_stream => STDOUT, :timeout => 60000
- )
- shellout.run_command
- puts "-----> Command '#{cmd}' ran in #{shellout.execution_time} seconds."
- shellout.error!
- end
- end
- end
-end
@@ -1,51 +0,0 @@
-# -*- encoding: utf-8 -*-
-
-require 'rake'
-require 'rake/tasklib'
-require_relative '../jamie'
-
-module Jamie
- module Rake
- class Tasks < ::Rake::TaskLib
- attr_accessor :name
-
- def initialize(name = :jamie)
- @name = name
- yield self if block_given?
- define
- end
-
- def define
- config = Jamie::Config.new
-
- namespace(name) do
- config.instances.each do |instance_name|
- desc "Run #{instance_name} integration"
- task(instance_name) do
- puts "-----> Cleaning up any prior instances of #{instance_name}"
- config.backend.destroy(instance_name)
- puts "-----> Bringing up instance #{instance_name}"
- config.backend.up(instance_name)
- puts "-----> Instance #{instance_name} completed."
- end
-
- namespace(instance_name) do
- desc "Destroy #{instance_name} instance"
- task :destroy do
- puts "-----> Destroying any prior instances of #{instance_name}"
- config.backend.destroy(instance_name)
- puts "-----> Instance #{instance_name} destruction complete."
- end
- end
- end
-
- desc "Destroy all instances"
- task :destroy => config.instances.map { |i| "#{i}:destroy" }
- end
-
- desc "Run Jamie integration"
- task name => config.instances
- end
- end
- end
-end
View
@@ -1,69 +0,0 @@
-# -*- encoding: utf-8 -*-
-
-require_relative '../jamie'
-require 'vagrant'
-require 'forwardable'
-
-module Jamie
- module Vagrant
- class Config < ::Vagrant::Config::Base
- extend Forwardable
-
- def_delegators :@config, :yaml, :yaml=, :platforms, :platforms=,
- :suites, :suites=, :log_level, :log_level=,
- :data_bags_base_path, :data_bags_base_path=, :yaml_data
-
- def initialize
- @config = Jamie::Config.new
- end
- end
-
- def self.init!
- ::Vagrant.config_keys.register(:jamie) { Jamie::Vagrant::Config }
- end
-
- def self.define_vms(config)
- config.jamie.suites.each do |suite|
- config.jamie.platforms.each do |platform|
- define_vagrant_vm(config, suite, platform)
- end
- end
- end
-
- private
-
- def self.define_vagrant_vm(config, suite, platform)
- name = "#{suite.name}-#{platform.name}".gsub(/_/, '-').gsub(/\./, '')
-
- config.vm.define name do |c|
- c.vm.box = platform.vagrant_box
- c.vm.box_url = platform.vagrant_box_url if platform.vagrant_box_url
- c.vm.host_name = "#{name}.vagrantup.com"
- c.vm.customize ["modifyvm", :id, "--memory", "256"]
-
- c.vm.provision :chef_solo do |chef|
- chef.log_level = config.jamie.log_level
- chef.run_list = platform.base_run_list + Array(suite.run_list)
- chef.json = suite.json
- chef.data_bags_path = calculate_data_bags_path(config, name)
- end
- end
- end
-
- def self.calculate_data_bags_path(config, instance_name)
- base_path = config.jamie.data_bags_base_path
- instance_data_bags_path = File.join(base_path, instance_name, "data_bags")
- common_data_bags_path = File.join(base_path, "data_bags")
-
- if File.directory?(instance_data_bags_path)
- instance_data_bags_path
- elsif File.directory?(common_data_bags_path)
- common_data_bags_path
- else
- nil
- end
- end
- end
-end
-
-Jamie::Vagrant.init!

0 comments on commit d452be2

Please sign in to comment.