Skip to content

Commit

Permalink
Build Docker image using a distillery release
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtaylor committed May 8, 2019
1 parent 28f5b55 commit ca09fd9
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 60 deletions.
18 changes: 0 additions & 18 deletions .deliver/config

This file was deleted.

10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_build/
deps/
.git/
.gitignore
Dockerfile
README*
test/
.elixir_ls
.vscode
_build
57 changes: 57 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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

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

# The environment to build with
ARG MIX_ENV=prod

ENV APP_NAME="lowflyingrocks" \
APP_VSN="0.1.0" \
MIX_ENV=${MIX_ENV}

# By convention, /opt is typically used for applications
WORKDIR /opt/app

# This step installs all the build tools we'll need
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
git \
build-base && \
mix local.rebar --force && \
mix local.hex --force

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

# From this line onwards, we're in a new image, which will be the image used in production
FROM alpine:${ALPINE_VERSION}

# We need python, curl, openssh and procps for Heroku ps:exec to work
RUN apk update && \
apk add --no-cache \
bash \
openssl-dev \
curl

ENV REPLACE_OS_VARS=true \
LANG=en_US.UTF-8 \
APP_NAME="lowflyingrocks" \
MIX_ENV=prod

WORKDIR /opt/app

COPY --from=builder /opt/built .

CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} foreground
30 changes: 13 additions & 17 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,29 @@ defmodule LowFlyingRocks.Mixfile do
use Mix.Project

def project do
[app: :lowflyingrocks,
version: "0.1.0",
elixir: "~> 1.4",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps()]
[
app: :lowflyingrocks,
version: "0.1.0",
elixir: "~> 1.7",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

def application do
[extra_applications: [:logger],
applications: [
:timex, :httpotion, :extwitter, :edeliver, :poison, :oauth, :number,
:decimal
],
mod: {LowFlyingRocks.Application, []}]
[extra_applications: [:logger], mod: {LowFlyingRocks.Application, []}]
end

defp deps do
[
{:timex, "~> 3.0"},
{:poison, "~> 2.0"},
{:httpotion, "~> 3.0.2"},
{:timex, "~> 3.5"},
{:poison, "~> 3.0"},
{:httpotion, "~> 3.0"},
{:number, "~> 0.5.0"},
{:oauth, github: "tim/erlang-oauth"},
{:extwitter, "~> 0.7"},
{:edeliver, "~> 1.4.0"},
{:distillery, ">= 0.8.0", warn_missing: false},
{:distillery, "~> 2.0.0"}
]
end
end
33 changes: 19 additions & 14 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
%{"bbmustache": {:hex, :bbmustache, "1.0.1", "6f8504fa069e6e3595593260384c6c372065dd4ead557bf5b61a2b2bbb4d80f9", [:rebar], []},
"certifi": {:hex, :certifi, "1.2.1", "c3904f192bd5284e5b13f20db3ceac9626e14eeacfbb492e19583cf0e37b22be", [:rebar3], []},
"combine": {:hex, :combine, "0.9.6", "8d1034a127d4cbf6924c8a5010d3534d958085575fa4d9b878f200d79ac78335", [:mix], []},
%{
"artificery": {:hex, :artificery, "0.2.6", "f602909757263f7897130cbd006b0e40514a541b148d366ad65b89236b93497a", [:mix], [], "hexpm"},
"bbmustache": {:hex, :bbmustache, "1.0.1", "6f8504fa069e6e3595593260384c6c372065dd4ead557bf5b61a2b2bbb4d80f9", [:rebar], []},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm"},
"conform": {:hex, :conform, "0.16.0", "f6d6b207c693f2f939af8edeab7c735c4fd48552c63c0a019a52b6d2d98a1ca4", [:mix], [{:neotoma, "~> 1.7.3", [hex: :neotoma, optional: false]}]},
"decimal": {:hex, :decimal, "1.3.1", "157b3cedb2bfcb5359372a7766dd7a41091ad34578296e951f58a946fcab49c6", [:mix], []},
"distillery": {:hex, :distillery, "1.1.0", "e9943bd29557e9c252a051d8ac4b47e597cd9bf2a74332b8628eab4954eb51d7", [:mix], []},
"distillery": {:hex, :distillery, "2.0.12", "6e78fe042df82610ac3fa50bd7d2d8190ad287d120d3cd1682d83a44e8b34dfb", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm"},
"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], []},
"exrm": {:hex, :exrm, "0.18.8", "8bc43a5da2cd54eb18fdffc6bb1608424f3897f97e816bcf752fb931c0ef1af4", [:mix], [{:conform, "~> 0.16.0", [hex: :conform, optional: false]}, {:relx, "~> 3.1.0", [hex: :relx, optional: false]}]},
"extwitter": {:hex, :extwitter, "0.7.3", "0d54031bde6b829484c7336b54fca85a0dc114c9e5b3cceb6c164c9b86fda634", [:mix], [{:poison, "~> 2.0", [hex: :poison, optional: false]}]},
"extwitter": {:hex, :extwitter, "0.9.3", "7c93305bd6928bfc3566f91d751275c9408701031e76ae9f250711d4a5e1a6a0", [:mix], [{:oauther, "~> 1.1", [hex: :oauther, repo: "hexpm", optional: false]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"floki": {:hex, :floki, "0.11.0", "b4532ab64d67225f13f5626e4ba1b8cf3ee9d5bd48017075bb975e1522efd32d", [:mix], [{:mochiweb, "~> 2.15", [hex: :mochiweb, optional: false]}]},
"getopt": {:hex, :getopt, "0.8.2", "b17556db683000ba50370b16c0619df1337e7af7ecbf7d64fbf8d1d6bce3109b", [:rebar], []},
"gettext": {:hex, :gettext, "0.13.0", "daafbddc5cda12738bb93b01d84105fe75b916a302f1c50ab9fb066b95ec9db4", [:mix], []},
"hackney": {:hex, :hackney, "1.8.6", "21a725db3569b3fb11a6af17d5c5f654052ce9624219f1317e8639183de4a423", [:rebar3], [{:certifi, "1.2.1", [hex: :certifi, optional: false]}, {:idna, "5.0.2", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"gettext": {:hex, :gettext, "0.16.1", "e2130b25eebcbe02bb343b119a07ae2c7e28bd4b146c4a154da2ffb2b3507af2", [:mix], [], "hexpm"},
"hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"httpotion": {:hex, :httpotion, "3.0.2", "525b9bfeb592c914a61a8ee31fdde3871e1861dfe805f8ee5f711f9f11a93483", [:mix], [{:ibrowse, "~> 4.2", [hex: :ibrowse, optional: false]}]},
"ibrowse": {:hex, :ibrowse, "4.2.2", "b32b5bafcc77b7277eff030ed32e1acc3f610c64e9f6aea19822abcadf681b4b", [:rebar3], []},
"idna": {:hex, :idna, "5.0.2", "ac203208ada855d95dc591a764b6e87259cb0e2a364218f215ad662daa8cd6b4", [:rebar3], [{:unicode_util_compat, "0.2.0", [hex: :unicode_util_compat, optional: false]}]},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"},
"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, optional: false]}]},
"oauth": {:git, "https://github.com/tim/erlang-oauth.git", "bd19896e31125f99ff45bb5850b1c0e74b996743", []},
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []},
"oauther": {:hex, :oauther, "1.1.1", "7d8b16167bb587ecbcddd3f8792beb9ec3e7b65c1f8ebd86b8dd25318d535752", [:mix], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"providers": {:hex, :providers, "1.4.1", "e74176b29d4771544410af5022fe1306b100d0f57c9e0f3656bcff5962f87cd2", [:rebar], [{:getopt, "0.8.2", [hex: :getopt, optional: false]}]},
"relx": {:hex, :relx, "3.1.0", "71b7e00e83543c92512d785a268db78a970fe5d811171329623784daca7d23dc", [:rebar], [{:bbmustache, "1.0.1", [hex: :bbmustache, optional: false]}, {:erlware_commons, "0.13.0", [hex: :erlware_commons, optional: false]}, {:getopt, "0.8.2", [hex: :getopt, optional: false]}, {:providers, "1.4.1", [hex: :providers, optional: false]}]},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []},
"timex": {:hex, :timex, "3.1.7", "71f9c32e13ff4860e86a314303757cc02b3ead5db6e977579a2935225ce9a666", [:mix], [{:combine, "~> 0.7", [hex: :combine, optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, optional: false]}]},
"tzdata": {:hex, :tzdata, "0.5.12", "1c17b68692c6ba5b6ab15db3d64cc8baa0f182043d5ae9d4b6d35d70af76f67b", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.2.0", "dbbccf6781821b1c0701845eaf966c9b6d83d7c3bfc65ca2b78b88b8678bfa35", [:rebar3], []}}
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
"timex": {:hex, :timex, "3.5.0", "b0a23167da02d0fe4f1a4e104d1f929a00d348502b52432c05de875d0b9cffa5", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
"tzdata": {:hex, :tzdata, "0.5.20", "304b9e98a02840fb32a43ec111ffbe517863c8566eb04a061f1c4dbb90b4d84c", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
}
42 changes: 31 additions & 11 deletions rel/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@ Path.join(["rel", "plugins", "*.exs"])
|> Enum.map(&Code.eval_file(&1))

use Mix.Releases.Config,
# This sets the default release built by `mix release`
default_release: :default,
# This sets the default environment used by `mix release`
default_environment: :dev
# This sets the default release built by `mix release`
default_release: :default,
# This sets the default environment used by `mix release`
default_environment: Mix.env()

# For a full list of config options for both releases
# and environments, visit https://hexdocs.pm/distillery/configuration.html


# You may define one or more environments in this file,
# an environment's settings will override those of a release
# when building in that environment, this combination of release
# and environment configuration is called a profile

environment :dev do
set dev_mode: true
set include_erts: false
set(dev_mode: true)
set(include_erts: false)
set(cookie: :k1YpFGekEWf6IV2nCeWLtQ8cX7IMoO5tUX233xtMM58W8pDua0vrbSByoJusyA2o)
set(vm_args: "rel/vm.args")
end

environment :prod do
set include_erts: true
set include_src: false
set(include_erts: true)
set(include_src: false)
set(cookie: :"YBWAa7Vbdbqh5cr/TNC0h0NB+rhzmtC41ye3s9m6d2auyuxcCfZVQ2wCenNPg3ov")
set(vm_args: "rel/vm.args")
end

# You may define one or more releases in this file.
Expand All @@ -37,6 +40,23 @@ end
# will be used by default

release :lowflyingrocks do
set version: current_version(:lowflyingrocks)
set(version: current_version(:lowflyingrocks))

set(
applications: [
:runtime_tools
]
)

set(
config_providers: [
{Mix.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/config.exs"]}
]
)

set(
overlays: [
{:copy, "rel/config/config.exs", "etc/config.exs"}
]
)
end

5 changes: 5 additions & 0 deletions rel/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config :extwitter, :oauth,
consumer_key: System.get_env("TWITTER_CONSUMER_KEY"),
consumer_secret: System.get_env("TWITTER_CONSUMER_SECRET"),
access_token: System.get_env("TWITTER_ACCESS_TOKEN"),
access_token_secret: System.get_env("TWITTER_ACCESS_TOKEN_SECRET")
33 changes: 33 additions & 0 deletions rel/vm.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## This file provide the arguments provided to the VM at startup
## You can find a full list of flags and their behaviours at
## http://erlang.org/doc/man/erl.html

## Name of the node
-name <%= release_name %>@127.0.0.1

## Cookie for distributed erlang
-setcookie <%= release.profile.cookie %>

## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
## (Disabled by default..use with caution!)
##-heart

## Enable kernel poll and a few async threads
##+K true
##+A 5
## For OTP21+, the +A flag is not used anymore,
## +SDio replace it to use dirty schedulers
##+SDio 5

## Increase number of concurrent ports/sockets
##-env ERL_MAX_PORTS 4096

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

# Enable SMP automatically based on availability
# On OTP21+, this is not needed anymore.
-smp auto

# Disable CPU busy waiting, to improve CPU accounting in a shared environment
+sbwt none +sbwtdcpu none +sbwtdio none

0 comments on commit ca09fd9

Please sign in to comment.