【问题标题】:Capistrano 3.1: rake assets precompile not workingCapistrano 3.1:rake 资产预编译不起作用
【发布时间】:2014-04-07 15:04:15
【问题描述】:

我是 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 的优秀文档链接发送给我。

谢谢,

【问题讨论】:

  • 请提供日志。部署时是否在日志中显示rake assets:precompile
  • 不,它不显示 rake 资产:precompile 在 revision.log 文件中的任何位置。我在我的问题中添加了 revision.log 文件内容。
  • 不,我说的是部署时控制台上打印的日志。
  • 不,它没有向我显示 rake 资产:在日志中的任何位置预编译。检查问题中更新的日志。
  • @UandI - 我已经更新了 deploye.rb 文件,现在我收到错误为 DEBUG [cf204b99] /usr/bin/env: DEBUG [cf204b99] rake DEBUG [cf204b99] :没有这样的文件或目录 DEBUG [cf204b99] 上限中止! .请查看我更新的问题。

标签: ruby-on-rails-3 capistrano


【解决方案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"

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

    • 还记得将这些添加到您的 gemfile 中。 gem 'capistrano-rvm' 和 gem 'capistrano-rails'
    【解决方案3】:

    我必须更新节点并在我的服务器上安装 yarn 以获得 rake assets:precompile 才能工作。 令人沮丧的部分是它没有产生任何错误或反馈。我在 rake assets 时才发现这是问题:clobber

    【讨论】:

      【解决方案4】:

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

      而不是在我之前

      cap production deploy

      我只是跑

      rake assets:precompile RAILS_ENV=production

      从我的本地机器,然后继续部署。

      【讨论】:

      • 它有什么帮助?它与生产服务器同步吗?
      • 不是一个好的解决方案。在这种情况下,资产被预编译上传到存储库,这将增加每次部署所花费的时间,因为现在存储库非常大
      猜你喜欢
      • 2012-01-16
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 2012-04-23
      • 2012-07-28
      • 1970-01-01
      相关资源
      最近更新 更多