From 5cbd11496690cde14a88f6559b1de27f1c36bed7 Mon Sep 17 00:00:00 2001 From: Pablo Banderas Date: Thu, 20 Aug 2015 12:43:05 +0200 Subject: [PATCH] Added custom ENV for project resource Resource now receives a new attribute env, in order to specify additional shell environment variables --- providers/project.rb | 9 ++++++--- resources/project.rb | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/providers/project.rb b/providers/project.rb index a7ca7f2..778591e 100644 --- a/providers/project.rb +++ b/providers/project.rb @@ -40,11 +40,12 @@ def make_execute(cmd) optimize = new_resource.optimize_autoloader ? optimize_flag(cmd) : '' prefer_dist = new_resource.prefer_dist ? '--prefer-dist' : '' prefer_source = new_resource.prefer_source ? '--prefer-source' : '' + environment = { 'COMPOSER_HOME' => Composer.home_dir(node) }.merge(new_resource.env) execute "#{cmd}-composer-for-project" do cwd new_resource.project_dir command "#{node['composer']['bin']} #{cmd} --no-interaction --no-ansi #{quiet} #{dev} #{optimize} #{prefer_dist} #{prefer_source}" - environment 'COMPOSER_HOME' => Composer.home_dir(node) + environment environment action :run only_if 'which composer' user new_resource.user @@ -57,11 +58,12 @@ def make_require dev = new_resource.dev ? '--dev' : '--update-no-dev' vendor = new_resource.vendor prefer_dist = new_resource.prefer_dist ? '--prefer-dist' : '' + environment = { 'COMPOSER_HOME' => Composer.home_dir(node) }.merge(new_resource.env) execute 'Install-composer-for-single-project' do cwd new_resource.project_dir command "#{node['composer']['bin']} require #{vendor} #{dev} #{prefer_dist}" - environment 'COMPOSER_HOME' => Composer.home_dir(node) + environment environment action :run only_if 'which composer' user new_resource.user @@ -72,11 +74,12 @@ def make_require def remove_vendor(cmd) vendor = new_resource.vendor + environment = { 'COMPOSER_HOME' => Composer.home_dir(node) }.merge(new_resource.env) execute "#{cmd}-composer-for-project" do cwd new_resource.project_dir command "#{node['composer']['bin']} remove #{vendor}" - environment 'COMPOSER_HOME' => Composer.home_dir(node) + environment environment action :run only_if 'which composer' end diff --git a/resources/project.rb b/resources/project.rb index 6657926..ad8aa34 100644 --- a/resources/project.rb +++ b/resources/project.rb @@ -19,6 +19,7 @@ attribute :user, :kind_of => String, :default => 'root' attribute :group, :kind_of => String, :default => 'root' attribute :umask, :kind_of => [String, Fixnum], :default => 0002 +attribute :env, :kind_of => [Hash], :default => {} def initialize(*args) super