Skip to content

Commit

Permalink
Add support for using deployment spec values within appspec.yml file.…
Browse files Browse the repository at this point in the history
  • Loading branch information
ejhayes committed Jun 22, 2018
1 parent 81ffec2 commit 743f6f6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
8 changes: 8 additions & 0 deletions lib/instance_agent/plugins/codedeploy/command_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion lib/instance_agent/plugins/codedeploy/hook_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 743f6f6

Please sign in to comment.