Solution:
Added the following to the bottom of deploy.rb
Rake::Task["deploy:assets:restore_manifest"].clear_actions
before 'deploy:finishing_rollback', 'deploy:pre_start_precompile'
task :pre_start_precompile do
on roles(:db) do
with rails_env: "#{fetch(:stage)}" do
path_to_bundler = "/usr/local/rbenv/shims/bundle"
execute "cd #{release_path}; RAILS_ENV=production #{path_to_bundler} exec rake assets:precompile"
end
end
end
This worked!
Original question:
I'm running Rails 4.2 and Ruby 2.5.8 and capistrano 3.14.1. When I try and roll back I get this error;
** Execute bundler:install
00:04 bundler:install
The Gemfile's dependencies are satisfied, skipping installation
** Execute deploy:reverted
** Invoke deploy:rollback_assets (first_time)
** Invoke deploy:set_rails_env
** Execute deploy:rollback_assets
** Invoke deploy:assets:restore_manifest (first_time)
** Execute deploy:assets:restore_manifest
00:04 deploy:assets:restore_manifest
WARN Rails assets manifest file (or backup file) not found.
#<Thread:0x00007ff7f8218548@/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as user@<server ip>: Rails assets manifest file (or backup file) not found. (SSHKit::Runner::ExecuteError)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as <user>@<server ip>: Rails assets manifest file (or backup file) not found.
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
Caused by:
Capistrano::FileNotFound: Rails assets manifest file (or backup file) not found.
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:103:in `block (5 levels) in <top (required)>'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:92:in `within'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:90:in `block (4 levels) in <top (required)>'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:assets:restore_manifest
I read somewhere that I have to make two files on the production server which I have and it didn't make a difference;
$ touch public/assets/.manifest.json
$ touch public/assets/.sprockets-manifest.json
The error happens within assets.rake part of capistrano-rails;
task :restore_manifest do
on release_roles(fetch(:assets_roles)) do
within release_path do
targets = detect_manifest_path.split(' ')
sources = targets.map do |target|
release_path.join('assets_manifest_backup', File.basename(target))
end
if test(:ls, *sources) && test(:ls, *targets) # <-- this line
source_map = sources.zip(targets)
source_map.each do |source, target|
execute :cp, source, target
end
else
msg = 'Rails assets manifest file (or backup file) not found.'
warn msg
fail Capistrano::FileNotFound, msg
end
end
end
end
I manually tested sources and targets. I found sources failed and targets passed. Below are both;
(byebug) sources
[#<Pathname:/var/www/<site>.com.au/releases/20201004053756/assets_manifest_backup/.sprockets-manifest-2df820954d56273c97d9696e88075409.json>, #<Pathname:/var/www/<site>.com.au/releases/20201004053756/assets_manifest_backup/.sprockets-manifest.json>]
(byebug) targets
["/var/www/<site>.com.au/releases/20201004053756/public/assets/.sprockets-manifest-2df820954d56273c97d9696e88075409.json", "/var/www/<site>.com.au/releases/20201004053756/public/assets/.sprockets-manifest.json"]
Update: listing of shared/public
[capistrano root]/shared/public$ find .
.
./system
./assets
./assets/application-e02d56bdf7493178ee13a95f4211508873eedfc4dbcff55cda9447e26b589ad0.js
./assets/application-04fbdaf9d6b9abbae40cd5dbc0a71ca7094b363cf5016d06db76b7018a397231.css
./assets/application-04fbdaf9d6b9abbae40cd5dbc0a71ca7094b363cf5016d06db76b7018a397231.css.gz
./assets/.sprockets-manifest-2df820954d56273c97d9696e88075409.json
./assets/application-81e70a4729ca29787e86c6981d9275dedbedddab40a87dfbcc39e19c9851c7b6.css
./assets/application-89cedfcf3e9592cd9f252337803bc10a9e57d40dc7fa8e192f2a4a32ef109b0c.js.gz
./assets/application-89cedfcf3e9592cd9f252337803bc10a9e57d40dc7fa8e192f2a4a32ef109b0c.js
./assets/application-e02d56bdf7493178ee13a95f4211508873eedfc4dbcff55cda9447e26b589ad0.js.gz
./assets/application-9416e76266dcf39961fba3ae76d96e7e89ce9e0eba1a0ccf529aa003869cac9d.css
./assets/.manifest.json
./assets/.sprockets-manifest.json
./assets/application-9416e76266dcf39961fba3ae76d96e7e89ce9e0eba1a0ccf529aa003869cac9d.css.gz
./assets/application-81e70a4729ca29787e86c6981d9275dedbedddab40a87dfbcc39e19c9851c7b6.css.gz