Skip to content

Instantly share code, notes, and snippets.

@dprotaso
Last active August 11, 2018 21:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dprotaso/48ca78f01432dba30a36 to your computer and use it in GitHub Desktop.
Save dprotaso/48ca78f01432dba30a36 to your computer and use it in GitHub Desktop.
Render a BOSH template
#!/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
@dprotaso
Copy link
Author

dprotaso commented Feb 22, 2017

Gemfile

source 'https://rubygems.org'

gem 'bosh-template', '~> 1.3202.0'
gem 'activesupport', '~> 4.2.5.2'
gem 'rspec', '~> 3.4.0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment