diff --git a/lib/mix/tasks/bonny.gen.dockerfile.ex b/lib/mix/tasks/bonny.gen.dockerfile.ex index 2dbb81c..20e8738 100644 --- a/lib/mix/tasks/bonny.gen.dockerfile.ex +++ b/lib/mix/tasks/bonny.gen.dockerfile.ex @@ -15,9 +15,13 @@ defmodule Mix.Tasks.Bonny.Gen.Dockerfile do {opts, _, _} = Mix.Bonny.parse_args(args, @default_opts, switches: @switches, aliases: @aliases) + binding = [ + app_name: Mix.Bonny.app_dir_name() + ] + "Dockerfile" |> Mix.Bonny.template() - |> EEx.eval_file([]) + |> EEx.eval_file(binding) |> Mix.Bonny.render(opts[:out]) end end diff --git a/priv/templates/bonny.gen/Dockerfile b/priv/templates/bonny.gen/Dockerfile index 8cb47ca..d0ebd44 100644 --- a/priv/templates/bonny.gen/Dockerfile +++ b/priv/templates/bonny.gen/Dockerfile @@ -1,18 +1,33 @@ -FROM elixir:1.7.4-alpine +######################### +###### Build Image ###### +######################### + +FROM bitwalker/alpine-elixir:1.9.1 as builder ENV MIX_ENV=prod \ - MIX_HOME=/opt/mix \ - HEX_HOME=/opt/hex + MIX_HOME=/opt/mix \ + HEX_HOME=/opt/hex RUN mix local.hex --force && \ - mix local.rebar --force + mix local.rebar --force WORKDIR /app COPY . . -RUN mix deps.get --only-prod && \ - mix deps.compile && \ - mix compile +RUN mix deps.get --only-prod && mix release + +######################### +##### Release Image ##### +######################### + +FROM alpine:3.10 + +RUN apk add --update openssl ncurses + +WORKDIR /app +COPY --from=builder /app/_build/prod/rel/<%= app_name %> ./ +RUN chown -R nobody: /app -CMD ["mix", "run", "--no-halt"] +ENTRYPOINT ["/app/bin/<%= app_name %>"] +CMD ["start"] diff --git a/test/mix/tasks/bonny.gen.dockerfile_test.exs b/test/mix/tasks/bonny.gen.dockerfile_test.exs index 771708b..32edee8 100644 --- a/test/mix/tasks/bonny.gen.dockerfile_test.exs +++ b/test/mix/tasks/bonny.gen.dockerfile_test.exs @@ -5,13 +5,13 @@ defmodule Mix.Tasks.Bonny.Gen.DockerfileTest do import ExUnit.CaptureIO describe "run/1" do - test "generates a Dockerfile" do + test "generates a Dockerfile using the application name" do output = capture_io(fn -> Dockerfile.run(["--out", "-"]) end) - assert output =~ "FROM elixir" + assert output =~ "/app/_build/prod/rel/bonny" end end end