Skip to content
Browse files

sort of working now

  • Loading branch information...
1 parent 5dbacdd commit f2324aa15f8599d449d99b24829ae89081d24f07 @mkocher committed Nov 15, 2010
Showing with 97 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +4 −0 Gemfile
  3. +2 −0 Rakefile
  4. +58 −0 bin/soloist
  5. +3 −0 lib/soloist.rb
  6. +3 −0 lib/soloist/version.rb
  7. +24 −0 soloist.gemspec
View
3 .gitignore
@@ -0,0 +1,3 @@
+pkg/*
+*.gem
+.bundle
View
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in soloist.gemspec
+gemspec
View
2 Rakefile
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
View
58 bin/soloist
@@ -0,0 +1,58 @@
+#!/usr/bin/env ruby
+require 'rubygems'
+require "json"
+require 'fileutils'
+require 'yaml'
+require 'tempfile'
+
+def fileify(contents)
+ file = Tempfile.new("sololist")
+ file << contents
+ file.flush
+ file
+end
+
+class Array
+ def to_array_string
+ "[\"#{self.join("\", \"")}\"]"
+ end
+end
+
+def walk_up_and_find_file(filenames)
+ pwd = FileUtils.pwd
+ file = nil
+ path_to_file = ""
+ while !file && FileUtils.pwd != '/'
+ file = filenames.detect { |f| Dir.glob("*").include?(f) }
+ FileUtils.cd("..")
+ path_to_file << "../" unless file
+ end
+ FileUtils.cd(pwd)
+ File.read(path_to_file + file) if file
+end
+
+log_level = ENV['LOG_LEVEL'] || "info"
+
+soloistrc = YAML.load(walk_up_and_find_file(["soloistrc"]))
+
+json_contents = {
+ :recipes => soloistrc["Recipes"]
+}
+
+solo_rb_contents = "cookbook_path #{soloistrc["Cookbook_Paths"].to_array_string}"
+
+# if ARGV.length >= 1
+# json_config = JSON.parse(File.read(json_file))
+# json_config["recipes"] = ARGV
+# json_file = "/tmp/#{File.basename(json_file)}"
+# puts "OVERRIDING RECIPES: running [#{json_config["recipes"].join(", ")}]. Temp json config file: #{json_file}"
+# File.open(json_file, "w+"){|f| f<<JSON.pretty_generate(json_config) }
+# end
+
+solo_rb = fileify(solo_rb_contents)
+metadata_json = fileify(json_contents.to_json)
+
+command = "sudo bash -c 'RAILS_ENV=$RAILS_ENV chef-solo -j #{metadata_json.path} -c #{solo_rb.path} -l #{log_level}'"
+
+puts "running chef: " + command
+system(command) || exit(1)
View
3 lib/soloist.rb
@@ -0,0 +1,3 @@
+module Soloist
+ # Your code goes here...
+end
View
3 lib/soloist/version.rb
@@ -0,0 +1,3 @@
+module Soloist
+ VERSION = "0.0.1"
+end
View
24 soloist.gemspec
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "soloist/version"
+
+Gem::Specification.new do |s|
+ s.name = "soloist"
+ s.version = Soloist::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Matthew Kocher"]
+ s.email = ["kocher@gmail.com"]
+ s.homepage = "http://rubygems.org/gems/soloist"
+ s.summary = %q{Soloist is a simple way of running chef-solo}
+ s.description = %q{Soloist is an easy way of running chef solo, but it's not doing much.}
+
+ s.rubyforge_project = "soloist"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency('chef', '0.9.12')
+ s.add_dependency('json', '1.4.6')
+end

0 comments on commit f2324aa

Please sign in to comment.
Something went wrong with that request. Please try again.