scientiffic
scientiffic

Reputation: 9415

Heroku: Compiled Slug Size is too large

I've already spent half the day trying to debug a Heroku error where I can't push code to my staging server because of a slug compilation error:

Compiled slug size: 320.5MB is too large (max is 300MB).

I've moved all assets to AWS3 and created a .slugignore file with the following information:

*.psd
*.pdf
test
spec
features
doc
public

What other strategies can I use? The strangest thing is that, as far as I know, the code is the same as the production server, and I don't get any errors with pushing to the production server.

Upvotes: 12

Views: 23654

Answers (9)

karns
karns

Reputation: 5847

When using Heroku and Wicked PDF gem, sometimes you may have the binaries included in your Gemfile. These are huge. Use wkhtmltopdf-heroku binary :

gem 'wkhtmltopdf-binary', '~> 0.12.6', group: [:development, :test]

gem 'wkhtmltopdf-heroku', '~> 2.12.6', group: [:production]

This took my slug size, I think, from over 500 mb to 150mb!

There are other solutions to get the binaries out of your slug such as separate buildpacks as well.

Upvotes: 6

Sandeep Rai
Sandeep Rai

Reputation: 1

I also got the same error and removing the unnecessary dependencies in requirement.txt solved the problem. So try removing some dependencies which are not in use in your app. Hope it helps!

Upvotes: 0

Justin Lee
Justin Lee

Reputation: 21

I know this is for Ruby on Rails but for my project I had many python dependencies which added tremendously to the slugsize.

So I reckon that you could separate your dependencies for development and production (heroku).

Upvotes: 0

Philip Mutua
Philip Mutua

Reputation: 6891

Slug size

Your slug size is displayed at the end of a successful compile after the Compressing message. The maximum allowed slug size (after compression) is 500 MB.

You can inspect the extracted contents of your slug with heroku run bash and by using commands such as ls and du.

Slug size varies greatly depending on what language and framework you are using, how many dependencies you have added and other factors specific to your app. Smaller slugs can be transferred to the dyno manager more quickly, allowing for more immediate scaling. You should try to keep your slugs as small and nimble as possible.

Here are some techniques for reducing slug size:

  1. Move large assets like PDFs or audio files to asset storage.
  2. Remove unneeded dependencies and exclude unnecessary files via .slugignore.
  3. Purge the build cache.

Upvotes: 0

Ghost Of Winterfell
Ghost Of Winterfell

Reputation: 186

This worked for me:

$ heroku repo:gc -a appname

$ heroku repo:purge_cache -a appname

$ heroku repo:reset -a appname

Upvotes: 0

dani24
dani24

Reputation: 2288

In my case I forgot to add buildpacks, so my slug was reaching 624.4MB

What I did is to add these ones:

After delpoying again, my slug size was 393.9MB

Upvotes: 0

Shiva
Shiva

Reputation: 12514

this worked for me

$ heroku repo:gc -a appname

Will run git gc --aggressive on your repo.

$ heroku repo:purge_cache -a appname

Then I mannually pushed code to heroku

$ git push heroku-prod master

Upvotes: 8

Choylton B. Higginbottom
Choylton B. Higginbottom

Reputation: 2304

I was able to fix this by running git gc.

Upvotes: -1

Lukas Eklund
Lukas Eklund

Reputation: 6138

It's possible that before you added the .slugignore file you had some large files added the git repo and now they are in the slug cache or as git refs. The git-repo plugin has commands to fix these problems:

$ heroku repo:gc -a appname

Will run git gc --aggressive on your repo.

$ heroku repo:purge_cache -a appname

This will delete the build cache and then you probably should run to rebuild the application.

$ heroku repo:rebuild -a appname

Upvotes: 21

Related Questions