Created
January 13, 2009 04:15
-
-
Save juliocesar/46319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# largely inspired by http://blog.macromates.com/2006/keychain-access-from-shell/ | |
namespace :deploy do | |
desc "Generates database.yml from info store in Keychain" | |
task :generate_database_yml do | |
account = ENV['KEYCHAIN_ACC'] | |
security_stdout = `security find-generic-password -ga #{account} 2>&1 > /dev/null` | |
if security_stdout[/could not be found/] | |
rollback | |
say "Couldn't not find database password in Keychain using the account #{account}" | |
end | |
password = security_stdout.match(/\"(.*)\"/)[1] | |
puts password | |
get File.join(current_path, *%w{config database.yml.erb}), '/tmp/database.yml.erb' | |
database_config = ERB.new(File.read('/tmp/database.yml.erb'), binding) | |
put database_config, File.join(current_path, *%w{config database.yml.erb}) | |
end | |
end | |
after "deploy:symlink", "deploy:generate_database_yml" | |
### WHERE database.yml.erb is | |
production: | |
production: | |
adapter: mysql | |
database: a_database | |
username: a_username | |
password: <%= password %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment