How we reduced our Heroku slug size by 50% to deploy again
Compiled slug size: 600.5MB is too large (max is 500MB).
A few months back we *needed* to deploy a fix to Bento's production application but because our Heroku slug size was too large it was stopping us from actually pushing it up.
This was immensely frustrating at the time but also enlightening. We learned a little bit more about how Heroku works, how to fix issues like this, and how to deploy confidently again as your app eventually gets to the size of Bento!
Attempt #1: Purge!
Install the Heroku Repo plugin:
heroku plugins:install heroku-repo
heroku repo:gc --app your-app-name heroku repo:purge_cache --app your-app-name
Attempt #2: Delete!
Over time we had accumulated a lot of files in our repo. Silly stuff like old videos, unoptimised images, and even some sound files from before our Conversations refactor! We removed these and it managed to get our slug down by 50mb — still, not enough!
Attempt #3: RM ALL THE THINGS!
So, let's remove the node_modules folder after everything is compiled.
To do this we just have to amend the existing rake assets:clean task a tad.
namespace :assets do desc "Remove 'node_modules' folder" task rm_node_modules: :environment do Rails.logger.info "Removing node_modules folder" FileUtils.remove_dir("node_modules", true) end end skip_clean = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"]) unless skip_clean if Rake::Task.task_defined?("assets:clean") Rake::Task["assets:clean"].enhance do Rake::Task["assets:rm_node_modules"].invoke end else Rake::Task.define_task("assets:clean" => "assets:rm_node_modules") end end
This alone dropped our total slug size by 50% and we could deploy!
Hope one of these solutions helps when you're debugging this issue.