Minex - A deployment helper for Elixir

Minex (Docs)

Minex allows you to create your own re-usable deployment tasks to setup deployment to your own needs. I created it to replace bash script with something more configurable/re-usable. It contains helpers to run commands locally and remotely (on the target specified by :host). It doesn’t contain specific deployment strategies, except for the example deploy tasks.

It’s possible to generate a bash script for enabled tasks (by passing a [generate_script: true] as options or using generate_script_task(...). This is useful for when you need a full shell/tty. For example when starting a remote console session)

Example deploy file:

use Minex

set(:name, "my_app")
set(:deploy_to, "/apps/#{get(:name)}")
set(:host, "deploy@")

Code.require_file("deploy/tasks.exs", Path.dirname(__ENV__.file))

# expects a config/deploy/Dockerfile
public_task(:build, fn ->
  command("docker container rm dummy", allow_fail: true)
  command("docker build -f config/deploy/Dockerfile  -t #{get(:name)} .")
  command("docker create -ti --name dummy #{get(:name)}:latest bash")
  command("docker cp dummy:/release.tar.gz release.tar.gz")

public_task(:deploy, fn ->
  run(:upload, ["release.tar.gz", "#{get(:deploy_to)}/release.tar.gz"])
  run(:remote, fn ->
    command("cd #{get(:deploy_to)}")
    command("( [ -d \"bin\" ] && ./bin/#{get(:name)} stop || true )")
    command("tar -zxf release.tar.gz -C .")
    command("./bin/#{get(:name)} daemon")


Let me know your thoughts!


I would use similar approach to the ExUnit for Minex.run(). So you would do System.at_exit(fn -> Minex.run(System.argv()) end) in Minex.__using__/1 so the user would not need to remember to run it on their own (probably add a flag that would allow disabling such behaviour).

Another question is - why not make it Mix task?


Thanks for the suggestions!

I’ve considered the at_exit but this seems more flexible. You can for example extract a target (staging/production) out of System.argv() and pass the rest to Minex.run.

I did create a mix task to help run tasks: mix minex task_name. Is that what you mean?

I have something similar that I use internally (it’s like an elixir-ish ansible): it’s like ansible and minex in that it can either issue locally via cmd or via ssh. I’ve been thinking about open sourcing it, but am slightly afraid in that people might make fun of me for reimplementing ansible (with less yaml, things are more obviously functions, you can IO.inspect everywhere, etc etc etc). Is that something y’all might use if I open sourced it or if we joined forces?

also generate_script: true is really fantastic.

1 Like

I would personally be curious about it!

Why not both? By default you could do the at_exit (so people do not have to remember), and provide an option for the use which switches that off, when the user desires to do so.

Less footguns, you know?

1 Like

My proposal is like @wolf4earth said, you have:

defmodule Minex do
  defmacro __using__(opts) do
    autorun = Keyword.get(opts, :autorun, true)

    quote do
      if unquote(autorun), do: System.at_exit(fn -> unquote(__MODULE__).run(System.argv())) end)
1 Like