Skip to content

Instantly share code, notes, and snippets.

Last active January 1, 2022 23:21
Show Gist options
  • Save joakimk/48ed80f1a7adb5f5ea27 to your computer and use it in GitHub Desktop.
Save joakimk/48ed80f1a7adb5f5ea27 to your computer and use it in GitHub Desktop.
CircleCI elixir build example

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible.

We've been using this for months in multiple projects without any issues. Please ping be if there is any issues with this script and I'll update it.

It should be generic enough to work on any elixir app using mix.

If you have a elixir_buildpack.config, then enable that section in the build script to keep versions in sync!

2016-08-09: Updated to newer Erlang and Elixir and fixed curl command.

- script/ci/
- ~/dependencies
- ~/.mix
- _build
- deps
- script/ci/
# NOTE: Keep in mind that this script does not verify the shasum of the downloads.
# NOTE: Don't forget to make this file executable or the build won't run
set -e
export ERLANG_VERSION="19.0"
export ELIXIR_VERSION="v1.3.2"
# If you have a elixir_buildpack.config, do this instead:
#export ERLANG_VERSION=$(cat elixir_buildpack.config | grep erlang_version | tr "=" " " | awk '{ print $2 }')
#export ELIXIR_VERSION=v$(cat elixir_buildpack.config | grep elixir_version | tr "=" " " | awk '{ print $2 }')
export INSTALL_PATH="$HOME/dependencies"
mkdir -p $INSTALL_PATH
# Install erlang
if [ ! -e $ERLANG_PATH/bin/erl ]; then
curl -L -O$ERLANG_VERSION.tar.gz
tar xzf otp_src_$ERLANG_VERSION.tar.gz
./configure --enable-smp-support \
--enable-m64-build \
--disable-native-libs \
--disable-sctp \
--enable-threads \
--enable-kernel-poll \
--disable-hipe \
# Symlink to make it easier to setup PATH to run tests
# Install elixir
export PATH="$ERLANG_PATH/bin:$PATH"
if [ ! -e $ELIXIR_PATH/bin/elixir ]; then
git clone $ELIXIR_PATH
git checkout $ELIXIR_VERSION
# Symlink to make it easier to setup PATH to run tests
# Install package tools
if [ ! -e $HOME/.mix/rebar ]; then
yes Y | LC_ALL=en_GB.UTF-8 mix local.hex
yes Y | LC_ALL=en_GB.UTF-8 mix local.rebar
# If you use Elm:
# 1) add the code below
# 2) run the Elm build like this " ~/dependencies/sysconfcpus/bin/sysconfcpus -n 2 node_modules/brunch/bin/brunch build"
# 3) your Elm builds will finish in seconds instead of minutes
# For more info see:
#if [ ! -d $INSTALL_PATH/sysconfcpus/bin ]; then
# git clone
# cd libsysconfcpus
# ./configure --prefix=$INSTALL_PATH/sysconfcpus
# make && make install
# cd ..
# Fetch and compile dependencies and application code (and include testing tools)
export MIX_ENV="test"
mix do deps.get, deps.compile, compile
export MIX_ENV="test"
export PATH="$HOME/dependencies/erlang/bin:$HOME/dependencies/elixir/bin:$PATH"
mix test
Copy link

ubernil commented Feb 12, 2016

I had to change script/ci/ to bash script/ci/, as I got bash: line 1: script/ci/ Permission denied Action failed: script/ci/
Also, -L to the curl command helped to solve gzip: stdin: not in gzip format

Copy link

ArturT commented Feb 15, 2016

@ubernil You probably forgot to set chmod executable on those sh files.

Copy link

jcortesg commented Feb 17, 2016

@joakimk You need -L: curl -OL$ERLANG_VERSION.tar.gz

Copy link

cdale77 commented Mar 4, 2016

Thanks! In case it helps others, this is what I did with erlang 18.2.1 and elixir 1.2.3:
-change the script names to and and put them in the app root
-used the -L switch for curl
-my circle.yml calls the scripts thusly: - ./

Copy link

thbar commented Apr 28, 2016

Indeed --location seems required today. Thanks for your script!

Copy link

thbar commented Apr 30, 2016

Changes required to get formatted test output on CircleCI can be found here.

The part below is what was a bit harder to find:

    - script/ci/
    - mkdir -p $CIRCLE_TEST_REPORTS/exunit
    - cp _build/test/test-junit-report.xml $CIRCLE_TEST_REPORTS/exunit

Copy link

jc00ke commented May 17, 2016

@thbar thanks!

Copy link

aerosol commented Jul 6, 2016

Hi @joakimk, isn't it recompiling Erlang every time you push a new branch?

Copy link

alexparker commented Jul 8, 2016

Seems the download is failing for me related to gzip format. I can run the curl locally just fine

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

100   184  100   184    0     0    539      0 --:--:-- --:--:-- --:--:--  1628

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

script/ci/ returned exit code 2

Action failed: script/ci/

adding -L option to curl solved it. The location had a 301 redirect on it.

Copy link

joakimk commented Aug 9, 2016

@aerosol I don't use branches very much, but that might be the case. How would you work around that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment