capistrano / rails

Official Ruby on Rails specific tasks for Capistrano
http://www.capistranorb.com/
MIT License
867 stars 270 forks source link

Capistrano::FileNotFound: Rails assets manifest file not found when using --print-config-variables option #223

Open bikramwp opened 6 years ago

bikramwp commented 6 years ago

Steps to reproduce

Do a cold deploy (where the <app>/current path does not exist). Deploy with cap --print-config-variables deploy

Expected behavior

The assets_manifest file should be copied from the current release_path <app>/releases/20180718040802/public/assets/.sprockets-manifest-abcd to <app>/releases/20180718040802/assets_manifest_backup/.sprockets-manifest-abcd.

See in the error trace below: ls: cannot access '/home/deploy-user/test-app/current/public/assets/.sprockets-manifest*': No such file or directory

Since the /current path does not yet exist, the backup fails. Maybe(?) the /current should not be getting used at all for the backup and instead it should be the release_path that should be used at all times?

Actual behavior

An error is thrown:

      WARN  Rails assets manifest file not found.
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy-user@127.0.0.1: Rails assets manifest file not found.

Caused by:
Capistrano::FileNotFound: Rails assets manifest file not found.

Tasks: TOP => deploy:assets:backup_manifest
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy-user@127.0.0.1: Rails assets manifest file not found.

** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:

 DEBUG [35002d68] Finished in 0.101 seconds with exit status 0 (successful).
  INFO [16952ff6] Running /usr/bin/env mkdir -p /home/deploy-user/test-app/releases/20180718040802/assets_manifest_backup as deploy-user@127.0.0.1
 DEBUG [16952ff6] Command: cd /home/deploy-user/test-app/releases/20180718040802 && /usr/bin/env mkdir -p /home/deploy-user/test-app/releases/20180718040802/assets_manifest_backup
  INFO [eeef99ea] Finished in 0.103 seconds with exit status 0 (successful).
 DEBUG [c149607f] Running /usr/bin/env ls /home/deploy-user/test-app/current/public/assets/.sprockets-manifest* as deploy-user@172.16.1.153
 DEBUG [c149607f] Command: cd /home/deploy-user/test-app/releases/20180718040802 && /usr/bin/env ls /home/deploy-user/test-app/current/public/assets/.sprockets-manifest*
  INFO [502f9b11] Finished in 0.101 seconds with exit status 0 (successful).
 DEBUG [a569bd45] Running /usr/bin/env ls /home/deploy-user/test-app/current/public/assets/.sprockets-manifest* as deploy-user@127.0.0.1
 DEBUG [a569bd45] Command: cd /home/deploy-user/test-app/releases/20180718040802 && /usr/bin/env ls /home/deploy-user/test-app/current/public/assets/.sprockets-manifest*
 DEBUG [2f0f2f0c]   ls: cannot access '/home/deploy-user/test-app/current/public/assets/.sprockets-manifest*': No such file or directory
 DEBUG [2f0f2f0c] Finished in 0.105 seconds with exit status 2 (failed).
 DEBUG [e28e7923] Running /usr/bin/env ls /home/deploy-user/test-app/current/public/assets/manifest*.* as deploy-user@127.0.0.1
 DEBUG [e28e7923] Command: cd /home/deploy-user/test-app/releases/20180718040802 && /usr/bin/env ls /home/deploy-user/test-app/current/public/assets/manifest*.*
 DEBUG [924d8181]   ls: cannot access '/home/deploy-user/test-app/current/public/assets/.sprockets-manifest*': No such file or directory
 DEBUG [924d8181] Finished in 0.112 seconds with exit status 2 (failed).
 DEBUG [8b58a53b] Running /usr/bin/env ls /home/deploy-user/test-app/current/public/assets/manifest*.* as deploy-user@172.16.1.153
 DEBUG [8b58a53b] Command: cd /home/deploy-user/test-app/releases/20180718040802 && /usr/bin/env ls /home/deploy-user/test-app/current/public/assets/manifest*.*
 DEBUG [d9b7d0fe]   ls: cannot access '/home/deploy-user/test-app/current/public/assets/manifest*.*': No such file or directory
 DEBUG [d9b7d0fe] Finished in 0.105 seconds with exit status 2 (failed).
  WARN Rails assets manifest file not found.

Possible Fix?

diff --git i/lib/capistrano/tasks/assets.rake w/lib/capistrano/tasks/assets.rake
index f01a62f..de30734 100644
--- i/lib/capistrano/tasks/assets.rake
+++ w/lib/capistrano/tasks/assets.rake
@@ -101,8 +101,14 @@ namespace :deploy do
       end
     end

+    def assets_manifests_path
+      fetch(:assets_manifests).map do |pattern|
+        release_path.join("public", fetch(:assets_prefix), pattern)
+      end
+    end
+
     def detect_manifest_path
-      fetch(:assets_manifests).each do |candidate|
+      assets_manifests_path.each do |candidate|
         return capture(:ls, candidate).strip.gsub(/(\r|\n)/, ' ') if test(:ls, candidate)
       end
       msg = 'Rails assets manifest file not found.'
@@ -130,10 +136,6 @@ namespace :load do
   task :defaults do
     set :assets_roles, fetch(:assets_roles, [:web])
     set :assets_prefix, fetch(:assets_prefix, 'assets')
-    set :assets_manifests, -> {
-      %w[.sprockets-manifest* manifest*.*].map do |pattern|
-        release_path.join("public", fetch(:assets_prefix), pattern)
-      end
-    }
+    set :assets_manifests, %w[.sprockets-manifest* manifest*.*]
   end
 end