我是 Capistrano 的新手,正在尝试预编译资产。 输入命令后cap production deploy
我的代码已成功部署在服务器上,但我的资产未编译。
#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的良好文档链接。
谢谢
您需要在一个命令中更改目录并编译资产。我正在使用这个:
execute "cd #{release_path}/ && RAILS_ENV=production bundle exec rake assets:precompile"
有时(这取决于服务器配置)capistrano 可能会引发一个错误,它找不到"捆绑包",然后 您必须使用以下方法查找捆绑包在服务器上的位置:
which bundle
并将完整路径添加到上面的行,在我的配置中需要提供完整路径:
execute "cd #{release_path}/ && RAILS_ENV=production /usr/local/bin/bundle exec rake assets:precompile"
我决定使用 capastrano 3 部署我的应用程序。实际上,我的 capfile 中没有包含以下两行。
require 'capistrano/rvm'
require 'capistrano/rails'
包含这两行后,我的问题已解决。
我必须更新节点并在服务器上安装 yarn 才能让 rake assets:precompile 工作。令人沮丧的是,它没有产生任何错误或反馈。我只是在做耙资产时才发现这是问题所在:clobber
对于 Rails 4 和 Capistrano 3,我发现没有必要编写 Capistrano 配方来预编译用于生产的资产。
而是在我之前
cap production deploy
我只是跑
rake assets:precompile RAILS_ENV=production
从我的本地计算机,然后继续部署。