Capistrano 3 + Sprockets 3 + Rails 4.2.1 won't deploy?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 11:42:49

问题


I ran bundle update and updated sprockets to 3.0.0.

When I try to deploy via Capistrano 3 I get the following error:

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

I've looked all around for people possibly having the same issues and it seems there are no issues or comments on it anywhere...

Honestly I'm not even sure how sprockets, sprockets-rails are related to rails. It's all quite confusing to me... for example, the default Gemfile which comes with a fresh Rails 4.2.1 app says sprockets 3.0.0 is allowed in Gemfile.lock, yet when you go to the sprockets 2->3 upgrade guide, it shows that //= include has been removed, yet it's right there in the application.js file.

So, maybe I'm missing something, but I'm not quite sure how to solve this.


回答1:


The problem is easy to fix, but I think that first we should address some of the other questions.

sprockets is a ruby library that automates managing web front end assets (CSS, JS, images, etc).

It is based on the idea of keeping your asset files logically organized in development, and to then chain and minify them before deploying to production. Sprockets makes this process automatic.

Rails 3.1 (a long time ago, now) released a new feature called "Asset Pipeline", that automated the management of web assets. The Rails' Asset Pipeline was, and still is, powered by sprockets.

Both sprockets and rails are actively maintained and developed libraries. New versions are released with new features and breaking changes.
I believe that Rails does not use, by default, the latest version of sprockets. It is ok, we're talking about compiling CSS and JS here, not interacting with some external API; even an old version of sprockets can do the job.
This means that updating sprockets is not a good idea. Each version of Rails declares a specific (min-max) version of sprockets, for good reason: it's the version that the current Asset Pipeline relies on. Updating it might break things.

Then, let's move to the manifest file.
By default, after precompiling the assets (resolving references, including some files into others, chaining and minifying them), the compiled assets are copied in RAILS_ROOT/public/assets. With them, Rails generates a manifest file that contains a list of all the precompiled assets. In your version of Rails it should be manifest.json, but it used to be manifest.yml.

Now, the last piece of the puzzle is capistrano, which I imagine you know how to use.

The line:

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

means that capistrano tried to find a manifest file in your RAILS_ROOT/public/assets directory. The wildcard is there because it might be either manifest.json or manifest.yml, depending on the version of Rails.
Also, stat means that capistrano is trying to get some info from the file, probably to figure out how recent it is.

The problem is that the file is not present.
You should precompile the assets, then commit the generated files and try to deploy again.




回答2:


If you are using capistrano-rails, try update to 1.1.3. This has fixed the issue for me.

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



回答3:


per comment, I fixed this by upgrading capistrano-rails from 1.1.2 -> 1.1.3

# Gemfile
'capistrano-rails', '~> 1.1.3'


来源:https://stackoverflow.com/questions/29617239/capistrano-3-sprockets-3-rails-4-2-1-wont-deploy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!