DockerDistiller

This package uses Distillery and Docker to create containerized builds of Elixir apps that are small and nimble.

In the past, this tool built all environments - however, we stepped away from this. We currently only build one environment, deploy, hard-coded, which is expected to be run with REPLACE_OS_VARS and thus use 12FA style environment variable injection to make a different between staging, production, and whatever else.

Installation/Use

If available in Hex, the package can be installed as:

  1. Add docker_distiller to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:docker_distiller, "~> 1.0"}]
end
```
  1. Run mix release.init to get a Distillery config setup. See the Distillery Docs for details.

    Some changes in rel/config.exs you need to make:

    1. Set default_environment to deploy and include an environment stanza for that environment.
  2. Add a target docker_repo setting to your application in mix.exs - we will deploy to that repository.

    def project do
      [app: :my_app,
       ...
       docker_repo: "quay.io/my_quay_repo",
       ...
      ]
    end
  3. (Optionally) override the build image. By default, we will use the bitwalker/alpine-elixir images for the correct elixir version, but you can override this in the project settings (in case you use a newer Elixir than published, or you can’t use public Docker images for security reasons, etcetera):

    def project do
      [...
       build_image: "super.repo.io/myrepo/elixir-dev:1.2.3"
       ...
      ]
    end
  4. (Optionally) use a local dockerfile as the build image.

    def project do
      [...
       build_dockerfile: "path/to/your/Dockerfile"
       ...
      ]
    end
  5. (Optionally) use something else than /opt/app for the location where we unpack the app:

    def project do
      [...
       path_in_container: "/"
       ...
      ]
    end

    (needs to end with a slash, by the way)

  6. Add a template Dockerfile called Dockerfile.deploy.eex. This template will get stuff injected from the build and then written as Dockerfile, overwriting existing things. The following is sent to the template:

    • add_dist_tar: Put an expansion for this in the Dockerfile at the location where you want the ADD (tarball) (appname) lines to land
* `cmd_to_run`: The command to run for the built release

 An example minimal template:

 ```
 FROM bitwalker/alpine-elixir:1.5.2

 <%= add_dist_tar %>

 CMD <%= cmd_to_run %> foreground
 ```

 Note that even though the distribution tar contains Erlang, there are packages that
 Erlang needs (like the libncurses) so building from a basic Alpine image will most
 likely not work.
  1. Run mix publish to build a release and publish it.