diff --git a/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb b/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb index 519b3ed9..5875bf4f 100644 --- a/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb +++ b/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb @@ -2,6 +2,8 @@ require 'instance_agent/plugins/codedeploy/application_specification/file_info' require 'instance_agent/plugins/codedeploy/application_specification/linux_permission_info' require 'instance_agent/plugins/codedeploy/application_specification/mode_info' +require 'ostruct' +require 'erb' module InstanceAgent module Plugins @@ -23,7 +25,10 @@ def initialize(yaml_hash, opts = {}) @permissions = parse_permissions(yaml_hash['permissions'] || []) end - def self.parse(app_spec_string) + def self.parse(app_spec_template_string, deployment_spec) + # make deployment_spec keys available to the yaml template + app_spec_string = ERB.new(app_spec_template_string || '').result(OpenStruct.new(deployment_spec).instance_eval { binding }) + new(YAML.load(app_spec_string)) end diff --git a/lib/instance_agent/plugins/codedeploy/command_executor.rb b/lib/instance_agent/plugins/codedeploy/command_executor.rb index 3d1a1def..e1d0e51b 100644 --- a/lib/instance_agent/plugins/codedeploy/command_executor.rb +++ b/lib/instance_agent/plugins/codedeploy/command_executor.rb @@ -199,6 +199,14 @@ def most_recent_deployment_dir(deployment_group) def default_app_spec(deployment_spec) default_app_spec_location = File.join(archive_root_dir(deployment_spec), app_spec_path) log(:debug, "Checking for app spec in #{default_app_spec_location}") + app_spec = ApplicationSpecification::ApplicationSpecification.parse(File.read(default_app_spec_location), { + :application_name => deployment_spec.application_name, + :deployment_id => deployment_spec.deployment_id, + :deployment_group_name => deployment_spec.deployment_group_name, + :deployment_group_id => deployment_spec.deployment_group_id, + :deployment_root_dir => deployment_root_dir(deployment_spec), + :last_successful_deployment_dir => last_successful_deployment_dir(deployment_spec.deployment_group_id) + }) validate_app_spec_hooks(ApplicationSpecification::ApplicationSpecification.parse(File.read(default_app_spec_location)), deployment_spec.all_possible_lifecycle_events) end diff --git a/lib/instance_agent/plugins/codedeploy/hook_executor.rb b/lib/instance_agent/plugins/codedeploy/hook_executor.rb index 6674b090..dbfd6f45 100644 --- a/lib/instance_agent/plugins/codedeploy/hook_executor.rb +++ b/lib/instance_agent/plugins/codedeploy/hook_executor.rb @@ -227,7 +227,19 @@ def parse_app_spec http://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file.html MESSAGE end - @app_spec = InstanceAgent::Plugins::CodeDeployPlugin::ApplicationSpecification::ApplicationSpecification.parse(File.read(app_spec_location)) + @app_spec = InstanceAgent::Plugins::CodeDeployPlugin::ApplicationSpecification::ApplicationSpecification.parse(File.read(app_spec_location), deployment_spec) + end + + private + def deployment_spec + { + :application_name => @application_name, + :deployment_id => @deployment_id, + :deployment_group_name => @deployment_group_name, + :deployment_group_id => @deployment_group_id, + :deployment_root_dir => @current_deployment_root_dir, + :last_successful_deployment_dir => @last_successful_deployment_dir + } end private diff --git a/test/instance_agent/plugins/codedeploy/command_executor_test.rb b/test/instance_agent/plugins/codedeploy/command_executor_test.rb index fc10b105..7e783f64 100644 --- a/test/instance_agent/plugins/codedeploy/command_executor_test.rb +++ b/test/instance_agent/plugins/codedeploy/command_executor_test.rb @@ -152,7 +152,7 @@ def generate_signed_message_for(map) stubs(:read). with("#@archive_root_dir/appspec.yml"). returns("APP SPEC") - ApplicationSpecification::ApplicationSpecification.stubs(:parse).with("APP SPEC").returns(@app_spec) + ApplicationSpecification::ApplicationSpecification.stubs(:parse).with("APP SPEC", {}).returns(@app_spec) end should "create an appropriate Installer" do