diff --git a/README.md b/README.md index d9e40ca..c77589b 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ ## Features * **Easy configuration** with `elixir_buildpack.config` file +* Automatic elixir and erlang version detection if you are using asdf * Use **prebuilt Elixir binaries** * Allows configuring Erlang * If your app doesn't have a Procfile, default web task `mix run --no-halt` will be run. @@ -14,7 +15,7 @@ #### Version support * Erlang - Prebuilt packages (17.5, 17.4, etc) - * The full list of prebuilt packages can be found here: + * 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 @@ -28,7 +29,7 @@ Note: you should choose an Elixir and Erlang version that are [compatible with o * Cloud Native users should use [this buildpack](https://github.com/elixir-buildpack/cloud-native-buildpack) -**This buildpack is not guaranteed to be Cloud Native compatible.** +**This buildpack is not guaranteed to be Cloud Native compatible.** The [elixir-buildpack/cloud-native-buildpack](https://github.com/elixir-buildpack/cloud-native-buildpack) is a buildpack that is actively under development and is designed specifically to follow the Cloud Native Buildpack conventions. @@ -70,7 +71,7 @@ https://github.com/HashNuke/heroku-buildpack-elixir.git#883f33e10879b4b8b030753c #### Using Heroku CI -This buildpack supports Heroku CI. +This buildpack supports Heroku CI. * To enable viewing test runs on Heroku, add [tapex](https://github.com/joshwlewis/tapex) to your project. * To detect compilation warnings use the `hook_compile` configuration option set to `mix compile --force --warnings-as-errors`. @@ -130,8 +131,9 @@ test_args="--cover" #### Migrating from previous build pack -the following has been deprecated and should be removed from `elixir_buildpack.config`: -``` +The following has been deprecated and should be removed from `elixir_buildpack.config`: + +```shell # Export heroku config vars config_vars_to_export=(DATABASE_URL) ``` @@ -140,13 +142,13 @@ config_vars_to_export=(DATABASE_URL) * Use prebuilt Elixir release -``` +```shell elixir_version=1.2.0 ``` * Use prebuilt Elixir branch, the *branch* specifier ensures that it will be downloaded every time -``` +```shell elixir_version=(branch master) ``` @@ -154,7 +156,7 @@ elixir_version=(branch master) * You can specify an Erlang release version like below -``` +```shell erlang_version=18.2.1 ``` @@ -196,12 +198,14 @@ heroku config:set MY_VAR=the_value ## Testing To run tests -``` + +```shell git clone https://github.com/HashNuke/heroku-buildpack-elixir export BUILDPACK="$(pwd)/heroku-buildpack-elixir" git clone https://github.com/jesseshieh/heroku-buildpack-testrunner git clone https://github.com/jesseshieh/shunit2 export SHUNIT_HOME="$(pwd)/shunit2" + cd heroku-buildpack-testrunner bin/run $BUILDPACK ``` diff --git a/bin/compile b/bin/compile index 221003d..3daa784 100755 --- a/bin/compile +++ b/bin/compile @@ -25,6 +25,7 @@ source ${build_pack_path}/lib/elixir_funcs.sh source ${build_pack_path}/lib/app_funcs.sh source ${build_pack_path}/lib/canonical_version.sh +rm -rf $(build_platform_tools_path) mkdir $(build_platform_tools_path) export_env_vars diff --git a/lib/misc_funcs.sh b/lib/misc_funcs.sh index 2e5f95c..8edaf9f 100644 --- a/lib/misc_funcs.sh +++ b/lib/misc_funcs.sh @@ -53,10 +53,28 @@ function assert_elixir_version_set() { fi } +function asdf_extract_versions() { + local file=$1 + local line + + # Initialize as empty + local elixir_version_raw="" + + while IFS= read -r line; do + if [[ $line == erlang* ]]; then + erlang_version="${line#erlang }" + elif [[ $line == elixir* ]]; then + elixir_version_raw="${line#elixir }" + elixir_version="${elixir_version_raw%-otp*}" + fi + done < "$file" +} + function load_config() { output_section "Checking Erlang and Elixir versions" local custom_config_file="${build_path}/elixir_buildpack.config" + local custom_asdf_file="${build_path}/.tool-versions" # Source for default versions file from buildpack first source "${build_pack_path}/elixir_buildpack.config" @@ -64,12 +82,15 @@ function load_config() { if [ -f $custom_config_file ]; then source $custom_config_file + assert_elixir_version_set $custom_config_file + elif [ -f $custom_asdf_file ]; then + echo "asdf file found, extracting versions from source" + asdf_extract_versions $custom_asdf_file else output_line "Sorry, an elixir_buildpack.config is required. Please see https://github.com/HashNuke/heroku-buildpack-elixir#configuration" exit 1 fi - assert_elixir_version_set $custom_config_file fix_erlang_version fix_elixir_version