Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/capistrano/recipes/deploy/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def parse_manifest(str)
assets_hash.to_a.flatten.map {|a| [a, "#{a}.gz"]}.flatten
end

def number_of_manifests
output = capture("ls -1 #{shared_path.shellescape}/#{shared_assets_prefix}/manifest* | grep -v \"manifest.js.gz\"")
# splitting on "." because File.basename(path, ".*") only removes the *first* extension, so for x.js.gz, it will return x.js
output = output.map { |path| File.basename(path).split(".")[0] }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make gsub(/.js$/, ".js.gz")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually gsub(/\.js(\.gz|)$/, '')

# we may get manifest-X.js and manifest-X.js.gz, so we shouldn't count those as unique manifests
return output.uniq.size
end

namespace :deploy do
namespace :assets do
desc <<-DESC
Expand Down Expand Up @@ -91,10 +99,9 @@ def parse_manifest(str)
logger.info 'Ignoring multiple asset/clean_expired manifests...'
end
if should_retry_if_multi
# test for multiple
if capture("ls -1 #{shared_path.shellescape}/#{shared_assets_prefix}/manifest* | grep -v \"manifest.js.gz\" | wc -l").to_i > 1
if number_of_manifests > 1
logger.info "Multiple manifest assets detected; clearing old assets..."
run "mv #{shared_path.shellescape}/#{shared_assets_prefix} '/tmp/#{shared_assets_prefix}-#{Time.now.to_s}'"
run "mv #{shared_path.shellescape}/#{shared_assets_prefix} '/tmp/#{shared_assets_prefix}-#{Time.now.to_s}' && mkdir #{shared_path.shellescape}/#{shared_assets_prefix} && chmod 775 #{shared_path.shellescape}/#{shared_assets_prefix}"
run <<-CMD.compact
sudo -n rm -f /tmp/assets-precompile-output*.log > /dev/null || true ;
#{precompile_command}
Expand All @@ -104,7 +111,7 @@ def parse_manifest(str)
end

# test again
if capture("ls -1 #{shared_path.shellescape}/#{shared_assets_prefix}/manifest* | grep -v \"manifest.js.gz\" | wc -l").to_i > 1
if number_of_manifests > 1
logger.info "Multiple manifest assets still detected; skipping..."
end

Expand Down