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@1.2.3.4")

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")
end)

public_task(:deploy, fn ->
  run(:build)
  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")
  end)
end)

Minex.run(System.argv())

Let me know your thoughts!

7 Likes