HashNuke/heroku-buildpack-elixir
{ "createdAt": "2014-02-12T18:02:09Z", "defaultBranch": "master", "description": "Heroku Buildpack for Elixir with nitro boost", "fullName": "HashNuke/heroku-buildpack-elixir", "homepage": "", "language": "Shell", "name": "heroku-buildpack-elixir", "pushedAt": "2024-05-01T00:20:51Z", "stargazersCount": 816, "topics": [ "elixir", "heroku-buildpack" ], "updatedAt": "2025-08-15T09:28:57Z", "url": "https://github.com/HashNuke/heroku-buildpack-elixir"}Heroku Buildpack for Elixir
Section titled “Heroku Buildpack for Elixir”Features
Section titled “Features”- Easy configuration with
elixir_buildpack.configfile - Use prebuilt Elixir binaries
- Allows configuring Erlang
- If your app doesn’t have a Procfile, default web task
mix run --no-haltwill be run. - Consolidates protocols
- Hex and rebar support
- Caching of Hex packages, Mix dependencies and downloads
- Compilation procedure hooks through
hook_pre_compile,hook_compile,hook_post_compileconfiguration
Version support
Section titled “Version support”- Erlang - Prebuilt packages (17.5, 17.4, etc)
- The full list of prebuilt packages can be found here:
- gigalixir-20 or heroku-20 stacks: https://builds.hex.pm/builds/otp/ubuntu-20.04/builds.txt
- heroku-22 stacks: https://builds.hex.pm/builds/otp/ubuntu-22.04/builds.txt
- All other stacks: https://github.com/HashNuke/heroku-buildpack-elixir-otp-builds/blob/master/otp-versions
- The full list of prebuilt packages can be found here:
- Elixir - Prebuilt releases (1.0.4, 1.0.3, etc) or prebuilt branches (master, v1.7, etc)
- The full list of releases can be found here: https://github.com/elixir-lang/elixir/releases
- The full list of branches can be found here: https://github.com/elixir-lang/elixir/branches
Note: you should choose an Elixir and Erlang version that are compatible with one another.
Cloud Native Support
Section titled “Cloud Native Support”- Cloud Native users should use this buildpack
This buildpack is not guaranteed to be Cloud Native compatible. The elixir-buildpack/cloud-native-buildpack is a buildpack that is actively under development and is designed specifically to follow the Cloud Native Buildpack conventions.
Create a Heroku app with this buildpack
Section titled “Create a Heroku app with this buildpack”heroku create --buildpack hashnuke/elixirSet the buildpack for an existing Heroku app
Section titled “Set the buildpack for an existing Heroku app”heroku buildpacks:set hashnuke/elixirUse the edge version of buildpack
Section titled “Use the edge version of buildpack”The hashnuke/elixir buildpack contains the latest published version of the buildpack, but you can use the edge version (i.e. the source code in this repo) by running:
heroku buildpacks:set https://github.com/HashNuke/heroku-buildpack-elixir.gitWhen you decide to use the published or the edge version of the buildpack you should be aware that, although we attempt to maintain the buildpack for as many old Elixir and Erlang releases as possible, it is sometimes difficult since there’s a matrix of 3 variables involved: Erlang version, Elixir version and Heroku stack. If your application cannot be updated for some reason and requires an older version of the buildpack then [use a specific version of buildpack]!(#use-a-specific-version-of-buildpack).
Use a specific version of buildpack
Section titled “Use a specific version of buildpack”The methods above always use the latest version of the buildpack code. To use a specific version of the buildpack, choose a commit from the commits page. The commit SHA forms part of your buildpack url.
For example, if you pick the commit “883f33e10879b4b8b030753c13aa3d0dda82e1e7”, then the buildpack url for your app would be:
https://github.com/HashNuke/heroku-buildpack-elixir.git#883f33e10879b4b8b030753c13aa3d0dda82e1e7It is recommended to use a buildpack url with a commit SHA on production apps. This prevents the unpleasant moment when your Heroku build fails because the buildpack you use just got updated with a breaking change. Having buildpacks pinned to a specific version is like having your Hex packages pinned to a specific version in mix.lock.
Using Heroku CI
Section titled “Using Heroku CI”This buildpack supports Heroku CI.
- To enable viewing test runs on Heroku, add tapex to your project.
- To detect compilation warnings use the
hook_compileconfiguration option set tomix compile --force --warnings-as-errors.
Elixir Releases
Section titled “Elixir Releases”This buildpack can optionally build an Elixir release. The release build will be run after hook_post_compile.
WARNING: If you need to do further compilation using another buildpack, such as the Phoenix static buildpack, you probably don’t want to use this option. See the Elixir release buildpack instead.
To build and use a release for an app called foo compiled with MIX_ENV=prod:
- Make sure
elixir_versioninelixir_buildpack.configis at least 1.9 - Add
release=truetoelixir_buildpack.config - Use
web: _build/prod/rel/foo/bin/foo startin your Procfile
NOTE: This requires the master version of the buildpack (or a commit later than 7d369c)
Configuration
Section titled “Configuration”Create a elixir_buildpack.config file in your app’s root dir. The file’s syntax is bash.
If you don’t specify a config option, then the default option from the buildpack’s elixir_buildpack.config file will be used.
Here’s a full config file with all available options:
# Erlang versionerlang_version=18.2.1
# Elixir versionelixir_version=1.2.0
# Always rebuild from scratch on every deploy?always_rebuild=false
# Create a release using `mix release`? (requires Elixir 1.9)release=true
# A command to run right before fetching dependencieshook_pre_fetch_dependencies="pwd"
# A command to run right before compiling the app (after elixir, .etc)hook_pre_compile="pwd"
hook_compile="mix compile --force --warnings-as-errors"
# A command to run right after compiling the apphook_post_compile="pwd"
# Set the path the app is run fromruntime_path=/app
# Enable or disable additional test argumentstest_args="--cover"Migrating from previous build pack
Section titled “Migrating from previous build pack”the following has been deprecated and should be removed from elixir_buildpack.config:
# Export heroku config varsconfig_vars_to_export=(DATABASE_URL)Specifying Elixir version
Section titled “Specifying Elixir version”- Use prebuilt Elixir release
elixir_version=1.2.0- Use prebuilt Elixir branch, the branch specifier ensures that it will be downloaded every time
elixir_version=(branch master)Specifying Erlang version
Section titled “Specifying Erlang version”- You can specify an Erlang release version like below
erlang_version=18.2.1Specifying config vars to export at compile time
Section titled “Specifying config vars to export at compile time”- To set a config var on your heroku node you can exec from the shell:
heroku config:set MY_VAR=the_valueOther notes
Section titled “Other notes”-
Add your own
Procfileto your application, else the default web taskmix run --no-haltwill be used. -
Your application should build embedded and start permanent. Build embedded will consolidate protocols for a performance boost, start permanent will ensure that Heroku restarts your application if it crashes. See below for an example of how to use these features in your Mix project:
defmodule MyApp.Mixfile douse Mix.Projectdef project do[app: :my_app,version: "0.0.1",build_embedded: Mix.env == :prod,start_permanent: Mix.env == :prod]endend -
The buildpack will execute the commands configured in
hook_pre_compileand/orhook_post_compilein the root directory of your application before/after it has been compiled (respectively). These scripts can be used to build or prepare things for your application, for example compiling assets. -
The buildpack will execute the commands configured in
hook_pre_fetch_dependenciesin the root directory of your application before it fetches the application dependencies. This script can be used to clean certain dependencies before fetching new ones.
Development
Section titled “Development”- Build scripts to build erlang are at https://github.com/HashNuke/heroku-buildpack-elixir-otp-builds
- Sample app to test is available at https://github.com/HashNuke/heroku-buildpack-elixir-test
Testing
Section titled “Testing”To run tests
git clone https://github.com/HashNuke/heroku-buildpack-elixirexport BUILDPACK="$(pwd)/heroku-buildpack-elixir"git clone https://github.com/jesseshieh/heroku-buildpack-testrunnergit clone https://github.com/jesseshieh/shunit2export SHUNIT_HOME="$(pwd)/shunit2"cd heroku-buildpack-testrunnerbin/run $BUILDPACKSee more info at https://github.com/jesseshieh/heroku-buildpack-testrunner/blob/master/README.md
Credits
Section titled “Credits”© Akash Manohar under The MIT License. Feel free to do whatever you want with it.