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:
-
Add
docker_distillerto your list of dependencies inmix.exs:
```elixir
def deps do
[{:docker_distiller, "~> 1.0"}]
end
```Run
mix release.initto get a Distillery config setup. See the Distillery Docs for details.Some changes in
rel/config.exsyou need to make:-
Set
default_environmenttodeployand include anenvironmentstanza for that environment.
-
Set
Add a target
docker_reposetting to your application inmix.exs- we will deploy to that repository.def project do [app: :my_app, ... docker_repo: "quay.io/my_quay_repo", ... ] end(Optionally) override the build image. By default, we will use the
bitwalker/alpine-elixirimages 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(Optionally) use a local dockerfile as the build image.
def project do [... build_dockerfile: "path/to/your/Dockerfile" ... ] end(Optionally) use something else than
/opt/appfor the location where we unpack the app:def project do [... path_in_container: "/" ... ] end(needs to end with a slash, by the way)
Add a template Dockerfile called
Dockerfile.deploy.eex. This template will get stuff injected from the build and then written asDockerfile, 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 theADD (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.-
Run
mix publishto build a release and publish it.