【问题标题】:Rails 4, capistrano error: cannot load such file -- deploy/assetsRails 4,capistrano 错误:无法加载此类文件 -- 部署/资产
【发布时间】:2013-11-06 04:05:12
【问题描述】:

在部署到 VPS http://railscasts.com/episodes/335-deploying-to-a-vps 时,我一直在关注此 railscast,但我似乎一直坚持部署。当我输入 cap deploy 时,我得到了这个。

cap aborted!
cannot load such file -- deploy/assets
/files/rails/Capfile:2:in `load'
/files/rails/Capfile:2:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/capistrano-3.0.1/lib/capistrano/application.rb:22:in `load_rakefile'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/capistrano-3.0.1/lib/capistrano/application.rb:12:in `run'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/capistrano-3.0.1/bin/cap:3:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p247/bin/cap:23:in `load'
/usr/local/rvm/gems/ruby-2.0.0-p247/bin/cap:23:in `<main>'
(See full trace by running task with --trace)

我的 deploy.rb

require "bundler/capistrano"

server "(removed)", :web, :app, :db, primary: true

set :application, "Fooddiscovery"
set :user, "(removed)"
set :deploy_to, "/home/rails"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "(removed)"
set :branch, "master"

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

after "deploy", "deploy:cleanup" # keep only the last 5 releases

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"

  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end
  before "deploy", "deploy:check_revision"
end

我的文件

load 'deploy' if respond_to?(:namespace)
load 'deploy/assets'
load 'config/deploy'

我阅读了其他说要添加的问题和答案 if respond_to?(:namespace) 这确实有助于解决第一个错误,而不是部署/资产,它用于显示仅部署的错误(无法加载此类文件 - 部署)。为所有三个链接添加 if respond_to?(:namespace) 并不能解决问题。事实上,如果我这样做告诉我未定义的局部变量或方法“tasks_without_stage_dependency”,则会出现一个新错误。

谢谢!

【问题讨论】:

  • 你解决了吗?我也有类似的问题
  • @MichaelMoulsdale 不幸的是没有。从那以后我再也没有重温过这个。

标签: ruby-on-rails deployment ruby-on-rails-4 capistrano


【解决方案1】:

@Michael 正确的是您将 Capistrano 2 语法与 Capistrano 3 一起使用,但您只需确保在 Gemfile 中使用 Capistrano 2 即可快速修复。

gem 'capistrano', '2.15.5'

但是,如果您对使用 Capistrano 3 感兴趣,这里有一个非常不错的 upgrade guide,它对我很有用。

【讨论】:

    【解决方案2】:

    看起来您在 Capfile 中使用 Capistrano 2 语法,并且您已升级到 Capistrano 3 gem。

    Capistrano 3 在 Capfile 中看起来更像以下内容

    require 'capistrano/rails'
    

    【讨论】:

      猜你喜欢
      • 2013-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-15
      • 1970-01-01
      • 2011-11-23
      • 2014-02-05
      相关资源
      最近更新 更多