7

Suppose I have a CLI application with subcommands and arguments (like application foo --bar baz). How can I package it for distribution without requiring user to install Erlang?

I know there's mix escript Mix task, but it builds a binary that requires Erlang to be installed, also Mix reference states that escripts should be used only for development purposes. mix release, however, produces redundant shell scripts that I don't want to see in dist.

So, is there a way to make a standalone distributable of an Elixir CLI application?

P. S. This is actually my first experience with Elixir (and the whole Erlang ecosystem)

k.meinkopf
  • 158
  • 6

2 Answers2

4

Elixir applications can be packaged as Erlang releases, see also here. These can include Erlang VM. Elixir since 1.9 supports building releases without extra tooling, using included mix task mix release - please check the documentation for greasy details: https://hexdocs.pm/mix/Mix.Tasks.Release.html

You might benefit from a quick look at this blog post for inspiration and conceptual overview, noticing that for simple CLI app it is much simpler: https://www.cogini.com/blog/best-practices-for-deploying-elixir-apps/

FooF
  • 4,323
  • 2
  • 31
  • 47
  • As I understood, `mix release` used more for applications that should run as a service, like Web-server. It generates shell scripts I don't need. I have seen somewhere that it is possible to use `app eval SomeModule.main` to run an application, but this means that I should write another shell script to launch shell script to launch the application. That's weird. I thought that there can be another mix task that will generate shell scripts for CLI applications (like ones that are used by Elixir CLI tools). – k.meinkopf Feb 17 '21 at 16:31
  • 1
    (1/2) I proposed to use Erlang release because the question asked for a way to package elixir app without requiring the user to install erlang. Elixir by necessity requires Erlang, so I thought it should be packaged along with the app to make it easier for the target user. Typical Erlang app is more complicated (distributed, concurrent, persistent, error resilient, configurable) than a simple CLI app that is run and then just quits, so Erlang release surely will take care of more concerns than you need. – FooF Feb 19 '21 at 11:00
  • 1
    (2/2) Anyway there are lots of ways to control how the release (`mix release` executing `Mix.Tasks.Release`) is done, for example removing stuff you do not need by `steps` configuration, and this is where Broadway as proposed in another answer, also plugs in. – FooF Feb 19 '21 at 11:01
2

Bakeware generates a single executable file.

They have added a CLI app example here.

  • This seems to be the best solution, however, it does not now support Windows. Sadly, I need the application to work on Windows, so this does not work for me... – k.meinkopf Feb 21 '21 at 18:12
  • Just an update from the future, it looks like Bakeware supports windows now – ollien Nov 06 '22 at 18:06