Advertisement
Guest User

Untitled

a guest
Jul 11th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. # config valid only for current version of Capistrano
  2. lock '3.4.0'
  3.  
  4. set :application, 'domochat'
  5. set :repo_url, 'git@github.com:domochat/domochat.git'
  6. set :ruby_version, '2.2.3'
  7.  
  8. # Default branch is :master
  9. # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
  10.  
  11. # Default deploy_to directory is /var/www/my_app_name
  12. set :deploy_to, "/var/www/#{fetch(:application)}"
  13. set :keep_releases, 5
  14.  
  15. set :rails_env, -> { fetch(:stage) }
  16. set :scm, :git # Default value for :scm is :git
  17. set :format, :pretty # Default value for :format is :pretty
  18. set :log_level, :info # Default value for :log_level is :debug
  19.  
  20. set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
  21. set :linked_files, %w{config/application.yml config/database.yml config/secrets.yml}
  22.  
  23. # rbenv config
  24. set :rbenv_type, :user # or :system, depends on your rbenv setup
  25. set :rbenv_ruby, -> { fetch(:ruby_version) }
  26. set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
  27. set :rbenv_map_bins, %w{rake gem bundle ruby rails}
  28. set :rbenv_roles, :all # default value
  29.  
  30.  
  31.  
  32. namespace :deploy do
  33. desc "Setup server"
  34. task :setup do
  35. puts '--------------------------> Initial server config'
  36. invoke 'admin:friendly_github'
  37. invoke 'admin:check_write_permissions'
  38. invoke 'admin:setup_configs'
  39. end
  40.  
  41.  
  42.  
  43. after :restart, :clear_cache do
  44. on roles(:web), in: :groups, limit: 3, wait: 10 do
  45. # Here we can do anything such as:
  46. # within release_path do
  47. # execute :rake, 'cache:clear'
  48. # end
  49. end
  50. end
  51.  
  52. end
  53.  
  54.  
  55. ######### Administration part
  56.  
  57.  
  58. namespace :admin do
  59. desc "Report Uptimes"
  60. task :uptime do
  61. on roles(:all) do |host|
  62. info "Host #{host} (#{host.roles.to_a.join(', ')}):\t#{capture(:uptime)}"
  63. end
  64. end
  65.  
  66. desc "Add github to ~/.ssh/known_hosts"
  67. task :friendly_github do
  68. on roles(:all) do |host|
  69. execute 'ssh-keyscan', '-t rsa', '-H github.com >> ~/.ssh/known_hosts'
  70. end
  71. end
  72.  
  73. desc "Check that we can access everything"
  74. task :check_write_permissions do
  75. on roles(:all) do |host|
  76. if test("[ -w #{fetch(:deploy_to)} ]")
  77. info "#{fetch(:deploy_to)} is writable on #{host}"
  78. else
  79. error "#{fetch(:deploy_to)} is not writable on #{host}"
  80. end
  81. end
  82. end
  83.  
  84. desc "Creates initial templates for server-side configs."
  85. task :setup_configs do
  86. on roles(:app) do |host|
  87. unless test "[ -d #{ shared_path }/config ]"
  88. execute 'mkdir', "-p #{ shared_path }/config"
  89. end
  90.  
  91. unless test "[ -f #{ shared_path }/config/database.yml ]"
  92. puts '--------------> Create config/database.yml'
  93. set :db_driver, ask('Enter the database driver', 'postgresql')
  94. set :db_database, ask('Enter database', "#{fetch(:application)}_#{fetch(:stage)}")
  95. set :db_user, ask('Enter the database user:', 'db_user')
  96. set :db_password, ask('Enter the database password:', nil, echo: false)
  97. set :db_host, ask('Enter the database host:', 'localhost')
  98.  
  99. if fetch(:db_driver) == 'postgis'
  100.  
  101. database_yml = <<-EOF
  102. #{fetch(:stage)}:
  103. adapter: #{fetch(:db_driver)}
  104. encoding: unicode
  105. pool: 5
  106. database: #{fetch(:db_database)}
  107. host: #{fetch(:db_host)}
  108. username: #{fetch(:db_user)}
  109. password: #{fetch(:db_password)}
  110. schema_search_path: public, postgis
  111. EOF
  112.  
  113. else
  114.  
  115. database_yml = <<-EOF
  116. #{fetch(:stage)}:
  117. adapter: #{fetch(:db_driver)}
  118. encoding: unicode
  119. pool: 5
  120. database: #{fetch(:db_database)}
  121. host: #{fetch(:db_host)}
  122. username: #{fetch(:db_user)}
  123. password: #{fetch(:db_password)}
  124. EOF
  125.  
  126. end
  127.  
  128.  
  129.  
  130. upload! StringIO.new(database_yml), "#{shared_path}/config/database.yml"
  131. end
  132.  
  133. unless test "[ -f #{ shared_path }/config/secrets.yml ]"
  134. puts '--------------> Upload config/secrets.yml'
  135.  
  136. secrets_yml = <<-EOF
  137. #{fetch(:stage)}:
  138. secret_key_base: #{SecureRandom.hex(64)}
  139. EOF
  140.  
  141.  
  142. upload! StringIO.new(secrets_yml), "#{ shared_path }/config/secrets.yml"
  143. end
  144.  
  145. unless test "[ -f #{ shared_path }/config/application.yml ]"
  146. puts '--------------> Upload config/application.yml'
  147. upload! 'config/application.yml', "#{ shared_path }/config/application.yml"
  148. end
  149.  
  150. puts '---------------------------------------------------'
  151. puts "Now edit the config files in #{shared_path}/config."
  152. end
  153. end
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement