Permalink
Browse files

feat: Implemented configurable RAILS_ENV

Before this change, RAILS_ENV was hardcoded to `production`. This was not a best solution, since
many different environments may be introduced to AWS stack (`staging`, `beta` etc.). To solve this,
the `app['framework']['rails_env']` configuration parameter is introduced, which serves exactly for
that purpose.

Resolves #34
  • Loading branch information...
ajgon committed Aug 30, 2016
1 parent 58f840c commit 2567b715d60c074ef05947941e12ed976e3fe258
View
@@ -143,6 +143,10 @@ Currently only `Rails` is supported.
* **Default:** `true`
* `app['framework']['assets_precompilation_command']`
* A command which will be invoked to precompile assets.
* `app['framework']['rails_env']`
* **Default:** `production`
* `rails` framework only. Sets the `RAILS_ENV` variable for all the ruby-related
actions in the project (server, worker, etc.)
### appserver
View
@@ -84,6 +84,7 @@
'&& /usr/local/bin/bundle exec rake db:migrate || /usr/local/bin/bundle exec rake db:setup'
default['defaults']['framework']['assets_precompile'] = true
default['defaults']['framework']['assets_precompilation_command'] = '/usr/local/bin/bundle exec rake assets:precompile'
default['defaults']['framework']['rails_env'] = 'production'
# worker
## common
@@ -5,12 +5,13 @@ class Rails < Drivers::Framework::Base
adapter :rails
allowed_engines :rails
output filter: [
:migrate, :migration_command, :deploy_environment, :assets_precompile, :assets_precompilation_command
:migrate, :migration_command, :deploy_environment, :assets_precompile, :assets_precompilation_command,
:rails_env
]
packages debian: 'zlib1g-dev', rhel: 'zlib-devel'
def raw_out
super.merge(deploy_environment: { 'RAILS_ENV' => 'production' })
super.merge(deploy_environment: { 'RAILS_ENV' => super[:rails_env] })
end
def deploy_before_restart(context)
View
@@ -43,6 +43,7 @@ def node(override = {})
},
framework: {
adapter: 'rails',
rails_env: 'staging',
migrate: false
},
worker: {
@@ -14,9 +14,10 @@
expect(described_class.new(aws_opsworks_app, node).out).to eq(
assets_precompile: true,
assets_precompilation_command: 'bundle exec rake assets:precompile',
deploy_environment: { 'RAILS_ENV' => 'production' },
deploy_environment: { 'RAILS_ENV' => 'staging' },
migration_command: 'rake db:migrate',
migrate: false
migrate: false,
rails_env: 'staging'
)
end
end
@@ -191,7 +191,7 @@
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="production" bundle exec sidekiq ' \
'ENV_VAR2="some data" RAILS_ENV="staging" bundle exec sidekiq ' \
'-C /srv/www/dummy_project/shared/config/sidekiq_1.yml ' \
'-P /srv/www/dummy_project/shared/pids/sidekiq_dummy_project-1.pid ' \
'-r /srv/www/dummy_project/current/lorem_ipsum.rb 2>&1 ' \
@@ -214,7 +214,7 @@
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="production" bundle exec sidekiq ' \
'ENV_VAR2="some data" RAILS_ENV="staging" bundle exec sidekiq ' \
'-C /srv/www/dummy_project/shared/config/sidekiq_2.yml ' \
'-P /srv/www/dummy_project/shared/pids/sidekiq_dummy_project-2.pid ' \
'-r /srv/www/dummy_project/current/lorem_ipsum.rb 2>&1 ' \
@@ -245,7 +245,7 @@
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="production" bundle exec sidekiq ' \
'ENV_VAR2="some data" RAILS_ENV="staging" bundle exec sidekiq ' \
'-C /srv/www/dummy_project/shared/config/sidekiq_1.yml ' \
'-P /srv/www/dummy_project/shared/pids/sidekiq_dummy_project-1.pid ' \
'-r /srv/www/dummy_project/current/lorem_ipsum.rb 2>&1 ' \
@@ -268,7 +268,7 @@
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="production" bundle exec sidekiq ' \
'ENV_VAR2="some data" RAILS_ENV="staging" bundle exec sidekiq ' \
'-C /srv/www/dummy_project/shared/config/sidekiq_2.yml ' \
'-P /srv/www/dummy_project/shared/pids/sidekiq_dummy_project-2.pid ' \
'-r /srv/www/dummy_project/current/lorem_ipsum.rb 2>&1 ' \
@@ -43,7 +43,7 @@
revision: 'master',
scm_provider: Chef::Provider::Git,
enable_submodules: false,
environment: aws_opsworks_app['environment'].merge('RAILS_ENV' => 'production'),
environment: aws_opsworks_app['environment'].merge('RAILS_ENV' => 'staging'),
ssh_wrapper: '/tmp/ssh-git-wrapper.sh',
symlinks: {
'system' => 'public/system',

0 comments on commit 2567b71

Please sign in to comment.