From 4f7fdb9465b4e553982c96fb510d955cd21c098b Mon Sep 17 00:00:00 2001 From: Alex Chumak Date: Mon, 25 Apr 2016 20:13:49 -0400 Subject: [PATCH 1/2] Allow custom environment to be added to any layer, not just rails-app It will restart the server in a rails-app layer only. And will only write application.yml if it is a rails app that is being deployed. --- recipes/configure.rb | 8 ++------ recipes/restart_command.rb | 4 ++-- recipes/write_config.rb | 7 +++++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/recipes/configure.rb b/recipes/configure.rb index 13191ee..7cdaf32 100644 --- a/recipes/configure.rb +++ b/recipes/configure.rb @@ -1,6 +1,2 @@ -if node[:opsworks][:instance][:layers].include?('rails-app') - - include_recipe "opsworks_custom_env::restart_command" - include_recipe "opsworks_custom_env::write_config" - -end +include_recipe "opsworks_custom_env::restart_command" +include_recipe "opsworks_custom_env::write_config" diff --git a/recipes/restart_command.rb b/recipes/restart_command.rb index d26277d..0064a52 100644 --- a/recipes/restart_command.rb +++ b/recipes/restart_command.rb @@ -1,5 +1,4 @@ node[:deploy].each do |application, deploy| - execute "restart Rails app #{application} for custom env" do cwd deploy[:current_path] if node[:opsworks][:rails_stack][:name].eql? "apache_passenger" @@ -10,6 +9,7 @@ user deploy[:user] action :nothing - end + only_if { node[:opsworks][:instance][:layers].include?('rails-app') } + end end diff --git a/recipes/write_config.rb b/recipes/write_config.rb index 501aa5f..a198287 100644 --- a/recipes/write_config.rb +++ b/recipes/write_config.rb @@ -2,11 +2,14 @@ # See https://forums.aws.amazon.com/thread.jspa?threadID=118107 node[:deploy].each do |application, deploy| - + # rails apps only + next unless deploy[:application_type].eql?('rails') + # and only if custom_env JSON is present + next unless node[:custom_env].present? && node[:custom_env][application].present? + custom_env_template do application application deploy deploy env node[:custom_env][application] end - end From 1f42d4c82604ae4e6578720a60c2a612c13bba64 Mon Sep 17 00:00:00 2001 From: Alex Chumak Date: Mon, 25 Apr 2016 20:35:35 -0400 Subject: [PATCH 2/2] By default application's custom environment is an empty Hash --- recipes/write_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/write_config.rb b/recipes/write_config.rb index a198287..32a1aec 100644 --- a/recipes/write_config.rb +++ b/recipes/write_config.rb @@ -10,6 +10,6 @@ custom_env_template do application application deploy deploy - env node[:custom_env][application] + env node[:custom_env][application] || {} end end