-
Notifications
You must be signed in to change notification settings - Fork 21.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not store production information in .yml files #13463
Conversation
Instead, read information from environment variables.
This approach is much better than the .gitignore one, which requires extra work on setting up the machine for development, and also works nicely with most deploy platforms. |
💯 |
@josevalim what do you think about using a namespace for the environment variables. Something like RAILS_DATABASE_URL. Since environment variables are not Rails specific in my opinion would be better if we add the namespace. |
@rafaelfranca @josevalim or even prefix using the app's name so that it works per-app. |
@rafaelfranca that sounds like a good idea. I just want to point out that Active Record already checks for DATABASE_URL in a couple places. I know @hone did some work during RailsConf to extract that out but I can't remember if it was merged. @hone? |
I love the move toward using The |
I don't mind switching to this default, but would not be so affirmative in the comment. For once, the mere default suggests the convention treats production differently for a reason, and second I have seen several client projects where the production stuff is in the repo without any problem. Whether production config in the repo is good or bad depends on the project. |
@fxn Good point. Although I would say those companies are probably very comfortable with what they are doing and they probably know when to abandon rails golden path. :) |
+1 From the perspective of failing fast, |
-1 to using |
@zmoazeni ah, yes, that won't work |
Amazing 👍 @rafaelfranca internally rails is still relying on the Setting a convention for environment variables used by Rails to start with |
This commit also cleans up the rake tasks that were checking for DATABASE_URL in different places. In fact, it would be nice to deprecate DATABASE_URL usage in the long term, considering the direction we are moving of allowing those in .yml files.
I've added the |
Do not store production information in .yml files
Looks like travis failed railties tests after this, mind taking a look bro? (sorry I won't be able =/) |
Prior to rails#13463 when `DATABASE_URL` was set, Rails automagically used that value instead of the database.yml. There are tests in dbs_test that expect this to still be true. After that PR, `RAILS_DATABASE_URL` is expected to be read into the YAML file via ERB, this PR fixes that behavior. Note: this does not entirely fix the tests. It seems that `ActiveRecord::Tasks::DatabaseTasks.current_config` does not process the url string correctly (convert it into a hash), and ` ActiveRecord::Tasks::DatabaseTasks.structure_load(current_config, filename)` as well as other methods in `DatabaseTasks` expect a hash. It seems like we should involve the resolver somewhere in this process to correctly convert the database url, I do not know the best place for that /cc @josevalim
Current conversations about this topic, including wether to add secrets.ymlto source control by default: * rails/rails#13388 * rails/rails#13463 I expect to support something more closely to the [figaro](https://github.com/laserlemon/figaro) gem in the future. For now I wait until Rails 4.1 is released.
I'm still looking into behavior of Active Record concerning environment variables. I would like to address consistency of behavior across multiple ways AR can be used, and re-visit the bike shed that is naming environment variables. tl;dr I'm working on making behavior of Active Record consistent across all scenarios with regard to Consistency of EnvironmentsHere are all the ways that AR initiates a connection today:
We should make all of these behave exactly the same way, which if you dig into AR is non-trivial. I'm working to see if I can put all of this logic in one place for consistency, but as I mentioned, it's a non-trivial task. Currently AR can be configured via the environment variable
ImplementationI'm currently working on getting the above to work and be consistent with all environments, the last barrier I have to overcome is the Rake tasks. I expect this last bit to take 80% of the effort. This also brings me to my second topic: env var naming. Env Var NamingAs I mentioned above, AR already has built in support for I was originally 👍 on name-spacing the environment variables with
One of the initial reasons for namespacing was to prevent conflicts between different languages running on the same box. I think this is the minority case, a more likely use case would be multiple Rails applications on the same box. Using the Deployment seems to be leaning towards using containers (through LXC, docker, or similar) which allows you to set a clean By keeping this value standard, you could have your container generation code create a I'm out to lunch on namespacing of I'm interested in talking about this point more, right now I would recommend switching back from |
Should not the the DATABASE_URL the winner in this case too?
When I proposed the namespacing I was more concerned with the secret key. Since the DATABASE_URL is already being used and it is a pseudo-standard we can change it back. |
@rafaelfranca I'm okay with that behavior as well. I like the ability to change this value if needed. If we're saying that
It would be confusing to me, if I modified the
However if a user has
I will submit a PR to change the default env var values to |
Agree the second case is confusing. Supposing that a user for some reason want to use a different database in production that the one configured in the Lets go with your proposed behavior |
See rails#13463 (comment) for full conversation.
Here's my somewhat ambitious proposal actually implemented: #13582 If we want to change any of the merge behavior it is all isolated to one place, so it should be way easier now than before. |
* don't write `config/database.yml` in Rails 4.1, See rails/rails#13463 (comment). * setup env var SECRET_KEY_BASE for Rails 4.1's `config/secrets.yml`
* don't write `config/database.yml` in Rails 4.1, See rails/rails#13463 (comment). * setup env var SECRET_KEY_BASE for Rails 4.1's `config/secrets.yml`
If the purpose of removing database configuration information is purely for security and/or compliance reasons then encrypting the passwords and secrets in config files is sufficient. We encrypted all production passwords and secrets.yml for PCI compliance using the SymmetricEncryption gem |
Rails has changed how DB connection configs are loaded and merged together -- DATABASE_URL Env Vars are now merged with database.yml settings (see: rails/rails#13463 (comment)). We now fetch the current config from `ActiveRecord::Base.configurations`, which will ensure the settings have been properly loaded.
Current conversations about this topic, including wether to add secrets.ymlto source control by default: * rails/rails#13388 * rails/rails#13463 I expect to support something more closely to the [figaro](https://github.com/laserlemon/figaro) gem in the future. For now I wait until Rails 4.1 is released.
Instead, read information from environment variables.