How to Package an Erlang App? - erlang

What is the idiomatic way of packaging erlang modules/app? For example, in Java there two options: jar or war depending on deployment target.

In Erlang, modules are grouped into applications. Applications are grouped into releases. How does this works? Like this.
Luckily, Rebar exists to do most of it. Rebar is probably the most commonly used tool to manage applications and releases.

Related

What is the best way to package Elixir CLI application?

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)
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/
Bakeware generates a single executable file.
They have added a CLI app example here.

What is the difference between rebar and rebar3? or erlang.mk

I am very new to Erlang programming language. Is there a standard build tool in Erlang?
I have googled out these, not sure which one I should use. I don't know that what kind of occasion is it used for?
Rebar2: It is first usable and de facto build tool that most of the Erlang projects are using it. It uses Erlang script for getting dependencies, compiling, testing and making release of your project. However it is not a modern build tool and suffers from slowness of compiling in developing phase, difficulty for using in larger projects and a bit hard to understand for newcomers.
Rebar3: It is a successor to rebar2 with an attempt to improving its mechanism and providing new features which is compatible with modern build tools. Also it is easier to use for newcomers
Erlang.mk: It is a big Makefile. As Makefile is fast and is available by default in every unix system, so you can benefit from these features for your Erlang application build tool. It has a package index of most well-known Erlang projects and other standard features like Rebar. Also it is faster that rebar2 in developing phase (preliminary results show that rebar3 is notably faster than Erlang.mk)
I myself use Rebar and this possible duplicate of your question has two answers that recommend Rebar as well. But it is a matter of taste and I recommend to consider two different approaches and choose what is closer to your purposes.

Can and should I use sbt and sbt-native-packager for non Java or Scala specific packaging of an RPM?

Like I could using Ant?
I don't have to compile sources or create jars to make the RPM.
If this is a good approach?
How to I use sbt without language specific features?
"Convention over configuration" is speaking:
You could, but that would require reconfiguring lots of tasks and settings to meet your requirements and would likely not offer much benefit.

Good practices when developing an application in Erlang (and Riak)?

We are getting familiar with Erlang/OTP and Riak (Core, KV, Pipe, and so on) trying to build an open-source distributed application in turn. Our project is going to have a bunch of dependencies : tools like erlang_js, protobuffs, etc., but also services that we need to have running, such as Riak KV.
In Python/Ruby/Node.js, if modules are placed in a standard subdirectory relative to your project's, you can reference them, and later package them in releases. You can fire up a shell in the project's directory, play with your modules, do tests and so on, all just easily if good practices are followed.
What are the best practices for organizing a development environment in Erlang/OTP, with all dependencies reachable (and easily updatable to newest version), shell access to running nodes, testing, making releases, and so forth?
Check out rebar3: used for packaging, templating and managing releases of Erlang/OTP applications. You will find there an entire tutorial on how to use it.
Check out this tutorial on OTP first, before you can switch to this one which shows you releases and how they are handled in Erlang. Use this entire book as reference as you develop your project and because the author is still progressively adding more advanced stuff that you may need.
You may also want to keep reading about Erlang Applications and then do check out these quick links below:
Erlang Packaging, Process OneOTP Packaging Video by Chicago Boss GuysErlang Dependency ManagementRichard Jones Advice and examples on Packaging Erlang Projects with DependenciesMaven Tool and how it is used in packaging Erlang Projects
Most importantly, take rebar very seriously. It is very important in managing Erlang applications which have dependencies. You can keep posting your questions here on Stack Overflow for any assistance as you progress.
Before I forget, do check out a lot of stuff from the Riak Community.
Also, its important to check out the system documentation on creating target systems and also how to use Reltool to handle releases. The good thing with erlang is that it has several options of how to do something, as long as its easy to maintain your application in that way. With target systems, you will learn how to embed the Erlang VM, how to run Erlang applications on Solaris, VxWorks, and creating Erlang applications as Services on Windows NT using erlsrv.
Normally, we make sure that as an operating system is booting a Server, our application starts with it. Solaris so far has more customizations than any other OS as regards embedding Erlang/OTP VM. You can always communicate with (an) embedded Erlang VM(s) using Escript where by the escript creates a an erlang node which is allowed to connect to the embedded VM (so they have to share same cookie) and the embedded VM must have allowed the temporarily created Node to connect by executing net_kernel:allow(List_of_nodes)
Make sure to call this method to make your embedded VM allow connections only from an known strictly specified number of Nodes.

Directory Layout for Erlang Services?

In our Java applications we typically use the maven conventions (docs, src/java, test, etc.). For Perl we follow similar conventions only using a top level 'lib' which is easy to add to Perl's #INC.
I'm about to embark on creating a service written in Erlang, what's a good source layout for Erlang applications?
The Erlang recommended standard directory structure can be found here.
In addition you may need a few more directories depending on your project, common ones are (credit to Vance Shipley):
lib: OS driver libraries
bin: OS executables
c_src: C language source files (e.g. for drivers)
java_src: Java language source files
examples: Example code
mibs: SNMP MIBs
Other projects such as Mochiweb have their own structures, Mochiweb even have a script to create it all for you. Other projects such as Erlware overlay on the standard structure.
Another critical directory is the priv directory. Here you can store files that can easily be found from your applications.
code:priv_dir(Name) -> string() | {error, bad_name}
where Name is the name of your application.
Erlware is changing that - in a couple of days the Erlware structures will be exactly that of Erlang OTP. Actually the structure of app packages is already exactly that of OTP and as specified above. What will change is that Erlware installed directory structure will fit exactly over an existing Erlang/OTP install (of course one is not needed to install Erlware though) Erlware can now be used to add packages to an existing install very easily.
Cheers,
Martin

Resources