Skip to content

Instantly share code, notes, and snippets.

@dprotaso
Created February 22, 2017 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dprotaso/29452999bbedc7efa2134da84f5c1be9 to your computer and use it in GitHub Desktop.
Save dprotaso/29452999bbedc7efa2134da84f5c1be9 to your computer and use it in GitHub Desktop.
require 'active_support/core_ext/hash'
require 'erb'
require 'yaml'
require 'ostruct'
require 'bosh/template/evaluation_context'
require 'json'
include Bosh::Template::PropertyHelper
if ARGV.empty?
puts "ruby run-job.rb [job] [env.yml]"
exit
end
jobName = ARGV[0]
envFile = ARGV[1]
envProperties = YAML.load(File.open(envFile))
spec = YAML.load(File.open("../jobs/#{jobName}/spec"))
properties = spec["properties"]
newProperties = {}
properties.each_pair do |name, definition|
unless definition["default"] == nil
copy_property(newProperties, properties, name, definition["default"])
end
end
spec["properties"] = newProperties.deep_merge(envProperties)
evaluation_context = Bosh::Template::EvaluationContext.new(spec)
template_name = "../jobs/#{jobName}/templates/errand.sh.erb"
template = ERB.new(File.read(template_name))
script = template.result(evaluation_context.get_binding)
exec script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment