Capistrano 3 + Sprockets 3 + Rails 4.2.1不会部署?

时间:2015-04-14 00:30:21

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

我运行bundle update并将sprockets更新为3.0.0。

当我尝试通过Capistrano 3部署时,我收到以下错误:

INFO [e54ac5ca] Running /usr/bin/env cp /var/www/testapp/releases/20150414002210/public/assets/manifest* /var/www/testapp/releases/20150414002210/assets_manifest_backup as deploy@xx.xxx.xxx.xx
DEBUG [e54ac5ca] Command: cd /var/www/testapp/releases/20150414002210 && /usr/bin/env cp /var/www/testapp/releases/20150414002210/public/assets/manifest* /var/www/testapp/releases/20150414002210/assets_manifest_backup
DEBUG [e54ac5ca]    cp: cannot stat ‘/var/www/testapp/releases/20150414002210/public/assets/manifest*’
DEBUG [e54ac5ca]    : No such file or directory
DEBUG [d2c5a990]    cp: cannot stat ‘/var/www/testapp/releases/20150414002210/public/assets/manifest*’
DEBUG [d2c5a990]    : No such file or directory
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@xx.xxx.xxx.xxx: cp exit status: 1
cp stdout: Nothing written
cp stderr: cp: cannot stat ‘/var/www/testapp/releases/20150414002210/public/assets/manifest*’: No such file or directory
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:16:in `rescue in block (2 levels) in execute'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
SSHKit::Command::Failed: cp exit status: 1
cp stdout: Nothing written
cp stderr: cp: cannot stat ‘/var/www/testapp/releases/20150414002210/public/assets/manifest*’: No such file or directory
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/command.rb:95:in `exit_status='
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:179:in `block in _execute'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `tap'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `_execute'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/capistrano-rails-1.1.2/lib/capistrano/tasks/assets.rake:68:in `block (5 levels) in <top (required)>'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/backends/abstract.rb:77:in `within'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/capistrano-rails-1.1.2/lib/capistrano/tasks/assets.rake:67:in `block (4 levels) in <top (required)>'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/HomeHome/.rvm/gems/ruby-2.1.3/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => deploy:assets:backup_manifest
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing as deploy@xx.xxx.xxx.xxx: cp exit status: 1
cp stdout: Nothing written
cp stderr: cp: cannot stat ‘/var/www/testapp/releases/20150414002210/public/assets/manifest*’: No such file or directory

我已经四处寻找可能遇到同样问题的人,似乎在任何地方都没有任何问题或意见......

老实说,我甚至不确定sprocketssprockets-rails与铁轨有什么关系。这对我来说非常困惑......例如,新的Gemfile应用程序附带的默认Rails 4.2.1表示Gemfile.lock中允许使用sprockets 3.0.0,但是当你去了//= include时链轮2-> 3升级指南,它显示application.js已被删除,但它就在{{1}}文件中。

所以,也许我错过了什么,但我不太确定如何解决这个问题。

3 个答案:

答案 0 :(得分:22)

如果您使用的是capistrano-rails,请尝试更新至1.1.3。这为我解决了这个问题。

capistrano-rails CHANGELOG:

1.1.3 (Apr 18 2015)
- Fixed no_release behaviour (https://github.com/capistrano/rails/pull/95)
- Allow assets manifest backup with folder "manifests" (https://github.com/capistrano/rails/pull/92)
- Handle Sprocket 3 manifest filename

答案 1 :(得分:7)

问题很容易解决,但我认为首先我们应该解决其他一些问题。

sprockets是一个ruby库,可以自动管理Web前端资产(CSS,JS,图像等)。

它基于在开发中保持资产文件逻辑组织的想法,然后在部署到生产之前链接并缩小它们。链轮使这个过程自动化。

Rails 3.1(很久以前,现在)发布了一项名为&#34; Asset Pipeline&#34;的新功能,它可以自动管理网络资产。 Rails&#39; Asset Pipeline过去了,现在仍由sprockets提供支持。

sprocketsrails都是积极维护和开发的库。新版本发布了新功能和重大变化 我相信Rails默认不使用最新版本的sprockets。没关系,我们在这里谈论编译CSS和JS,而不是与一些外部API交互;即使是sprockets的旧版本也可以完成这项工作 这意味着更新sprockets不是一个好主意。每个版本的Rails都声明sprockets的特定(最小 - 最大)版本,原因很简单:它是当前Asset Pipeline所依赖的版本。更新它可能会破坏事情。

然后,让我们转到清单文件 默认情况下,在预编译资产(解析引用,包括某些文件到其他文件,链接和缩小它们)之后,编译的资产将复制到RAILS_ROOT/public/assets中。有了它们,Rails会生成一个manifest文件,其中包含所有预编译资产的列表。在您的Rails版本中,它应该是manifest.json,但它曾经是manifest.yml

现在,拼图的最后一块是capistrano,我想你知道如何使用它。

该行:

cp: cannot stat ‘/var/www/testapp/releases/20150414002210/public/assets/manifest*’

表示capistrano试图在manifest目录中找到RAILS_ROOT/public/assets文件。通配符在那里,因为它可能是manifest.jsonmanifest.yml,具体取决于Rails的版本。
此外,stat表示capistrano正在尝试从文件中获取一些信息,可能是为了弄清楚最近的信息。

问题是文件不存在。
您应该precompile the assets,然后提交生成的文件并尝试再次部署。

答案 2 :(得分:4)

根据评论,我通过从1.1.2 -> 1.1.3

升级capistrano-rails来解决此问题
# Gemfile
'capistrano-rails', '~> 1.1.3'