Packages

Library for building docker images of Elixir projects. Supports a plugin system which can allows the generated Dockerfile to be extended at various points.

Current section

Files

Jump to
docker_build lib mix tasks build.ex
Raw

lib/mix/tasks/build.ex

defmodule Mix.Tasks.Docker.Build do
use Mix.Task
alias DockerBuild.Build
@shortdoc "Builds a docker image for the project"
@moduledoc """
Builds a new docker image for the project for a given enviroment. Defaults to `:prod`
## Example
`mix docker.build dev`
## Options
* `--target` - stage to build. Can be "builder" or "release". Defaults to "release"
* `--no-build` - just generate the Dockerfile and do not build
"""
@doc false
def run(args) do
{:ok, opts} =
case OptionParser.parse!(args, strict: [target: :string, no_build: :boolean]) do
{opts, []} ->
{:ok, opts}
{opts, [env]} ->
{:ok, [{:env, env} | opts]}
_ ->
Mix.raise("Too many parameters")
:error
end
case Build.run(opts) do
0 -> Mix.shell().info("Build done")
n -> Mix.raise("Build failed. Exit code #{n}")
end
end
end