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

Commit

Permalink
feat: Implemented configurable RAILS_ENV
Browse files Browse the repository at this point in the history
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
Igor Rzegocki committed Aug 30, 2016
1 parent 58f840c commit 2567b71
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions attributes/default.rb
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions libraries/drivers_framework_rails.rb
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/node.rb
Expand Up @@ -43,6 +43,7 @@ def node(override = {})
},
framework: {
adapter: 'rails',
rails_env: 'staging',
migrate: false
},
worker: {
Expand Down
5 changes: 3 additions & 2 deletions spec/unit/libraries/drivers_framework_rails_spec.rb
Expand Up @@ -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
8 changes: 4 additions & 4 deletions spec/unit/recipes/configure_spec.rb
Expand Up @@ -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 ' \
Expand All @@ -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 ' \
Expand Down Expand Up @@ -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 ' \
Expand All @@ -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 ' \
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/recipes/deploy_spec.rb
Expand Up @@ -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',
Expand Down

0 comments on commit 2567b71

Please sign in to comment.