Skip to content

Instantly share code, notes, and snippets.

@drapergeek
Created August 25, 2016 17:22
Show Gist options
  • Save drapergeek/23b3640dd0acf1a6dad490fb2e5b41a1 to your computer and use it in GitHub Desktop.
Save drapergeek/23b3640dd0acf1a6dad490fb2e5b41a1 to your computer and use it in GitHub Desktop.
Common Files for Phoenix App - CircleCI, Setup & Deploy
machine:
environment:
PATH: "$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH"
pre:
- sudo curl --output /usr/local/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1
dependencies:
cache_directories:
- ~/.asdf
- ~/.node_modules
- deps
- _build
pre:
- if ! asdf | grep version; then git clone https://github.com/HashNuke/asdf.git ~/.asdf; fi
- asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git || true
- asdf plugin-add elixir https://github.com/HashNuke/asdf-elixir.git || true
- bin/setup
post:
- brunch build
test:
override:
- bin/test_suite
deployment:
staging:
branch: master
commands:
- bin/deploy staging
experimental:
notify:
branches:
only:
- master
#!/bin/sh
# Run this script to deploy the app to Heroku.
set -e
branch="$(git symbolic-ref HEAD --short)"
target="${1:-staging}"
git push "$target" "$branch:master"
heroku run "POOL_SIZE=2 mix ecto.migrate" --exit-code --remote "$target"
heroku restart --remote "$target"
#!/usr/bin/env sh
# Exit if any subcommand fails
set -e
# set up environment variables if not set up yet
if [ ! -f .env ]; then
echo "Copying .env file"
cp .sample.env .env
fi
# check if phantomjs is installed
if ! command -v phantomjs >/dev/null; then
echo "You must install PhantomJS 2.x before continuing."
exit 1
else
phantomjs_version=$(phantomjs -v)
major_version="${phantomjs_version%.*.*}"
if ((major_version < 2)); then
echo "Please update your PhantomJS to 2.x before continuing."
exit 1
fi
fi
if [ -z "$CI" ]; then
echo "Removing previous build artifacts"
rm -rf deps _build
fi
asdf install
echo "Installing dependencies and compiling"
mix local.hex --force
mix local.rebar --force
mix deps.get
mix deps.compile
mix compile
# Set up database
echo "Setting up the database"
mix ecto.create
mix ecto.migrate
# Grab JS dependencies from NPM
echo "Installing npm dependencies"
npm install --progress=false
echo "Setting up Heroku and git remotes"
if [ -z "$CI" ]; then
heroku join --app appname-staging || true
fi
if ! git config remote.staging.url > /dev/null; then
# It's important to use the `git@` url here. If you use the HTTP URL
# Heroku requires a `heroku login` which is not authenticated through
# CircleCI by default
git remote add staging git@heroku.com:appname-staging.git > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment