Last active
August 11, 2018 21:43
-
-
Save dprotaso/48ca78f01432dba30a36 to your computer and use it in GitHub Desktop.
Render a BOSH template
This file contains hidden or 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
#!/usr/bin/env ruby | |
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 "render-template [job] [template] [manifest]" | |
exit | |
end | |
jobName = ARGV[0] | |
template = ARGV[1] | |
envFile = ARGV[2] | |
release_dir= File.expand_path("..", File.dirname(__FILE__)) | |
envProperties = YAML.load(File.open(envFile)) | |
spec = YAML.load(File.open("#{release_dir}/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 = "#{release_dir}/jobs/#{jobName}/templates/#{template}" | |
template = ERB.new(File.read(template_name)) | |
script = template.result(evaluation_context.get_binding) | |
puts script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gemfile