diff --git a/bosh_template_go.go b/bosh_template_go.go index e51267c..c909afe 100644 --- a/bosh_template_go.go +++ b/bosh_template_go.go @@ -35,6 +35,7 @@ type EvaluationContext struct { type InstanceInfo struct { Address string `yaml:"address"` AZ string `yaml:"az"` + Bootstrap bool `yaml:"bootstrap"` Deployment string `yaml:"deployment"` ID string `yaml:"id"` Index int `yaml:"index"` diff --git a/bosh_template_go_test.go b/bosh_template_go_test.go index e14057e..af80a26 100644 --- a/bosh_template_go_test.go +++ b/bosh_template_go_test.go @@ -170,6 +170,7 @@ func TestRenderWithInstanceInfo(t *testing.T) { &InstanceInfo{ AZ: "myaz", Address: "foo.deadbeef.com", + Bootstrap: true, Deployment: "mydeployment", ID: "005443", IP: "256.256.256.256", @@ -189,7 +190,7 @@ func TestRenderWithInstanceInfo(t *testing.T) { // Assert assert.NoError(err) - assert.Equal("foo.deadbeef.com myaz false mydeployment 005443 123 256.256.256.256 foo\n", string(output)) + assert.Equal("foo.deadbeef.com myaz true mydeployment 005443 123 256.256.256.256 foo\n", string(output)) } func TestRenderWithLinks(t *testing.T) { diff --git a/go.sum b/go.sum index 18e1a88..8e29873 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ +github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg= github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0= github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ= github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0= +github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw= github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY= github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E= @@ -8,7 +10,9 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -17,7 +21,9 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/rb/template_evaluation_context.rb b/rb/template_evaluation_context.rb index 6b18908..7afa9b7 100644 --- a/rb/template_evaluation_context.rb +++ b/rb/template_evaluation_context.rb @@ -42,10 +42,10 @@ instances << Bosh::Template::Test::InstanceSpec.new( address: link_instance['address'], az: link_instance['az'], + bootstrap: link_instance['bootstrap'], id: link_instance['id'], index: link_instance['index'], name: link_instance['name'], - bootstrap: link_instance['index'] == '0', ) end links << Bosh::Template::Test::Link.new(name: name, instances: instances, properties: link['properties']) @@ -56,7 +56,7 @@ instance = Bosh::Template::Test::InstanceSpec.new( address: instance_info['address'], az: instance_info['az'], - bootstrap: instance_info['index'] == '0', + bootstrap: instance_info['bootstrap'], deployment: instance_info['deployment'], id: instance_info['id'], index: instance_info['index'], diff --git a/rice-box.go b/rice-box.go index 764ff28..4e8b6f0 100644 --- a/rice-box.go +++ b/rice-box.go @@ -11,15 +11,15 @@ func init() { // define files file2 := &embedded.EmbeddedFile{ Filename: "template_evaluation_context.rb", - FileModTime: time.Unix(1559331681, 0), + FileModTime: time.Unix(1562861680, 0), - Content: string("require \"bosh/template\"\nrequire \"erb\"\nrequire \"fileutils\"\nrequire \"json\"\nrequire \"yaml\"\n\nif $0 == __FILE__\n context_path, spec_path, instance_path, src_path, dst_path = *ARGV\n\n puts \"Context file: #{context_path}\"\n puts \"Instance file: #{instance_path}\"\n puts \"Spec file: #{spec_path}\"\n puts \"Template file: #{src_path}\"\n puts \"Output file: #{dst_path}\"\n\n # Load the context hash\n context_hash = YAML.load_file(context_path)\n\n # Load the job spec\n job_spec = YAML.load_file(spec_path)\n job_spec['properties'] = {} if job_spec['properties'].nil?\n\n # Load the instace info\n instance_info = YAML.load_file(instance_path)\n\n # Read the erb template\n begin\n perms = File.stat(src_path).mode\n template = Bosh::Template::Test::Template.new(job_spec, src_path)\n rescue Errno::ENOENT\n raise \"failed to read template file #{src_path}\"\n end\n\n # Build links\n links = []\n if context_hash['properties'] && context_hash['properties']['bosh_containerization'] && context_hash['properties']['bosh_containerization']['consumes']\n context_hash['properties']['bosh_containerization']['consumes'].each_pair do |name, link|\n next if link['instances'].empty?\n\n instances = []\n link['instances'].each do |link_instance|\n instances << Bosh::Template::Test::InstanceSpec.new(\n address: link_instance['address'],\n az: link_instance['az'],\n id: link_instance['id'],\n index: link_instance['index'],\n name: link_instance['name'],\n bootstrap: link_instance['index'] == '0',\n )\n end\n links << Bosh::Template::Test::Link.new(name: name, instances: instances, properties: link['properties'])\n end\n end\n\n # Build instance\n instance = Bosh::Template::Test::InstanceSpec.new(\n address: instance_info['address'],\n az: instance_info['az'],\n bootstrap: instance_info['index'] == '0',\n deployment: instance_info['deployment'],\n id: instance_info['id'],\n index: instance_info['index'],\n ip: instance_info['ip'],\n name: instance_info['name'],\n networks: {'default' => {'ip' => instance_info['ip'],\n 'dns_record_name' => instance_info['address'],\n # TODO: Do we need more, like netmask and gateway?\n # https://github.com/cloudfoundry/bosh-agent/blob/master/agent/applier/applyspec/v1_apply_spec_test.go\n }},\n )\n\n # Process the Template\n output = template.render(context_hash['properties'], spec: instance, consumes: links)\n\n begin\n # Open the output file\n output_dir = File.dirname(dst_path)\n FileUtils.mkdir_p(output_dir)\n out_file = File.open(dst_path, 'w')\n\n # Write results to the output file\n out_file.write(output)\n\n # Set the appropriate permissions on the output file\n if File.basename(File.dirname(dst_path)) == 'bin'\n out_file.chmod(0755)\n else\n out_file.chmod(perms)\n end\n rescue Errno::ENOENT, Errno::EACCES => e\n out_file = nil\n raise \"failed to open output file #{dst_path}: #{e}\"\n ensure\n out_file.close unless out_file.nil?\n end\nend\n"), + Content: string("require \"bosh/template\"\nrequire \"erb\"\nrequire \"fileutils\"\nrequire \"json\"\nrequire \"yaml\"\n\nif $0 == __FILE__\n context_path, spec_path, instance_path, src_path, dst_path = *ARGV\n\n puts \"Context file: #{context_path}\"\n puts \"Instance file: #{instance_path}\"\n puts \"Spec file: #{spec_path}\"\n puts \"Template file: #{src_path}\"\n puts \"Output file: #{dst_path}\"\n\n # Load the context hash\n context_hash = YAML.load_file(context_path)\n\n # Load the job spec\n job_spec = YAML.load_file(spec_path)\n job_spec['properties'] = {} if job_spec['properties'].nil?\n\n # Load the instace info\n instance_info = YAML.load_file(instance_path)\n\n # Read the erb template\n begin\n perms = File.stat(src_path).mode\n template = Bosh::Template::Test::Template.new(job_spec, src_path)\n rescue Errno::ENOENT\n raise \"failed to read template file #{src_path}\"\n end\n\n # Build links\n links = []\n if context_hash['properties'] && context_hash['properties']['bosh_containerization'] && context_hash['properties']['bosh_containerization']['consumes']\n context_hash['properties']['bosh_containerization']['consumes'].each_pair do |name, link|\n next if link['instances'].empty?\n\n instances = []\n link['instances'].each do |link_instance|\n instances << Bosh::Template::Test::InstanceSpec.new(\n address: link_instance['address'],\n az: link_instance['az'],\n bootstrap: link_instance['bootstrap'],\n id: link_instance['id'],\n index: link_instance['index'],\n name: link_instance['name'],\n )\n end\n links << Bosh::Template::Test::Link.new(name: name, instances: instances, properties: link['properties'])\n end\n end\n\n # Build instance\n instance = Bosh::Template::Test::InstanceSpec.new(\n address: instance_info['address'],\n az: instance_info['az'],\n bootstrap: instance_info['bootstrap'],\n deployment: instance_info['deployment'],\n id: instance_info['id'],\n index: instance_info['index'],\n ip: instance_info['ip'],\n name: instance_info['name'],\n networks: {'default' => {'ip' => instance_info['ip'],\n 'dns_record_name' => instance_info['address'],\n # TODO: Do we need more, like netmask and gateway?\n # https://github.com/cloudfoundry/bosh-agent/blob/master/agent/applier/applyspec/v1_apply_spec_test.go\n }},\n )\n\n # Process the Template\n output = template.render(context_hash['properties'], spec: instance, consumes: links)\n\n begin\n # Open the output file\n output_dir = File.dirname(dst_path)\n FileUtils.mkdir_p(output_dir)\n out_file = File.open(dst_path, 'w')\n\n # Write results to the output file\n out_file.write(output)\n\n # Set the appropriate permissions on the output file\n if File.basename(File.dirname(dst_path)) == 'bin'\n out_file.chmod(0755)\n else\n out_file.chmod(perms)\n end\n rescue Errno::ENOENT, Errno::EACCES => e\n out_file = nil\n raise \"failed to open output file #{dst_path}: #{e}\"\n ensure\n out_file.close unless out_file.nil?\n end\nend\n"), } // define dirs dir1 := &embedded.EmbeddedDir{ Filename: "", - DirModTime: time.Unix(1559325973, 0), + DirModTime: time.Unix(1562811983, 0), ChildFiles: []*embedded.EmbeddedFile{ file2, // "template_evaluation_context.rb" @@ -32,7 +32,7 @@ func init() { // register embeddedBox embedded.RegisterEmbeddedBox(`rb`, &embedded.EmbeddedBox{ Name: `rb`, - Time: time.Unix(1559325973, 0), + Time: time.Unix(1562811983, 0), Dirs: map[string]*embedded.EmbeddedDir{ "": dir1, },