Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asdf elixir and erlang version detection #216

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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)
```
Expand All @@ -140,21 +142,21 @@ 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)
```

#### Specifying Erlang version

* You can specify an Erlang release version like below

```
```shell
erlang_version=18.2.1
```

Expand Down Expand Up @@ -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
```
Expand Down
1 change: 1 addition & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion lib/misc_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,44 @@ 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"

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

Expand Down