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

为君一笑 提交于 2019-12-03 02:10:45

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.

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

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

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