Elixir

Elixir

Elixir Core Team

Elixir v1.9.0-rc.0 released

Release: Release v1.9.0-rc.0 · elixir-lang/elixir · GitHub

Releases

The main feature in Elixir v1.9 is the addition of releases. A release is a self-contained directory that consists of your application code, all of its dependencies, plus the whole Erlang Virtual Machine (VM) and runtime. Once a release is assembled, it can be packaged and deployed to a target as long as the target runs on the same operating system (OS) distribution and version as the machine running the mix release command.

You can start a new project and assemble a release for it in three easy steps:

$ mix new my_app
$ cd my_app
$ MIX_ENV=prod mix release

A release will be assembled in _build/prod/rel/my_app. Inside the release, there will be a bin/my_app file which is the entry point to your system. It supports multiple commands, such as:

  • bin/my_app start, bin/my_app start_iex, bin/my_app restart, and bin/my_app stop - for general management of the release

  • bin/my_app rpc COMMAND and bin/my_app remote - for running commands on the running system or to connect to the running system

  • bin/my_app eval COMMAND - to start a fresh system that runs a single command and then shuts down

  • bin/my_app daemon and bin/my_app daemon_iex - to start the system as a daemon on Unix-like systems

  • bin/my_app install - to install the system as a service on Windows machines

Why releases?

Releases allow developers to precompile and package all of their code and the runtime into a single unit. The benefits of releases are:

  • Code preloading. The VM has two mechanisms for loading code: interactive and embedded. By default, it runs in the interactive mode which dynamically loads modules when they are used for the first time. The first time your application calls Enum.map/2, the VM will find the Enum module and load it. There’s a downside. When you start a new server in production, it may need to load many other modules, causing the first requests to have an unusual spike in response time. Releases run in embedded mode, which loads all available modules upfront, guaranteeing your system is ready to handle requests after booting.

  • Configuration and customization. Releases give developers fine grained control over system configuration and the VM flags used to start the system.

  • Self-contained. A release does not require the source code to be included in your production artifacts. All of the code is precompiled and packaged. Releases do not even require Erlang or Elixir in your servers, as they include the Erlang VM and its runtime by default. Furthermore, both Erlang and Elixir standard libraries are stripped to bring only the parts you are actually using.

  • Multiple releases. You can assemble different releases with different configuration per application or even with different applications altogether.

Hooks and Configuration

Releases also provide built-in hooks for configuring almost every need of the production system:

  • config/config.exs (and config/prod.exs) - provides build-time application configuration, which is executed when the release is assembled

  • config/releases.exs - provides runtime application configuration. It is executed every time the release boots and is further extensible via config providers

  • rel/vm.args.eex - a template file that is copied into every release and provides static configuration of the Erlang Virtual Machine and other runtime flags

  • rel/env.sh.eex and rel/env.bat.eex - template files that are copied into every release and executed on every command to set up environment variables, including ones specific to the VM, and the general environment

We have written extensive documentation on releases, so we recommend checking it out for more information.

Configuration overhaul

A new Config module has been added to Elixir. The previous configuration API, Mix.Config, was part of the Mix build tool. But since releases provide runtime configuration and Mix is not included in releases, we ported the Mix.Config API to Elixir. In other words, use Mix.Config has been soft-deprecated in favor of import Config.

Another important change related to configuration is that mix new will no longer generate a config/config.exs file. Relying on configuration is undesired for most libraries and the generated config files pushed library authors in the wrong direction. Furthermore, mix new --umbrella will no longer generate a configuration for each child app, instead all configuration should be declared in the umbrella root. That’s how it has always behaved, we are now making it explicit.

Other enhancements

There are many other enhancements. The Elixir CLI got a handful of new options in order to best support releases. Logger now computes its sync/async/discard thresholds in a decentralized fashion, reducing contention. EEx templates support more complex expressions than before. Finally, there is a new ~U sigil for working with UTC DateTimes as well as new functions in the File, Registry, and System modules.

v1.9.0-rc.0 (2019-06-04)

1. Enhancements

EEx

  • [EEx] Allow more complex mixed expressions when tokenizing

Elixir

  • [Access] Allow Access.at/1 to handle negative index
  • [CLI] Add support for --boot, --boot-var, --erl-config, --pipe-to, --rpc-eval, and --vm-args options
  • [Code] Add static_atom_encoder option to Code.string_to_quoted/2
  • [Code] Support :force_do_end_blocks on Code.format_string!/2 and Code.format_file!/2
  • [Code] Do not raise on deadlocks on Code.ensure_compiled/1
  • [Config] Add Config, Config.Reader, and Config.Provider modules for working with configuration
  • [File] Add File.rename!/2
  • [Inspect] Add :inspect_fun and :custom_options to Inspect.Opts
  • [Kernel] Add ~U sigil for UTC date times
  • [Kernel] Optimize &super/arity and &super(&1)
  • [Kernel] Optimize generated code for with with a catch-all clause
  • [Kernel] Validate __struct__ key in map returned by __struct__/0,1
  • [Module] Add Module.get_attribute/3
  • [Protocol] Improve Protocol.UndefinedError messages to also include the type that was attempted to dispatch on
  • [Protocol] Optimize performance of dynamic dispatching for non-consolidated protocols
  • [Record] Include field names in generated type for records
  • [Regex] Automatically recompile regexes
  • [Registry] Add Registry.select/2
  • [System] Add System.restart/0, System.pid/0 and System.no_halt/1
  • [System] Add System.get_env/2, System.fetch_env/1, and System.fetch_env!/1
  • [System] Support SOURCE_DATE_EPOCH for reproducible builds

ExUnit

  • [ExUnit] Allow multiple :exclude on configuration/CLI
  • [ExUnit.DocTest] No longer wrap doctest errors in custom exceptions. They ended-up hiding more information than showing
  • [ExUnit.DocTest] Display the actual doctest code when doctest fails

IEx

  • [IEx.CLI] Copy ticktime from remote node on IEx --remsh
  • [IEx.CLI] Automatically add a host on node given to --remsh

Logger

  • [Logger] Use a decentralized mode computation for Logger which allows overloads to be detected more quickly
  • [Logger] Use persistent_term to store configuration whenever available for performance

Mix

  • [Mix] Follow XDG base dir specification in Mix for temporary and configuration files
  • [Mix.Generator] Add copy_file/3, copy_template/4, and overwite?/2
  • [mix archive.uninstall] Allow mix archive.uninstall APP to uninstall any installed version of APP
  • [mix new] No longer generate a config/ directory for mix new
  • [mix release] Add support for releases
  • [mix release.init] Add templates for release configuration
  • [mix test] Allow running tests for a given umbrella app from the umbrella root with mix test apps/APP/test. Test failures also include the apps/APP prefix in the test location

2. Bug fixes

EEx

  • [EEx] Consistently trim newlines when you have a single EEx expression per line on multiple lines

Elixir

  • [Code] Quote :: in Code.format_string!/1 to avoid ambiguity
  • [Enum] Ensure the first equal entry is returned by Enum.min/2 and Enum.max/2
  • [Kernel] Improve error message when string interpolation is used in a guard
  • [Kernel] Properly merge and handle docs for callbacks with multiple clauses
  • [Kernel] Guarantee reproducible builds on modules with dozens of specs
  • [Kernel] Resolve __MODULE__ accordingly in nested defmodule to avoid double nesting
  • [Kernel] Type variables starting with an underscore (_foo) should not raise compile error
  • [Kernel] Keep order of elements when macro in/2 is expanded with a literal list on the right-hand side
  • [Kernel] Print proper location on undefined function error from dynamically generated functions
  • [System] Make sure :init.get_status/0 is set to {:started, :started} once the system starts
  • [Path] Do not expand ~ in Path.expand/2 when not followed by a path separator
  • [Protocol] Ensure debug_info is kept in protocols
  • [Regex] Ensure inspect returns valid ~r// expressions when they are manually compiled with backslashes
  • [Registry] Fix ETS leak in Registry.register/2 for already registered calls in unique registries while the process is still alive

ExUnit

  • [ExUnit] Raise error if attempting to run single line tests on multiple files
  • [ExUnit] Return proper error on duplicate child IDs on start_supervised

IEx

  • [IEx] Automatically shut down IEx if we receive EOF

Logger

  • [Logger] Don’t discard Logger messages from other nodes as to leave a trail on both systems

Mix

  • [mix compile] Ensure Erlang-based Mix compilers (erlang, leex, yecc) set valid position on diagnostics
  • [mix compile] Ensure compilation halts in an umbrella project if one of the siblings fail to compile
  • [mix deps] Raise an error if the umbrella app’s dir name and mix.exs app name don’t match
  • [mix test] Do not consider modules that are no longer cover compiled when computing coverage report, which could lead to flawed reports

3. Soft-deprecations (no warnings emitted)

Mix

  • [Mix.Config] Mix.Config has been deprecated in favor of the Config module that now ships as part of Elixir itself. Reading configuration files should now be done by the Config.Reader module

4. Hard-deprecations

Elixir

  • [CLI] Deprecate --detached option, use --erl "-detached" instead
  • [Map] Deprecate Enumerable keys in Map.drop/2, Map.split/2, and Map.take/2
  • [String] The :insert_replaced option in String.replace/4 has been deprecated. Instead you may pass a function as a replacement or use :binary.replace/4 if you need to support earlier Elixir versions

Mix

  • [Mix.Project] Deprecate Mix.Project.load_paths/1 in favor of Mix.Project.compile_path/1

Checksums

  • Precompiled.zip SHA1: 775e9c39c0bf680ecbab0dcbb93589b3fadea773
  • Precompiled.zip SHA512: bc50c7f766196d961e26c912ead53257b95c421cfab81c6cf58d5ae4f3e3b646ea262f75e31d23de66761e8e1aacaa42fca42b110869f08428881b748095e2d6
  • Docs.zip SHA1: 19a34ddd89f6e5e0efc04fdc080a79acf48e0f7b
  • Docs.zip SHA512: 2c604884fdb1653b641a7d240a3533293ee763a085f14ba4df3cd883bd1e12d42ac8c69eaf694ad211115c7a1acb424036c9ebcc160510d39d8c9dfd7d2374a9

Have fun!

Most Liked

sergio

sergio

Woah! mix release is quite exciting! Congratulations to the Elixir team and thank you for all the hard work. You make our lives easier.

josevalim

josevalim

Creator of Elixir

Regarding documentation, those concerns aren’t solved right now (it is too soon) but I believe it will be solved in the short term as, by being part of core, more people will use it, battle test it, document it, write guides, etc. For example, [latest Ecto ships with functions(Add Ecto.Migrator.with_repo/2 to start/stop apps for migrations by josevalim · Pull Request #113 · elixir-ecto/ecto_sql · GitHub) that make running Ecto tasks inside a release very straightforward]. Phoenix guides will also be updated to cover it.

In particular:

Phoenix will ship with guides for this (it also does for distillery though).

There is a well-documented path for this in Elixir releases (TL;DR - there is a config/releases.exs that runs on release boot).

Custom code is still necessary for Elixir but you don’t need shell scripts. Only a module with functions you will invoke. See the Ecto link above and the official guides. The Hex migration (which is a Phoenix app) covered this too: Updating Hex.pm to use Elixir releases « Plataformatec Blog

Same as above other environments variables: just put it in config/releases.exs. In fact, for Phoenix v1.4 projects, getting it to work is a matter of renaming config/prod.secret.exs to config/releases.exs.

jsm

jsm

I really like that the config situation is starting to get cleared up :slight_smile: I do wonder if this still means that it is necessary to create a custom command to run migrations? I’ve always kind of hated having to do stuff like this distillery/docs/guides/running_migrations.md at master · bitwalker/distillery · GitHub in release images, instead of using the standard mix ecto.migrate which seems perfectly suited for the job.

Where Next?

Popular in News Top

Elixir
1. Bug fixes Elixir [bin/elixir] Properly handle the --dbg flag in Elixir’s CLI [Code.Formatter] Add brackets around keyword lists when ...
New
josevalim
NOTE: this is a focused thread, so we appreciate if everybody stayed on topic. Feel free to comment anything in regards to calendar forma...
New
whatyouhide
Hello folks, the Elixir team (well me, but I got a thumbs up from the others :P) is looking for contributors and potentially maintainers...
New
Elixir
Release: Release v1.10.3 · elixir-lang/elixir · GitHub 1. Bug fixes Elixir [Code] Return [{mod, bin}] from Code.compile_file/2, Code.re...
New
Elixir
1. Bug fixes Elixir [Duration] Fix parsing of fractional durations with non-positive seconds [Kernel] Do not attempt to group module war...
New
josevalim
See the post: https://elixir-lang.org/blog/2017/12/05/whats-new-in-elixir/ Kudos to @doomspork for starting the series!
New
Elixir
1. Enhancements Mix [mix compile.elixir] Do not run fixpoint computation on runtime dependencies. This should considerably improve compi...
New
josevalim
Announcement: Elixir v1.8 released - The Elixir programming language Release notes: Release v1.8.0 · elixir-lang/elixir · GitHub Thanks...
New
Elixir
Official announcement: Elixir v1.16 released - The Elixir programming language 1. Enhancements EEx [EEx] Include relative file informat...
New
Elixir
Elixir v1.18 is an impressive release with improvements across the two main efforts happening within the Elixir ecosystem right now: set-...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement