Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created January 13, 2009 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliocesar/46319 to your computer and use it in GitHub Desktop.
Save juliocesar/46319 to your computer and use it in GitHub Desktop.
# 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