In the `config/environments` directory!
config
└── environments
├── development.rb
├── production.rb
└── test.rb
config
└── environments
├── development.rb # <- ends with .rb, so it's ruby CODE
├── production.rb
└── test.rb
ALL THAT IS CODE SHALTH BE TESTED
Runtime code optimisations:
Development: optimise for code reloading and developer experience
Test: a sandbox environment so tests can safely run
Production: optimise for performance
Confusing RAILS environments with DEPLOYMENT environments.
export RAILS_ENV=development
export RAILS_ENV=test
export RAILS_ENV=production
- Using `development` locally
- Using `test` in CI
- Using `production` when deploying to the production "environment"
You have to be able to run ALL of them BEFORE deploying.
1. You have to be able to run with any RAILS_ENV on your local machine
2. You have to be able to run with any RAILS_ENV on any remote server
3. Don't hardcode deployment specific values... anywhere
Creating more rails environments.
You only need the 3.
No need for a `staging.rb` or a `uat.rb`. Use `RAILS_ENV=production`
You end up not testing the content of `production.rb` until you actually deploy to production.
BUGS! BUGS! BUGS!
Create a `staging.rb` file and have it contan:
require_relative './production'
...and nothing else.
That's just `RAILS_ENV=production` with extra steps.
Plus you need to document the differences somehwere...
Using RAILS_ENV as a global feature flag:
if Rails.env.production?
# ... do one thing
elsif Rails.env.development?
# ... do another
end
You end up not testing the content of `production.rb` until you actually deploy to production.
BUGS! BUGS! BUGS!
Global feature flags are bad practice in general, you should have feature flags per feature.
You develop code for Rails internals
Development tools
Test runners
Performance optimisations
Improve your Rails codebase by:
- Differentiate between RAILS environments and DEPLOYMENT environments
- Removing deployment specific hardcodings
- Remove extra rails environments
- Use feature flags per feature
- Run with all RAILS_ENV locally before merging code