Skip to content

Instantly share code, notes, and snippets.

@andrey-skat
Last active August 5, 2018 12:03
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save andrey-skat/10399224 to your computer and use it in GitHub Desktop.
Save andrey-skat/10399224 to your computer and use it in GitHub Desktop.
Local assets precompilation on Rails 4 using Capistrano 3
# also you need to uncomment next line in Capfile
# require 'capistrano/rails/assets'
namespace :deploy do
namespace :assets do
Rake::Task['deploy:assets:precompile'].clear_actions
desc 'Precompile assets locally and upload to servers'
task :precompile do
on roles(fetch(:assets_roles)) do
run_locally do
with rails_env: fetch(:rails_env) do
execute 'bin/rake assets:precompile'
end
end
within release_path do
with rails_env: fetch(:rails_env) do
old_manifest_path = "#{shared_path}/public/assets/manifest*"
execute :rm, old_manifest_path if test "[ -f #{old_manifest_path} ]"
upload!('./public/assets/', "#{shared_path}/public/", recursive: true)
end
end
run_locally { execute 'rm -rf public/assets' }
end
end
end
end
@kalashnikovisme
Copy link

I have an error while deploying

DEBUG [9ae7a7bd] Command: cd /srv/ulmic_stg/releases/20150521092902 && /usr/bin/env ls /srv/ulmic_stg/releases/20150521092902/public/assets/.sprockets-manifest*
DEBUG [9ae7a7bd]    ls: cannot access /srv/ulmic_stg/releases/20150521092902/public/assets/.sprockets-manifest*: No such file or directory
DEBUG [9ae7a7bd] Finished in 0.358 seconds with exit status 2 (failed).
DEBUG [764edefa] Running /usr/bin/env ls /srv/ulmic_stg/releases/20150521092902/public/assets/manifest*.* as ulmicru@ulmic.ru
DEBUG [764edefa] Command: cd /srv/ulmic_stg/releases/20150521092902 && /usr/bin/env ls /srv/ulmic_stg/releases/20150521092902/public/assets/manifest*.*
DEBUG [764edefa]    ls: cannot access /srv/ulmic_stg/releases/20150521092902/public/assets/manifest*.*: No such file or directory
DEBUG [764edefa] Finished in 0.279 seconds with exit status 2 (failed).
WARN Rails assets manifest file not found.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ulmicru@ulmic.ru: Rails assets manifest file not found.
Capistrano::FileNotFound: Rails assets manifest file not found.

@DavidBennettPIO
Copy link

@kalashnikovisme my guess is that your using sprockets 3.x.x which creates the manifest as a hidden file that’s not getting uploaded by the upload! command?

Might also want to check the contents of your shared/public and shared/public/assets folder for old assets and manifests.

@krishnasrihari
Copy link

Thank you. This is very slow to upload files. Other solutions with rsync may reduce deployment time.
https://gist.github.com/basti/9232976

@michaellarrubis
Copy link

Thank you. This really saves my ass.

@jairud-garcia
Copy link

Uploading many files (and some non compressed) can be slow.
Try compressing and packaging for uploading:
[Example here] (https://gist.github.com/jairud-garcia/4e9210c4d896b7c56f5fd54164812b8f)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment