Created
February 22, 2017 13:34
-
-
Save dprotaso/29452999bbedc7efa2134da84f5c1be9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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