Guest User

Untitled

a guest
Jan 3rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. require "bundler/capistrano"
  2.  
  3. set :application, "set your application name here"
  4. set :user, "set your Locaweb's user"
  5. set :server_addr, "set the Locaweb's server ip address or your ftp address"
  6. set :deploy_to, "/home/#{user}/rails_apps/#{application}"
  7. set :rails_env, "production"
  8. set :use_sudo, false
  9.  
  10. # Git settings
  11. set :scm, :git
  12. set :repository, "set your repository location here"
  13. set :branch, "master"
  14. set :deploy_via, :copy
  15.  
  16. # Bundler settings
  17. set :bundle_without, [:development, :test, :assets]
  18.  
  19. # Uses local instead of remote server keys, good for github ssh key deploy.
  20. ssh_options[:forward_agent] = true
  21.  
  22. # Server role
  23. server server_addr, :app, :web, :db, :primary => true
  24.  
  25. # Before setup callback
  26. before "deploy:setup",
  27. "db:configure",
  28. "mailer:configure",
  29. "uploader:configure"
  30.  
  31. # After update code callback
  32. after "deploy:update_code",
  33. "db:symlink",
  34. "mailer:symlink",
  35. "uploader:symlink",
  36. "deploy:assets:precompile",
  37. "deploy:migrate",
  38. "deploy:restart",
  39. "deploy:cleanup"
  40.  
  41. namespace :deploy do
  42. task :start do ; end
  43. task :stop do ; end
  44.  
  45. desc "restarts the rails app"
  46. task :restart, :roles => :app, :except => { :no_release => true } do
  47. run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  48. end
  49.  
  50. namespace :assets do
  51. desc "Run precompile task locally and sync on remote"
  52. task :precompile, :roles => :app do
  53. `bundle exec rake assets:precompile`
  54. run "rm -rf #{shared_path}/assets"
  55. `rsync -r public/assets #{user}@#{server_addr}:#{File.join(shared_path)}`
  56. `rm -rf public/assets`
  57. run "ln -nfs #{shared_path}/assets #{latest_release}/public"
  58. end
  59. end
  60. end
  61.  
  62. namespace :db do
  63. desc "Create database yaml in shared path"
  64. task :configure do
  65. set :database_name do
  66. Capistrano::CLI.ui.ask "Enter the database name: "
  67. end
  68.  
  69. set :database_password do
  70. Capistrano::CLI.password_prompt "Database password: "
  71. end
  72.  
  73. set :database_host do
  74. Capistrano::CLI.ui.ask "Database host address: "
  75. end
  76.  
  77. db_config = <<-EOF
  78. production:
  79. adapter: mysql2
  80. encoding: utf8
  81. reconnect: false
  82. database: #{database_name}
  83. pool: 5
  84. username: #{database_name}
  85. password: #{database_password}
  86. host: #{database_host}
  87. EOF
  88.  
  89. run "mkdir -p #{shared_path}/config"
  90. put db_config, "#{shared_path}/config/database.yml"
  91. end
  92.  
  93. desc "Make symlink for database yaml"
  94. task :symlink do
  95. run "ln -nfs #{shared_path}/config/database.yml #{latest_release}/config/database.yml"
  96. end
  97. end
  98.  
  99. namespace :mailer do
  100. desc "Create mailer configuration initializer in shared path"
  101. task :configure do
  102. set :domain do
  103. Capistrano::CLI.ui.ask "Enter your domain: "
  104. end
  105.  
  106. set :username do
  107. Capistrano::CLI.ui.ask "Enter the Locaweb FTP username: "
  108. end
  109.  
  110. set :password do
  111. Capistrano::CLI.password_prompt "Enter the Locaweb FTP password: "
  112. end
  113.  
  114. mailer_config = <<-EOF
  115. ActionMailer::Base.delivery_method = :sendmail
  116. ActionMailer::Base.smtp_settings = {
  117. :address => "localhost",
  118. :port => 587,
  119. :authentication => :login,
  120. :domain => "#{domain}",
  121. :user_name => "#{username}",
  122. :password => "#{password}"
  123. }
  124. EOF
  125.  
  126. run "mkdir -p #{shared_path}/config/initializers"
  127. put mailer_config, "#{shared_path}/config/initializers/setup_mailer.rb"
  128. end
  129.  
  130. desc "Make symlink for setup_mailer initializer"
  131. task :symlink do
  132. run "ln -nfs #{shared_path}/config/initializers/setup_mailer.rb #{latest_release}/config/initializers/setup_mailer.rb"
  133. end
  134. end
  135.  
  136. namespace :uploader do
  137. desc "Create mailer configuration initializer in shared path"
  138. task :configure do
  139. run "mkdir -p #{shared_path}/public/uploads"
  140. end
  141.  
  142. desc "Make symlink for setup_mailer initializer"
  143. task :symlink do
  144. run "ln -nfs #{shared_path}/public/uploads #{latest_release}/public/"
  145. end
  146. end
Add Comment
Please, Sign In to add comment