Skip to content

Instantly share code, notes, and snippets.

@obmarg
Forked from joakimk/README.md
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obmarg/6911fd9d395f19116f99 to your computer and use it in GitHub Desktop.
Save obmarg/6911fd9d395f19116f99 to your computer and use it in GitHub Desktop.

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible. It's not been run for very long so I don't know if it caches too much or of there is any other issues.

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

dependencies:
pre:
- script/ci/prepare.sh
cache_directories:
- ~/bin
- ~/dependencies
- ~/.mix
- _build
- deps
test:
override:
- mix test
#!/bin/bash
set -e
export ERLANG_VERSION="17.1"
export ELIXIR_VERSION="v1.0.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"
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 -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
export PATH="$ERLANG_PATH/bin:$PATH"
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
export PATH="$ERLANG_PATH/bin:$ELIXIR_PATH/bin:$PATH"
# 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
fi
# Fetch and compile dependencies and application code (and include testing tools)
export MIX_ENV="test"
cd $HOME/$CIRCLE_PROJECT_REPONAME
mix do deps.get, deps.compile, compile
# Link elixir & erlang binaries into /home/ubuntu/bin to avoid needing to modify PATH variable
ln -f -s /home/ubuntu/dependencies/erlang/bin/* /home/ubuntu/bin/
ln -f -s /home/ubuntu/dependencies/elixir/bin/* /home/ubuntu/bin/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment