Skip to content

Commit

Permalink
Fixes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
coryodaniel committed Aug 27, 2019
1 parent fd56755 commit 34cfc06
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
6 changes: 5 additions & 1 deletion lib/mix/tasks/bonny.gen.dockerfile.ex
Expand Up @@ -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
31 changes: 23 additions & 8 deletions 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"]
4 changes: 2 additions & 2 deletions test/mix/tasks/bonny.gen.dockerfile_test.exs
Expand Up @@ -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

0 comments on commit 34cfc06

Please sign in to comment.