Skip to content

Instantly share code, notes, and snippets.

@raysegantii
Forked from joakimk/README.md
Last active October 15, 2016 02:43
Show Gist options
  • Save raysegantii/45fed758b68b5738798328aaa86cbcbd to your computer and use it in GitHub Desktop.
Save raysegantii/45fed758b68b5738798328aaa86cbcbd 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.

2016-10-11: Forked and refactored a few lines.

machine:
environment:
MIX_ENV: test
PATH: $HOME/dependencies/erlang/bin:$HOME/dependencies/elixir/bin:$PATH
dependencies:
pre:
- test/ci/prepare.sh
cache_directories:
- ~/dependencies
- ~/.mix
- _build
- deps
test:
override:
- mix test
post:
- mix credo
#!/bin/bash -e
# Forked from: https://gist.github.com/joakimk/48ed80f1a7adb5f5ea27
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"
export ERLANG_PATH="$INSTALL_PATH/otp_src_$ERLANG_VERSION"
export ELIXIR_PATH="$INSTALL_PATH/elixir_$ELIXIR_VERSION"
mkdir -p $INSTALL_PATH
cd $INSTALL_PATH
# Install erlang
if [ ! -e $ERLANG_PATH/bin/erl ]; then
curl -L -O http://www.erlang.org/download/otp_src_$ERLANG_VERSION.tar.gz
tar xzf otp_src_$ERLANG_VERSION.tar.gz
cd $ERLANG_PATH
./configure --enable-smp-support \
--enable-m64-build \
--disable-native-libs \
--disable-sctp \
--enable-threads \
--enable-kernel-poll \
--disable-hipe \
--without-javac
make
# Symlink to make it easier to setup PATH to run tests
ln -sf $ERLANG_PATH $INSTALL_PATH/erlang
fi
# Install Elixir
if [ ! -e $ELIXIR_PATH/bin/elixir ]; then
git clone https://github.com/elixir-lang/elixir $ELIXIR_PATH
cd $ELIXIR_PATH
git checkout $ELIXIR_VERSION
make
# Symlink to make it easier to setup PATH to run tests
ln -sf $ELIXIR_PATH $INSTALL_PATH/elixir
fi
# Install package tools
[ -e $HOME/.mix/rebar ] || mix do local.hex --force, local.rebar --force
# Fetch and compile dependencies and application code (and include testing tools)
cd $HOME/$CIRCLE_PROJECT_REPONAME
mix do deps.get, deps.compile, compile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment