Makefile:
build-release:
echo "Make sure you bumped the version in mix.exs"
$(eval VERSION := $(shell sed -n '/version:/s/ *version: "\(.*\)",/\1/p' mix.exs))
sleep 3
mix deps.get
cd assets && ./node_modules/brunch/bin/brunch b -p
MIX_ENV=prod mix phx.digest
docker run -it -v `pwd`:/src --rm --workdir /src -e MIX_ENV=prod erlang-builder mix do deps.clean comeonin, deps.get, compile, release --env=prod
release:
$(eval VERSION := $(shell sed -n '/version:/s/ *version: "\(.*\)",/\1/p' mix.exs))
ssh [email protected] "mkdir /your_app_new"
scp _build/prod/rel/your_app/releases/$(VERSION)/your_app.tar.gz [email protected]:/your_app_new/
ssh [email protected] "cd /var/www/your_app && ./bin/your_app stop"
ssh [email protected] "mv /var/www/your_app /your_app_old"
ssh [email protected] "mv /your_app_new /var/www/your_app"
ssh [email protected] "cd /var/www/your_app && tar xzf your_app.tar.gz"
ssh [email protected] "cd /var/www/your_app && PORT=4000 ./bin/your_app start"
ssh [email protected] "rm -rf /your_app_old"
builder:
cd docker && docker build -t erlang-builder .
Dockerfile:
# Builds an image with erlang and elixir installed
# that matches our production system so the right
# libraries are in place when building releases
FROM ubuntu:16.04
ENV CACHE_BUST 20171114_1053
RUN apt-get update && apt-get install -y apt-transport-https
RUN apt-get install locales && locale-gen en_US.UTF-8
RUN apt-get install -y build-essential git-all wget
RUN wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
RUN dpkg -i erlang-solutions_1.0_all.deb
RUN apt-get update && apt-get install -y erlang elixir
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LANGUAGE en_US:en
RUN mix local.hex --force
RUN mix local.rebar --force
Release.Tasks
defmodule Release.Tasks do
alias Hearthdecks.Tasks.CardUpload
def migrate do
{:ok, _path} = Application.ensure_all_started(:hearthdecks)
path = Application.app_dir(:hearthdecks, "priv/repo/migrations")
Ecto.Migrator.run(Hearthdecks.Repo, path, :up, all: true)
end
def update do
{:ok, _path} = Application.ensure_all_started(:hearthdecks)
path = Application.app_dir(:hearthdecks, "priv/repo/migrations")
Ecto.Migrator.run(Hearthdecks.Repo, path, :up, all: true)
CardUpload.run()
end
end
post_start hook:
set +e
echo "post_start hook"
while true; do
nodetool ping
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "Application is up!"
break
fi
done
set -e
echo "Running migrations"
/var/www/hearthdecks/bin/hearthdecks rpc Elixir.Release.Tasks update
echo "migrations complete"