task :production do
set :deploy_to, "/data/sites/domain.com/apps/#{application}"
end
task :staging do
set :deploy_to, "/data/sites/staging.domain.com/apps/#{application}"
after 'deploy:update_code' do
run "cd #{release_path}; RAILS_ENV=staging bundle exec rake assets:precompile --trace"
end
end
THX我認爲這將是更容易使用Capistrano酒店的爲多級功能。這裏是我的設置生產和分期部署:
配置/ deploy.rb
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
set :application, "yourappname"
set :repository, "[email protected]:yourrepo.git"
set :stages, %w(production staging)
set :default_stage, "staging" # running "cap deploy" deploys to staging, "cap production deploy" deploys to production
set :user, "deploy" # the ssh user which does the deployment on the server
set :use_sudo, false
set :scm, :git
set :default_environment, {
'PATH' => "/usr/local/rbenv/shims:/usr/local/rbenv/bin:/usr/local/rbenv/versions/1.9.3-p327/bin:$PATH"
}
after "deploy:update_code", "deploy:migrate"
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
,如果你要加入一些額外的pathes進行部署(需要的set :default_environment
因爲,正常.bashrc
或.bash_profile
不包括當Capistrano的登錄到服務器)
配置/部署/ production.rb
set :rails_env, "production"
set :deploy_to, "/var/www/your_production_folder"
role :web, "example.com" # Your HTTP server, Apache/etc
role :app, "example.com" # This may be the same as your `Web` server
role :db, "example.com", :primary => true # This is where Rails migrations will run
配置/部署/ staging.rb
set :rails_env, "staging"
set :deploy_to, "/var/www/your_staging_folder"
role :web, "example.com" # Your HTTP server, Apache/etc
role :app, "example.com" # This may be the same as your `Web` server
role :db, "example.com", :primary => true # This is where Rails migrations will run
一定要包括在你的虛擬主機配置的RailsEnv變量。如果您使用的是Apache,這應該是這樣的:
<VirtualHost *:80>
ServerName staging.example.com
ServerAlias www.staging.example.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/your_staging_folder/current/public
<Directory /var/www/your_staging_folder/current/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
#AuthName "Staging Server"
#AuthType Basic
#AuthUserFile /var/staging.htpasswd
#require valid-user
</Directory>
RailsEnv staging
</VirtualHost>
未註釋AuthName
,如果你想用密碼保護你的暫存環境AuthType
使用。完成這些配置後,使用cap deploy:setup
測試您的部署,這將設置文件夾結構。 A cap deploy:cold
會將應用程序的所有文件複製到該目錄。 A cap deploy:migrate
遷移你的分貝。但你也可以只做一個cap deploy
。
另一件事是,你必須在rails應用程序中設置一個登臺環境。爲此,請將config/environments/production.rb
(或development.rb,您更喜歡)複製到staging.rb
,並根據需要調整配置。
我希望我沒有忘記任何東西;)讓我知道,如果您有任何進一步的問題
你使用斯特拉努的爲多級功能?以及爲什麼暫存和生產部署到相同的文件夾? – 23tux
未使用多分區功能;不知道你的部署?一個去domain.com,另一個去staging.domain.com – timpone
我已經給你寫了一個答案 – 23tux