2012-12-12 36 views
0

我已經設置了capistrano來部署到分段和生產。老實說,我對卡皮斯特拉諾不是很熟悉。我通過使用標準capistrano(而不是多主機)來做到這一點。我通過一個變量如:Multistaging capistrano:db:在生產上遷移正常工作,但不在升級

cap production deploy 
cap staging deploy 

但是我的db:migrate工作不正常。

與貓分期部署: 我得到湜:

* executing "cd /data/sites/staging.domain.com/apps/d-rails/releases/20121212203353 && bundle exec rake RAILS_ENV=production db:migrate" 

,並想(只是子生產 - >分期):

* executing "cd /data/sites/staging.domain.com/apps/d-rails/releases/20121212203353 && bundle exec rake RAILS_ENV=staging db:migrate" 

我將如何設置呢?或者我應該首先解決什麼問題?

在我deploy.rb,我有:提前

+0

你使用斯特拉努的爲多級功能?以及爲什麼暫存和生產部署到相同的文件夾? – 23tux

+0

未使用多分區功能;不知道你的部署?一個去domain.com,另一個去staging.domain.com – timpone

+0

我已經給你寫了一個答案 – 23tux

回答

4

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,並根據需要調整配置。

我希望我沒有忘記任何東西;)讓我知道,如果您有任何進一步的問題

相關問題