【问题标题】:Problems deploying rails app with Capistrano使用 Capistrano 部署 Rails 应用程序的问题
【发布时间】:2014-01-14 14:26:56
【问题描述】:

我正在使用 capistrano 将我的 rails 3.2.16 应用程序部署到 VPS 服务器。这是我使用 capistrano 的时间,所以请考虑我是新手。我在运行“cap deploy:update”时遇到了问题,我不知道从这里开始做什么。

以下是所发生情况的终端输出:

    ******-MBP:Folio stevo$ bundle exec cap deploy:update
    triggering load callbacks
  * 2013-12-26 20:29:21 executing `deploy:update'
 ** transaction: start
  * 2013-12-26 20:29:21 executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote git@bitbucket.org:**********/*********.git master-staging"
    command finished in 1626ms
  * executing "if [ -d /home/********/app/*********/shared/cached-copy ]; then cd /home/********/app/*********/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard c56df1b37c96846177a518133e89c1188b8d7a09 && git clean -q -d -x -f; else git clone -q -b master-staging git@bitbucket.org:**********/*********.git /home/********/app/*********/shared/cached-copy && cd /home/********/app/*********/shared/cached-copy && git checkout -q -b deploy c56df1b37c96846177a518133e89c1188b8d7a09; fi"
    servers: ["198.**.***.***"]
    [198.**.***.***] executing command
    command finished in 3002ms
    copying the cached version to /home/********/app/*********/releases/20131227002927
  * executing "cp -RPp /home/********/app/*********/shared/cached-copy /home/********/app/*********/releases/20131227002927 && (echo c56df1b37c96846177a518133e89c1188b8d7a09 > /home/********/app/*********/releases/20131227002927/REVISION)"
    servers: ["198.**.***.***"]
    [198.**.***.***] executing command
    command finished in 1025ms
  * 2013-12-26 20:29:28 executing `deploy:finalize_update'
    triggering before callbacks for `deploy:finalize_update'
  * 2013-12-26 20:29:28 executing `deploy:assets:symlink'
  * executing "rm -rf /home/********/app/*********/releases/20131227002927/public/assets && mkdir -p /home/********/app/*********/releases/20131227002927/public && mkdir -p /home/********/app/*********/shared/assets && ln -s /home/********/app/*********/shared/assets /home/********/app/*********/releases/20131227002927/public/assets"
    servers: ["198.**.***.***"]
    [198.**.***.***] executing command
    command finished in 911ms
  * 2013-12-26 20:29:29 executing `bundle:install'
  * executing "cd /home/********/app/*********/releases/20131227002927 && bundle install --gemfile /home/********/app/*********/releases/20131227002927/Gemfile --path /home/********/app/*********/shared/bundle --deployment --quiet --without development test"
    servers: ["198.**.***.***"]
    [198.**.***.***] executing command
    command finished in 1533ms
  * executing "chmod -R -- g+w /home/********/app/*********/releases/20131227002927 && rm -rf -- /home/********/app/*********/releases/20131227002927/public/system && mkdir -p -- /home/********/app/*********/releases/20131227002927/public/ && ln -s -- /home/********/app/*********/shared/system /home/********/app/*********/releases/20131227002927/public/system && rm -rf -- /home/********/app/*********/releases/20131227002927/log && ln -s -- /home/********/app/*********/shared/log /home/********/app/*********/releases/20131227002927/log && rm -rf -- /home/********/app/*********/releases/20131227002927/tmp/pids && mkdir -p -- /home/********/app/*********/releases/20131227002927/tmp/ && ln -s -- /home/********/app/*********/shared/pids /home/********/app/*********/releases/20131227002927/tmp/pids && rm -rf -- /home/********/app/*********/releases/20131227002927/config/application.yml && mkdir -p -- /home/********/app/*********/releases/20131227002927/config/ && ln -s -- /home/********/app/*********/shared/application.yml /home/********/app/*********/releases/20131227002927/config/application.yml"
    servers: ["198.**.***.***"]
    [198.**.***.***] executing command
    command finished in 940ms
    triggering after callbacks for `deploy:update_code'
  * 2013-12-26 20:29:32 executing `deploy:assets:precompile'
    triggering before callbacks for `deploy:assets:precompile'
  * 2013-12-26 20:29:32 executing `deploy:assets:update_asset_mtimes'
  * executing "[ -e /home/********/app/*********/shared/assets/manifest* ] && cat /home/********/app/*********/shared/assets/manifest* || echo"
    servers: ["198.**.***.***"]
    [198.**.***.***] executing command
    command finished in 903ms
  * executing "cat /home/********/app/*********/current/REVISION"
    servers: ["198.**.***.***"]
    [198.**.***.***] executing command
    command finished in 920ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/********/app/*********/releases/20131227002927; true"
    servers: ["198.**.***.***"]
    [198.**.***.***] executing command
    command finished in 918ms
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell 'default' -c 'cat /home/********/app/*********/current/REVISION'" on 198.**.***.***

这是我的 deploy.rb 文件,以防问题出在此处:

server '198.**.***.***', :web, :app, :db, primary: true

set :application, '*********'
set :user, '*********'
set :deploy_to, "/home/#{user}/app/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :rvm_type, :user

set :scm, 'git'
set :repository, "git@bitbucket.org:*****/#{application}.git"
set :branch, `git rev-parse --abbrev-ref HEAD`.strip

set :shared_children, shared_children + %w{ config/application.yml }

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

# Using Passenger
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


# Skipping Asset Compilation With Capistrano
# http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano/
namespace :deploy do
  namespace :assets do
    task :precompile, :roles => :web, :except => { :no_release => true } do
      from = source.next_revision(current_revision)
      if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
        run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
      else
        logger.info "Skipping asset pre-compilation because there were no asset changes"
      end
    end
  end
end

require "rvm/capistrano"
require "bundler/capistrano"

我做错了什么?

【问题讨论】:

  • 错误代码就这么多吗?为什么你运行deploy:update 而不是deploy
  • 嘿 Victor - 我正在关注本指南 (stackoverflow.com/a/13444106/303343),它建议先运行 :update。但是,运行 just deploy 会给出相同的错误消息。另外,是的,这是完整的错误代码。我首先怀疑是辅助预编译给我带来了问题 - 这就是最后一部分如何将其放入我的部署文件的方式。
  • 我帮不上什么忙,很抱歉,但这是我要让它完美运行的方法:railscasts.com/episodes/337-capistrano-recipes

标签: ruby-on-rails ruby ruby-on-rails-3 rvm capistrano


【解决方案1】:

您的 cap deploy 在 deploy:assets:precompile 任务中引发错误,您已在 deploy.rb 中覆盖该任务请在从 deploy.rb 注释以下给定代码后尝试运行 cap deploy

namespace :deploy do

  namespace :assets do

  task :precompile, :roles => :web, :except => { :no_release => true } do
    from = source.next_revision(current_revision)
    if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/  app/assets/ | wc -l").to_i > 0
    run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
    else
      logger.info "Skipping asset pre-compilation because there were no asset changes"
    end
  end
end

结束

【讨论】:

    猜你喜欢
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    相关资源
    最近更新 更多