Sha256: 72316d7e8f00d5f5b8d55fdb10b908821286dd66a0342d62b9e7c87e1396ea58

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

#!/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)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soloist-0.0.1 bin/soloist