I am deploying the production environment of my ruby on rails application with the capistrano gem onto a virtual private server. I run the following command to deploy:
bundle exec cap production deploy
All seems to be working well unless I try to check what environment my current production release is operating in.
One way I use to check this is to run:
rails console
Rails.env
The answer I receive is "development" which is quite frightening.
During another test: when I run the following in my current release:
rails db
I get an error that states that mydatabase_development is not created.
My application seems to be running well but I do not know if this will cause major problems moving forward. First of all: Is there a way to determine if I my live copy is actually running in development? Secondly: Given that I have a problem, how do I configure capistrano to deploy a production environment?
Keep in mind that rails console
engages in the current environment as dictated by RAILS_ENV
or RACK_ENV
in your environment. If you don't set up this explicitly on your server then it will probably default to development
.
One way to fix this is to force it in your .bash_profile
or whatever shell profile you're using. For example:
export RAILS_ENV=production
That should make it available and when you engage your Rails shell it'll kick in properly.
As a note, you shouldn't even be able to start in development mode on your production server since there shouldn't be an entry with that name in config/database.yml
. A best practice is to store config/database.yml
only on the production server and move it over during your Capistrano deploy.
Add this to your config/deploy.rb
:
set :linked_files, %w[
config/database.yml
]
Then you create a production only config in shared/config/database.yml
that will be linked into place when you deploy. Be sure to exclude config/database.yml
from your version control system so it doesn't get deployed.
The reason your site is probably okay is because a launcher like Passenger automatically sets RACK_ENV
to production
unless otherwise configured. This does not impact your shell, though, which defaults to development
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With