Capistrano 3.1:rake资产预编译不起作用

时间:2014-04-07 15:04:15

标签: ruby-on-rails-3 capistrano

我是Capistrano的新手并试图预编译资产。输入命令cap production deploy后,我的代码已成功部署在服务器上,但我的资产未编译。下面是我的deploy.rb文件。

       #SSHKit.config.command_map[:rake] = "bundle exec rake"
# config valid only for Capistrano 3.1
lock '3.1.0'

set :application, 'woi'
set :repo_url, 'git@github.com:sanjay-salunkhe/cap.git'
set :branch, "master"
set :deploy_via, :remote_cache
set :stages, ["production"]

# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

# Default deploy_to directory is /var/www/my_app
 set :deploy_to, '/home/webuser/apps/cap/'

# Default value for :scm is :git
# set :scm, :git

# Default value for :format is :pretty
# set :format, :pretty

# Default value for :log_level is :debug
# set :log_level, :debug

# Default value for :pty is false
# set :pty, true

# Default value for :linked_files is []
# set :linked_files, %w{config/database.yml}

# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
 set :keep_releases, 5

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
       execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end


  desc 'precompiling assets..............'
  task :composer_install do
    on roles(:web) do
      within release_path do
        execute :rake, "assets:precompile RAILS_ENV=production"
      end
    end
  end

  after :publishing, 'deploy:composer_install'



end

以下是我的日志

   DEBUG [cf204b99]     /usr/bin/env: 
DEBUG [cf204b99]    rake
DEBUG [cf204b99]    : No such file or directory
DEBUG [cf204b99]    
cap aborted!
SSHKit::Command::Failed: rake stdout: Nothing written
rake stderr: Nothing written
/var/lib/gems/1.9.1/gems/sshkit-1.3.0/lib/sshkit/command.rb:94:in `exit_status='
/var/lib/gems/1.9.1/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:142:in `block (4 levels) in _exe

如果可能的话请向我发送Capistrano 3.1的良好文档链接。

谢谢,

4 个答案:

答案 0 :(得分:1)

您需要在一个命令中更改目录和编译资产。 我用这个:
execute "cd #{release_path}/ && RAILS_ENV=production bundle exec rake assets:precompile"

有时(取决于服务器配置)capistrano可能会引发一个无法找到' bundle'的错误,那么你必须使用以下命令查找服务器上的bundle位置:
which bundle
添加上面一行的完整路径,在我的配置中,需要提供完整路径:
execute "cd #{release_path}/ && RAILS_ENV=production /usr/local/bin/bundle exec rake assets:precompile"

答案 1 :(得分:0)

最后我设法使用capistrano部署我的应用程序3.实际上我的capfile中没有包含以下两行。

 require 'capistrano/rvm'
require 'capistrano/rails'

在包含这两行后,我的问题已经解决。

答案 2 :(得分:0)

对于Rails 4和Capistrano 3,我发现没有必要编写Capistrano配方来预编译资产以进行生产。

之前我

cap production deploy

我刚跑

rake assets:precompile RAILS_ENV=production

从我的本地计算机上继续部署。

答案 3 :(得分:0)

我必须更新节点并在服务器上安装yarn才能获得rake资产:预编译才能正常工作。 令人沮丧的是,它没有产生任何错误或反馈。我只是在耙耙资产时发现了这个问题: