Guest User

Untitled

a guest
Mar 11th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. def validate_credentials
  2. fail("Cannot deploy without giving user credentials") unless variables[:user] && variables[:password]
  3. end
  4.  
  5. validate_credentials
  6.  
  7. set :user, variables[:user]
  8. set :password, variables[:password]
  9.  
  10. logger.info("Deploying to #{user}")
  11.  
  12. set deploy_to: "/home/#{user}/apps/#{application}"
  13.  
  14. set :app, "#{user}.my_domain.com"
  15. set :web, "#{user}.my_domain.com"
  16. set :db, "#{user}.my_domain.com"
  17.  
  18. # and configure it to write out the database.yml
  19. # some other options:
  20. # * manually put the database.yml in the #{shared_path}/config/database.yml and just symlink
  21. # This has the big benefit of only keeping the credentials on the server itself and not having
  22. # to manage them outside of that (Assuming they're relatively static, I would do that)
  23. # * automatically put the creds in #{shared_path}/config/database.yml and symlink it in
  24. namespace :db do
  25. task :update_config, :roles => :app, :except => { :no_release => true } do
  26. yaml = <<EOF
  27. production:
  28. adapter: mysql
  29. encoding: utf8
  30. database: #{user}_app_production
  31. username: #{user}
  32. password: #{pass}
  33. EOF
  34.  
  35. # now get that file into #{release_path}/config/database.yml
  36. # leave that up to you
  37. # I'd probably write to a temp file and upload it (should make sure to delete it afterwards to
  38. # avoid leaving a credentials file in tmp)
  39. # or echo it directly into a file on that box (but I can never get multiline stuff to work
  40. # properly when doing a run("..."))
  41. end
  42.  
  43. after 'deploy:update_code', 'db:update_config'
  44. end
Add Comment
Please, Sign In to add comment