Skip to content

Commit

Permalink
Deploy with a mix release in a Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtaylor committed Jun 7, 2020
1 parent 0dd9eca commit b6de055
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 124 deletions.
18 changes: 5 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# The version of Alpine to use for the final image
# This should match the version of Alpine that the `elixir:1.8.1-alpine` image uses
ARG ALPINE_VERSION=3.9
ARG ALPINE_VERSION=3.11

FROM tomtaylor/elixir:1.8.1-erlang-21.2.7 AS builder
FROM elixir:1.10.3-alpine AS builder

# The environment to build with
ARG MIX_ENV=prod
Expand All @@ -25,15 +25,7 @@ RUN apk update && \

COPY . .

RUN mix do deps.get, deps.compile, compile

RUN \
mkdir -p /opt/built && \
mix release --verbose --warnings-as-errors && \
cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VSN}/${APP_NAME}.tar.gz /opt/built && \
cd /opt/built && \
tar -xzf ${APP_NAME}.tar.gz && \
rm ${APP_NAME}.tar.gz
RUN mix do deps.get, deps.compile, compile, release

# From this line onwards, we're in a new image, which will be the image used in production
FROM alpine:${ALPINE_VERSION}
Expand All @@ -52,6 +44,6 @@ ENV REPLACE_OS_VARS=true \

WORKDIR /opt/app

COPY --from=builder /opt/built .
COPY --from=builder /opt/app/_build/${MIX_ENV}/rel/${APP_NAME} .

CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} foreground
CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} start
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use Mix.Config
import Config
2 changes: 1 addition & 1 deletion config/prod.exs.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :lowflyingrocks, import_interval: 3600
config :lowflyingrocks, perform_tweets: true
Expand Down
11 changes: 11 additions & 0 deletions config/releases.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Config

config :lowflyingrocks, import_interval: 3600
config :lowflyingrocks, perform_tweets: true

config :extwitter, :oauth, [
consumer_key: "",
consumer_secret: "",
access_token: "",
access_token_secret: ""
]
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use Mix.Config
import Config

config :lowflyingrocks, import_interval: 3600
15 changes: 10 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ defmodule LowFlyingRocks.Mixfile do
[
app: :lowflyingrocks,
version: "0.1.0",
elixir: "~> 1.7",
elixir: "~> 1.9",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps()
deps: deps(),
releases: [
lowflyingrocks: [
include_executables_for: [:unix],
applications: [runtime_tools: :permanent]
]
]
]
end

Expand All @@ -21,10 +27,9 @@ defmodule LowFlyingRocks.Mixfile do
{:timex, "~> 3.5"},
{:poison, "~> 3.0"},
{:httpotion, "~> 3.0"},
{:number, "~> 0.5.0"},
{:number, "~> 1.0"},
{:oauth, github: "tim/erlang-oauth"},
{:extwitter, "~> 0.7"},
{:distillery, "~> 2.0.0"}
{:extwitter, "~> 0.7"}
]
end
end
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},
"conform": {:hex, :conform, "0.16.0", "f6d6b207c693f2f939af8edeab7c735c4fd48552c63c0a019a52b6d2d98a1ca4", [:mix], [{:neotoma, "~> 1.7.3", [hex: :neotoma, optional: false]}]},
"decimal": {:hex, :decimal, "1.3.1", "157b3cedb2bfcb5359372a7766dd7a41091ad34578296e951f58a946fcab49c6", [:mix], [], "hexpm", "94f7e657875648bc9ac747726eaae05c11cebff2dd01b2f807c7ab822a857786"},
"decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"},
"distillery": {:hex, :distillery, "2.0.12", "6e78fe042df82610ac3fa50bd7d2d8190ad287d120d3cd1682d83a44e8b34dfb", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "ad094bfbbd69a39f6118265bc7d76a56534df9af2f06aca0d3fd03e1220fbe31"},
"edeliver": {:hex, :edeliver, "1.4.0", "c1713b3fabfa75d64770a28b715379be6631442b5d288fc92d45e037757dc9c8", [:mix], [{:distillery, ">= 0.8.0", [hex: :distillery, optional: true]}, {:exrm, ">= 0.16.0", [hex: :exrm, optional: true]}]},
"erlware_commons": {:hex, :erlware_commons, "0.13.0", "b86d493f3c3e52acba16f0a78900c12525e9eb46db3450b0d25b419aa8221115", [:rebar], []},
Expand All @@ -21,7 +21,7 @@
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], []},
"neotoma": {:hex, :neotoma, "1.7.3", "d8bd5404b73273989946e4f4f6d529e5c2088f5fa1ca790b4dbe81f4be408e61", [:rebar], []},
"number": {:hex, :number, "0.5.0", "52047c6db2168ecba7e4fc3c2b93c4f7366283dec8792eaae33de7c4c7f0efe4", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "bc212a818e452660f226c43b344f12f22d62777361cd63108397f9ca9aab14e9"},
"number": {:hex, :number, "1.0.1", "a1017dc867a9860b0c261bf9f3ac4990f64589dbbe50260724190c78a0b92104", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "149c62771306451198b2a044b4f077520c9acf6e69304723b17385257c683b52"},
"oauth": {:git, "https://github.com/tim/erlang-oauth.git", "bd19896e31125f99ff45bb5850b1c0e74b996743", []},
"oauther": {:hex, :oauther, "1.1.1", "7d8b16167bb587ecbcddd3f8792beb9ec3e7b65c1f8ebd86b8dd25318d535752", [:mix], [], "hexpm", "9374f4302045321874cccdc57eb975893643bd69c3b22bf1312dab5f06e5788e"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
Expand Down
62 changes: 0 additions & 62 deletions rel/config.exs

This file was deleted.

5 changes: 0 additions & 5 deletions rel/config/config.exs

This file was deleted.

6 changes: 6 additions & 0 deletions rel/env.bat.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off
rem Set the release to work across nodes. If using the long name format like
rem the one below (my_app@127.0.0.1), you need to also uncomment the
rem RELEASE_DISTRIBUTION variable below. Must be "sname", "name" or "none".
rem set RELEASE_DISTRIBUTION=name
rem set RELEASE_NODE=<%= @release.name %>@127.0.0.1
18 changes: 18 additions & 0 deletions rel/env.sh.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# Sets and enables heart (recommended only in daemon mode)
# case $RELEASE_COMMAND in
# daemon*)
# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND"
# export HEART_COMMAND
# export ELIXIR_ERL_OPTIONS="-heart"
# ;;
# *)
# ;;
# esac

# Set the release to work across nodes. If using the long name format like
# the one below (my_app@127.0.0.1), you need to also uncomment the
# RELEASE_DISTRIBUTION variable below. Must be "sname", "name" or "none".
# export RELEASE_DISTRIBUTION=name
# export RELEASE_NODE=<%= @release.name %>@127.0.0.1
33 changes: 0 additions & 33 deletions rel/vm.args

This file was deleted.

11 changes: 11 additions & 0 deletions rel/vm.args.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Customize flags given to the VM: http://erlang.org/doc/man/erl.html
## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here

## Number of dirty schedulers doing IO work (file, sockets, and others)
##+SDio 5

## Increase number of concurrent ports/sockets
##+Q 65536

## Tweak GC to run more often
##-env ERL_FULLSWEEP_AFTER 10

0 comments on commit b6de055

Please sign in to comment.