Slug Compiler
Table of Contents
Slugs are compressed packages optimized for lightning-fast distribution across the dyno manifold.
When you git push to Heroku, your code is received by the slug compiler, which transforms your repository into a slug.
Compilation
The slug compiler is invoked by a git pre-receive hook, which follows these steps:
- Create a fresh checkout of HEAD from the master branch.
- Download, build, and install local dependencies as specified in your build file (e.g. Gemfile,
package.json,requirements.txt, etc.) - Remove unused files, including the
.gitdirectory, anything inlogandtmp, local build dependencies such as .gem files in the bundledgemsdirectory, and anything specified in.slugignore. - Write the environment into the slug. (The slug is rebuilt any time a config var or add-on is changed)
- Package into the final slug archive.
Ignoring Files
If your repository contains files not necessary to run your app, you may wish to add these to a .slugignore file in the root of your repository. Examples of files you may wish to exclude from the slug:
- Unit tests or specs
- Art sources (like .psd files)
- Design documents (like .pdf files)
- Test data
The format is roughly similar to .gitignore. Here’s an example .slugignore:
*.psd
*.pdf
test
spec
Slug Size
Your slug size is displayed at the end of a successful compile. You can roughly estimate slug size locally by doing a fresh checkout of your app, deleting the .git directory, and running du -hsc.
Smaller slugs can be transferred across the dyno grid more quickly, allowing for a faster spin-up speed on your dynos. Generally speaking, any slug under 15MB is small and nimble; 30MB is average; and 40MB or above is weighty. If you find your app getting into the 40MB+ range, you may want to look into some techniques (such as removing unneeded dependencies or excluding files via .slugignore) to reduce the size.