Heroku: Compiled Slug Size is too large
Asked Answered
M

9

11

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.

Marela answered 12/5, 2015 at 19:30 Comment(7)
Is the production server also on heroku?Audubon
Max slug size is a constant across heroku instances (300 MB). Is there something done to prepare the production build besides just doing a git push?Audubon
@RobertMoskal not that I know ofMarela
Have you tried using the github.com/heroku/heroku-repo plugin? The purge_cache and gc commands might help trim the slug size.Wrongdoing
Do you have a lot of gems in your gemfile that are only enabled for staging? Even just a couple extra gems (compared to production) could be putting your compiled slug size over the limit.Schultz
@Schultz I have no gems specified just for staging. Lukas- I am trying that out now and will let you know if it works.Marela
@LukasEklund that seemed to work for me, thank you! If you add this as an answer, I will mark it as correct.Marela
W
20

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
Wrongdoing answered 12/5, 2015 at 20:13 Comment(2)
repo:rebuild seems to be gone now. 'reset' exists thoughTransact
if you havent installed the plugin be sure to run heroku plugins:install heroku-repo first :)Irina
F
8

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
Fustigate answered 28/12, 2015 at 17:52 Comment(0)
F
1

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.

Floatstone answered 21/6 at 12:11 Comment(0)
F
0

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

Fitted answered 22/5, 2021 at 14:32 Comment(0)
V
0

This worked for me:

$ heroku repo:gc -a appname

$ heroku repo:purge_cache -a appname

$ heroku repo:reset -a appname

Venial answered 27/5, 2021 at 8:22 Comment(0)
P
0

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.
Peepul answered 20/9, 2021 at 21:20 Comment(0)
H
0

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).

Hepta answered 18/5, 2022 at 11:38 Comment(0)
C
0

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!

Cauthen answered 31/8, 2022 at 10:57 Comment(0)
C
-1

I was able to fix this by running git gc.

Chacon answered 23/7, 2015 at 14:40 Comment(3)
...for one of my apps. The other required @Lukas Eklund's answer.Chacon
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.Catching
@NickM I did follow a different route than the previous answerer. I have changed the post's diction to reflect this. Thanks for the heads up.Chacon

© 2022 - 2024 — McMap. All rights reserved.