PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/config/deploy.rb

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