Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
fix(appserver): passing USER and HOME environment variables to appser…
Browse files Browse the repository at this point in the history
…ver process

Fixes #85
  • Loading branch information
ajgon committed Jun 18, 2017
1 parent 19bf034 commit 43210bc
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 40 deletions.
1 change: 1 addition & 0 deletions libraries/drivers_appserver_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def env_config(options = { source_file: nil, destination_file: nil })
def environment
framework = Drivers::Framework::Factory.build(context, app, options)
app['environment'].merge(framework.out[:deploy_environment] || {})
.merge('HOME' => node['deployer']['home'], 'USER' => node['deployer']['user'])
end
end
end
Expand Down
1 change: 1 addition & 0 deletions libraries/drivers_worker_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def process_count
def environment
framework = Drivers::Framework::Factory.build(context, app, options)
app['environment'].merge(framework.out[:deploy_environment] || {})
.merge('HOME' => node['deployer']['home'], 'USER' => node['deployer']['user'])
end
end
end
Expand Down
84 changes: 56 additions & 28 deletions spec/unit/recipes/configure_spec.rb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions spec/unit/recipes/shutdown_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
expect(chef_run).to(
run_execute(
'/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" bundle exec sidekiqctl stop ' \
'/srv/www/dummy_project/shared/pids/sidekiq_dummy_project-1.pid 8\''
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" ' \
'bundle exec sidekiqctl stop /srv/www/dummy_project/shared/pids/sidekiq_dummy_project-1.pid 8\''
)
)
expect(chef_run).to(
run_execute(
'/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" bundle exec sidekiqctl stop ' \
'/srv/www/dummy_project/shared/pids/sidekiq_dummy_project-2.pid 8\''
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" '\
'bundle exec sidekiqctl stop /srv/www/dummy_project/shared/pids/sidekiq_dummy_project-2.pid 8\''
)
)
end
Expand Down
8 changes: 6 additions & 2 deletions test/integration/all_options/serverspec/all_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
describe file('/srv/www/dummy_project/shared/scripts/puma.service') do
its(:content) { should include 'ENV[\'ENV_VAR1\'] = "test"' }
its(:content) { should include 'ENV[\'RAILS_ENV\'] = "staging"' }
its(:content) { should include 'ENV[\'HOME\'] = "/home/deploy"' }
its(:content) { should include 'ENV[\'USER\'] = "deploy"' }
its(:content) { should include 'PID_PATH="/srv/www/dummy_project/shared/pids/puma.pid"' }
its(:content) { should include 'def puma_running?' }
end
Expand Down Expand Up @@ -125,12 +127,14 @@
its(:content) { should include 'group sidekiq_dummy_project_group' }
its(:content) { should include 'check process sidekiq_dummy_project-1' }
its(:content) do
should include 'RAILS_ENV="staging" bundle exec sidekiq -C /srv/www/dummy_project/shared/config/sidekiq_1.yml'
should include 'RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" ' \
'bundle exec sidekiq -C /srv/www/dummy_project/shared/config/sidekiq_1.yml'
end
its(:content) { should include 'logger -t sidekiq-dummy_project-1' }
its(:content) { should include 'check process sidekiq_dummy_project-2' }
its(:content) do
should include 'RAILS_ENV="staging" bundle exec sidekiq -C /srv/www/dummy_project/shared/config/sidekiq_2.yml'
should include 'RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" ' \
'bundle exec sidekiq -C /srv/www/dummy_project/shared/config/sidekiq_2.yml'
end
its(:content) { should include 'logger -t sidekiq-dummy_project-2' }
end
Expand Down
2 changes: 2 additions & 0 deletions test/integration/default/serverspec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
describe file('/srv/www/dummy_project/shared/scripts/puma.service') do
its(:content) { should include 'ENV[\'ENV_VAR1\'] = "test"' }
its(:content) { should include 'ENV[\'RAILS_ENV\'] = "production"' }
its(:content) { should include 'ENV[\'HOME\'] = "/home/deploy"' }
its(:content) { should include 'ENV[\'USER\'] = "deploy"' }
its(:content) { should include 'PID_PATH="/srv/www/dummy_project/shared/pids/puma.pid"' }
its(:content) { should include 'def puma_running?' }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
describe file('/srv/www/dummy_project/shared/scripts/thin.service') do
its(:content) { should include 'ENV[\'ENV_VAR1\'] = "test"' }
its(:content) { should include 'ENV[\'RACK_ENV\'] = "production"' }
its(:content) { should include 'ENV[\'HOME\'] = "/home/deploy"' }
its(:content) { should include 'ENV[\'USER\'] = "deploy"' }
its(:content) { should include 'PID_PATH="/srv/www/dummy_project/shared/pids/thin.pid"' }
its(:content) { should include 'def thin_running?' }
end
Expand All @@ -70,15 +72,15 @@
its(:content) { should include 'check process delayed_job_dummy_project-1' }
its(:content) do
should include 'RACK_ENV="production" DATABASE_URL="sqlite:///srv/www/dummy_project/shared/db/data.sqlite3" ' \
'bin/delayed_job start --pid-dir=/srv/www/dummy_project/shared/pids/ -i 0 ' \
'--queues=default,mailers'
'HOME="/home/deploy" USER="deploy" bin/delayed_job start ' \
'--pid-dir=/srv/www/dummy_project/shared/pids/ -i 0 --queues=default,mailers'
end
its(:content) { should include 'logger -t delayed_job-dummy_project-1' }
its(:content) { should include 'check process delayed_job_dummy_project-2' }
its(:content) do
should include 'RACK_ENV="production" DATABASE_URL="sqlite:///srv/www/dummy_project/shared/db/data.sqlite3" ' \
'bin/delayed_job start --pid-dir=/srv/www/dummy_project/shared/pids/ -i 1 ' \
'--queues=default,mailers'
'HOME="/home/deploy" USER="deploy" bin/delayed_job start ' \
'--pid-dir=/srv/www/dummy_project/shared/pids/ -i 1 --queues=default,mailers'
end
its(:content) { should include 'logger -t delayed_job-dummy_project-2' }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
describe file('/srv/www/dummy_project/shared/scripts/unicorn.service') do
its(:content) { should include 'ENV[\'ENV_VAR1\'] = "test"' }
its(:content) { should include 'ENV[\'HANAMI_ENV\'] = "production"' }
its(:content) { should include 'ENV[\'HOME\'] = "/home/deploy"' }
its(:content) { should include 'ENV[\'USER\'] = "deploy"' }
its(:content) { should include 'PID_PATH="/srv/www/dummy_project/shared/pids/unicorn.pid"' }
its(:content) { should include 'def unicorn_running?' }
end
Expand All @@ -107,14 +109,16 @@
its(:content) { should include 'check process resque_dummy_project-1' }
its(:content) do
should include 'HANAMI_ENV="production" DATABASE_URL="sqlite:///srv/www/dummy_project/shared/db/data.sqlite3"' \
' QUEUE=default,mailers VERBOSE=1 PIDFILE=/srv/www/dummy_project/shared/pids/' \
' HOME="/home/deploy" USER="deploy" QUEUE=default,mailers VERBOSE=1 ' \
'PIDFILE=/srv/www/dummy_project/shared/pids/' \
'resque_dummy_project-1.pid COUNT=3 bundle exec rake environment resque:work'
end
its(:content) { should include 'logger -t resque-dummy_project-1' }
its(:content) { should include 'check process resque_dummy_project-2' }
its(:content) do
should include 'HANAMI_ENV="production" DATABASE_URL="sqlite:///srv/www/dummy_project/shared/db/data.sqlite3"' \
' QUEUE=default,mailers VERBOSE=1 PIDFILE=/srv/www/dummy_project/shared/pids/' \
' HOME="/home/deploy" USER="deploy" QUEUE=default,mailers VERBOSE=1 ' \
'PIDFILE=/srv/www/dummy_project/shared/pids/' \
'resque_dummy_project-2.pid COUNT=3 bundle exec rake environment resque:work'
end
its(:content) { should include 'logger -t resque-dummy_project-2' }
Expand Down

0 comments on commit 43210bc

Please sign in to comment.