当我执行cap deploy
部署我的 rails 应用程序时,会显示以下输出:
* executing "ls -x /var/www/releases"
servers: ["example.com"]
[example.com] executing command
command finished in 84ms
* 2013-06-30 01:17:49 executing `deploy'
* 2013-06-30 01:17:49 executing `deploy:update'
** transaction: start
* 2013-06-30 01:17:49 executing `deploy:update_code'
executing locally: "git ls-remote git@some-random-git-server.org:example.com.git HEAD"
command finished in 1187ms
* executing "git clone -q --depth 1 git@some-random-git-server.org:example.com.git /var/www/releases/20130629231751 && cd /var/www/releases/20130629231751 && git checkout -q -b deploy 8d4f9874c7c3c29529baa4a6cf7e9d8d409780bc && (echo 8d4f9874c7c3c29529baa4a6cf7e9d8d409780bc > /var/www/releases/20130629231751/REVISION)"
servers: ["example.com"]
[example.com] executing command
command finished in 10098ms
* 2013-06-30 01:18:01 executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* 2013-06-30 01:18:01 executing `deploy:assets:symlink'
* executing "rm -rf /var/www/releases/20130629230631/public/assets && mkdir -p /var/www/releases/20130629230631/public && mkdir -p /var/www/shared/assets && ln -s /var/www/shared/assets /var/www/releases/20130629230631/public/assets"
servers: ["example.com"]
[example.com] executing command
command finished in 71ms
* 2013-06-30 01:18:01 executing `bundle:install'
* executing "cd /var/www/releases/20130629230631 && bundle install --gemfile /var/www/releases/20130629230631/Gemfile --path /var/www/shared/bundle --deployment --quiet --without development test"
servers: ["example.com"]
[example.com] executing command
command finished in 631ms
* executing "chmod -R -- g+w /var/www/releases/20130629230631 && rm -rf -- /var/www/releases/20130629230631/public/system && mkdir -p -- /var/www/releases/20130629230631/public/ && ln -s -- /var/www/shared/system /var/www/releases/20130629230631/public/system && rm -rf -- /var/www/releases/20130629230631/log && ln -s -- /var/www/shared/log /var/www/releases/20130629230631/log && rm -rf -- /var/www/releases/20130629230631/tmp/pids && mkdir -p -- /var/www/releases/20130629230631/tmp/ && ln -s -- /var/www/shared/pids /var/www/releases/20130629230631/tmp/pids"
... more stuff...
这样做的问题是 capistrano 在获取新代码后使用错误的目录来执行命令(deploy:update_code
)。git clone 命令将检索到的文件存储到/var/www/releases/20130629231751
目录中,但以下所有命令都使用旧版本 ( /var/www/releases/20130629230631
)。结果是资产等被预编译为错误的版本。
我的config/deploy.rb
样子是这样的:
set :application, "example"
set :repository, "git@some-random-git-server.org:example.com.git"
set :deploy_to, "/var/www"
set :scm, :git
set :git_shallow_clone, 1
role :web, "example.org"
role :app, "example.org"
role :db, "example.org", :primary => true
set :user, "some-user"
set :use_sudo, false
ruby_version = 'ruby-1.9.3-p392'
set :default_environment, {
'PATH' => "/usr/local/rvm/gems/#{ruby_version}/bin/:$PATH",
'RUBY_VERSION' => "#{ruby_version}",
'GEM_HOME' => "/usr/local/rvm/gems/#{ruby_version}",
'GEM_PATH' => "/usr/local/rvm/gems/#{ruby_version}@global",
'BUNDLE_PATH' => "/usr/local/rvm/gems/#{ruby_version}",
'TERM' => 'xterm'
}
如何解决此问题,以便 git clone 之后的命令在正确的目录上运行?