Sample multi-environment deployment with capistrano


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. ##
  2. # Deploy recipe
  3. # Nate Miller 08.19.08
  4. #------------------------
  5.  
  6. # Git config
  7. set :scm, :git
  8. set :repository, "###"
  9. set :deploy_via, :remote_cache
  10. set :branch, "master"
  11. set :keep_releases, 4
  12.  
  13.  
  14. # Server side config
  15. set :application, "inur058"
  16. set :application_path, "/home/iudevelo/apps"
  17. set :user, "###"
  18. set :password, "#####"
  19. set :runner, "iudevelo"
  20. set :use_sudo, false
  21.  
  22. set :production_database,'iudevelon_production'
  23. set :production_dbhost, 'localhost'
  24. set :staging_database, 'iudevelo_staging'
  25. set :staging_dbhost, 'localhost'
  26.  
  27. set :dbuser, '###'
  28. set :dbpass, '###'
  29.  
  30. default_run_options[:pty] = true
  31. ssh_options[:paranoid] = false
  32.  
  33.  
  34. ## --------------------------------
  35. # Deployment environment receipes
  36. ## --------------------------------
  37.  
  38.  
  39. task :staging do
  40. role :web, "uiclients.com:2020"
  41. role :app, "uiclients.com:2020"
  42. role :db, "uiclients.com:2020", :primary => true
  43.  
  44.  
  45. set :rails_env, 'staging'
  46. set :environment_database, defer { staging_database }
  47. set :environment_dbhost, defer { staging_dbhost }
  48. set :remote_path, "#{application_path}/stage"
  49. set :deploy_to, "#{remote_path}"
  50. end
  51.  
  52. task :testing do
  53. role :web, "uiclients.com:2020"
  54. role :app, "uiclients.com:2020"
  55. role :db, "uiclients.com:2020", :primary => true
  56.  
  57. set :rails_env, 'test'
  58. set :environment_database, defer { staging_database }
  59. set :environment_dbhost, defer { staging_dbhost }
  60. set :remote_path, "#{application_path}/test"
  61. set :deploy_to, "#{remote_path}"
  62. end
  63.  
  64. task :production do
  65. role :web, "uiclients.com:2020"
  66. role :app, "uiclients.com:2020"
  67. role :db, "uiclients.com:2020", :primary => true
  68.  
  69. set :rails_env, 'production'
  70. set :environment_database, defer { production_database }
  71. set :environment_dbhost, defer { production_dbhost }
  72. set :remote_path, "#{application_path}/live"
  73. set :deploy_to, "#{remote_path}"
  74. end
  75.  
  76. ## --------------------------------
  77. # custom receipes
  78. ## --------------------------------
  79.  
  80. # Event hooks
  81. after "deploy:update_code", "db:symlink"
  82. after "db:symlink", "deploy:create_upload_symlink"
  83. after "deploy:create_upload_symlink", "deploy:cleanup"
  84.  
  85. # Deploy namespace modifications
  86. namespace :deploy do
  87. desc "Restarting Passenger through restart.txt file"
  88. task :restart, :roles => :app, :except => { :no_release => true } do
  89. run "touch #{current_path}/tmp/restart.txt"
  90. end
  91.  
  92. # Remove unused start and stop tasks
  93. [:start, :stop].each do |t|
  94. desc "#{t} task is a no-op with Passenger"
  95. task t, :roles => :app do ; end
  96. end
  97. end
  98.  
  99. namespace :db do
  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. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.