2

我一直在关注这个 railscast 部署到 VPS http://railscasts.com/episodes/335-deploying-to-a-vps并且我似乎一直坚持部署。当我输入 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)

我的部署.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”,则会显示一个新错误。

谢谢!

4

2 回答 2

2

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

gem 'capistrano', '2.15.5'

但是,如果您对使用 Capistrano 3 感兴趣,这里有一个非常适合我的升级指南

于 2013-12-11T05:56:45.610 回答
1

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

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

require 'capistrano/rails'
于 2013-12-11T05:03:46.943 回答