PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/config/deploy.rb

https://bitbucket.org/meta_cms/test3
Ruby | 126 lines | 103 code | 17 blank | 6 comment | 3 complexity | 303b06131c915f7b9d695e6a4351442b MD5 | raw file
  1. require "bundler/capistrano"
  2. set :application, "test3"
  3. set :deploy_to, "/home/deploy/#{application}"
  4. set :scm, :git
  5. set :repository, "git@bitbucket.org:meta_cms/#{application}.git"
  6. set :branch, "master"
  7. set :user, 'deploy'
  8. set :use_sudo, false
  9. set :deploy_via, :remote_cache
  10. set :normalize_asset_timestamps, false
  11. default_run_options[:pty] = true
  12. after 'deploy', 'deploy:cleanup'
  13. after 'deploy:create_symlink', 'metacms:upload_assets'
  14. before 'deploy:update_code', 'metacms:compress_assets'
  15. server "78.47.60.210", :app, :web, :db, primary: true
  16. namespace :deploy do
  17. %w[start stop restart].each do |command|
  18. desc "#{command} unicorn server"
  19. task command, roles: :app, except: {no_release: true} do
  20. run "/etc/init.d/unicorn_#{application} #{command}"
  21. end
  22. end
  23. task :setup_config, roles: :app do
  24. sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
  25. sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
  26. end
  27. after "deploy:setup", "deploy:setup_config"
  28. after "deploy:setup_config", "nginx:restart"
  29. end
  30. namespace :nginx do
  31. desc "restarts nginx"
  32. task :restart, roles: :app do
  33. sudo "/etc/init.d/nginx restart"
  34. end
  35. end
  36. namespace :metacms do
  37. desc "Creates Bitbucket repro and grants permissions"
  38. task :bitbucket do
  39. run_locally "curl --request POST --user meta_cms:kumeta2012 https://api.bitbucket.org/1.0/repositories/ --data name=#{application} --data scm=git"
  40. run_locally "curl --request PUT --user meta_cms:kumeta2012 https://api.bitbucket.org/1.0/privileges/meta_cms/#{application}/innomind --data write"
  41. if run_locally("git remote") =~ /origin/
  42. run_locally "git push"
  43. else
  44. run_locally "git remote add origin ssh://git@bitbucket.org/meta_cms/#{application}.git"
  45. run_locally "git push -u origin master"
  46. end
  47. end
  48. after "deploy:setup", "metacms:bitbucket"
  49. desc "Compress assets in a local file"
  50. task :compress_assets do
  51. run_locally("rm -rf public/assets/*")
  52. run_locally("bundle exec rake assets:precompile")
  53. run_locally("touch assets.tgz && rm assets.tgz")
  54. run_locally("tar zcvf assets.tgz public/assets/")
  55. run_locally("mv assets.tgz public/assets/")
  56. end
  57. desc "Upload assets"
  58. task :upload_assets do
  59. upload("public/assets/assets.tgz", release_path + '/assets.tgz')
  60. run "cd #{release_path}; tar zxf assets.tgz; rm assets.tgz"
  61. end
  62. end
  63. namespace :db do
  64. desc "Create database yaml in shared path"
  65. task :default do
  66. db_config = ERB.new <<-EOF
  67. # SQLite version 3.x
  68. # gem install sqlite3-ruby (not necessary on OS X Leopard)
  69. development:
  70. adapter: sqlite3
  71. database: #{shared_path}/db/development.sqlite3
  72. pool: 5
  73. timeout: 5000
  74. # Warning: The database defined as "test" will be erased and
  75. # re-generated from your development database when you run "rake".
  76. # Do not set this db to the same as development or production.
  77. test:
  78. adapter: sqlite3
  79. database: #{shared_path}/db/test.sqlite3
  80. pool: 5
  81. timeout: 5000
  82. production:
  83. adapter: postgresql
  84. database: #{application}_production
  85. username: innomind_production
  86. password: Aeghaeke5
  87. host: localhost
  88. encoding: UTF8
  89. EOF
  90. run "mkdir -p #{shared_path}/db"
  91. run "mkdir -p #{shared_path}/config"
  92. put db_config.result, "#{shared_path}/config/database.yml"
  93. end
  94. before "deploy:setup", "db"
  95. desc "creates the database"
  96. task :create, roles: :db do
  97. run_rake 'db:create'
  98. end
  99. # after "deploy:setup", "db:create"
  100. desc "Make symlink for database yaml"
  101. task :symlink do
  102. run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  103. end
  104. after "deploy:update_code", "db:symlink"
  105. end
  106. def run_rake(task, options={}, &block)
  107. command = "cd #{latest_release} && bundle exec rake #{task} RAILS_ENV=#{rails_env}"
  108. run(command, options, &block)
  109. end