Marco Sero
Marco Sero

Reputation: 460

Hide db's password with multiple git repository in Rails application

I have a git repository both on GitHub and on my private Amazon instance and with a unique commit I update both.

There is a way to commit the file database.yml only to my private repository and not on GitHub?

If could help, I'm using Capistrano for deployment.

Upvotes: 3

Views: 475

Answers (2)

Daniel Hernández
Daniel Hernández

Reputation: 1317

Another solution is provided here. If you previously define environment variables you can use them in the databases.yml file.

username: <%= ENV['POSTGRES_USERNAME'] %>
password: <%= ENV['POSTGRES_PASSWORD'] %>

Upvotes: 0

Marco Sero
Marco Sero

Reputation: 460

In the past days I found no answer to this question, but then I solved my problem, so I'll say what I've done to have things working.

Since I don't have to modify the file database.yml, I solved my problem manually copying it to my Amazon instance and adding it to .gitignore.

Then, I added a task in deploy.rb to link database.yml to the current directory of deployment

# copy db config
after "deploy:update_code", :copy_db_config
desc "copy db config file"
task :copy_db_config do
  run "ln -s ~/path/where/I/copied/database.yml #{release_path}/config/database.yml"
end

Hope this help.

Upvotes: 3

Related Questions